GitHub and Atom

Installing Atom (and dependencies)

I was an avid and long-time lover of Atom as my ‘IDE’ or text-editor of choice. Not only because I advocate for Linux, but due to it being an early adopter of git integration and plugin support (around the time Adobe’s Bracket was taking off). In this post I’ll go through (very briefly – these are things you’ll need to learn) on getting a very basic setup going to start with Git.

To configure the use of Atom (we’ll briefly touch on Code, too) on Linux to interact with Github, there are a few additional system requirements. First and foremost, you need to ensure you have the correct dependencies. For this guide, you’ll need to run the following (assuming apt is your package manager): sudo apt install npm node git -y

Of course, depending on what you’re coding (such as python) you may want to satisfy other dependencies – for now, we’re only going to cover the base installation of Git and Atom.

Now, we can have a debate around using snaps or apts but for me, I’ll use a snap package to install Atom – the command is: snap install atom

Of course, if you’re not sold, sudo apt install atom -y will yield a similar result.
From here, immediately perform the following to rectify a known bug:

sudo sed -i 's/Exec=env BAMF_DESKTOP_FILE_HINT=\/var\/lib\/snapd\/desktop\/applications\/atom_atom.desktop \/snap\/bin\/atom ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT=false \/usr\/bin\/atom %F/Exec=env BAMF_DESKTOP_FILE_HINT=\/var\/lib\/snapd\/desktop\/applications\/atom_atom.desktop ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT=false \/snap\/bin\/atom %F/' /var/lib/snapd/desktop/applications/atom_atom.desktop

Tweaks and Additional Settings

For the sole purpose of ‘redundancy’, I also install gitg and clone my repository via this. If you don’t want to do this, run the following commands to create your information:

git config --global user.email "email@domain.com"
git config --global user.name "MyGitName"

Once done in here, I clone the repository via gitg and pass in my username and access token. Fancier applications such as GitKraken handle OAuth better (in my personal experience), but that’s no fun.

Once within Atom, open the Project Folder and you’ll be prompted to do a plethora of changes to the editor. My changes are as follows – of course, my personal taste – for those interested:

  1. Uncheck “Show Welcome Guide When Opening Atom” – this should also help to ensure when you open Atom, it re-opens your project for you.
  2. Install a number of packages. Packages and extensions are what made Atom popular in the day. These are subjective to your needs, but I always get the following:
    • ide-powershell
    • build-powershell
    • atom-terminal-powershell
    • color-tabs
    • terminal-tab-service
    • atom-ide-ui
    • git-plus
    • ide-bash
    • atom-bash
  3. From here, select a theme. This is entirely cosmetic and is up to you, anon.

    There are a plethora of other minor tweaks to the UI, tabbed completion and debugging you can do. Of course, nothing on the level of the God-King himself, ThePrimeagen.

As much as it hurts me to say, I’ve been having quite a number of errors on Atom recently. I’m a scriptkiddie, not a developer, so I have migrated to Code.

One sad Michael

What I think you’ll find is the configuration options are very similar to Visual Studio Code. If we were to go into every detail and modify your config it could take hours – and I certainly don’t want to cover everything. At this point you will have a working ‘IDE’ with your extensions, and GIT integration – code on, legends.

Installing Visual Studio Code

Visual Studio Code has definitely rose to fame as arguably one of the most popular and accepted standard for coding. To me it’s a little annoying to use – and it’s not because it’s bad. You will most likely find more support for this product in the industry, so it’s an invaluable tool to install.

Much like Atom, it’s entirely subjective to what you need it to do. Once it’s installed your options are near unlimited. Because you’ve got your shared git configuration from before, you can open your project up and continue as if nothing has changed.

For example, the extensions I usually install are:
– PowerShell
– Azure PowerShell Tools
– Terminal Status Bar
– tl;dr pages
– Hacker Colors
– Git Lens

These are enough to get me started, and you’re away. Additionally (and I did not cover this with Atom), you can source your configuration file across devices – $HOME/.config/Code/User/settings.json – an example:

{
// NancarrowConsulting VSCode Configuration - https://michaelnancarrow.com
// Refer to: https://www.vscodecandothat.com/ for other great settings.    

    // The best workbench colors, ever:
            "workbench.colorTheme": "Hacker Colors"
    // Edits the code as you type it, useful for simple fixes:
            "editor.formatOnType": true 
    // Edits (or formats) as you paste your content from StackOverflow:
            "editor.formatOnPaste": true
    // Edits (or formats) as you save your file:
            "editor.formatOnSave": true
    // Highlights unsaved work tabs on your editor:
            "workbench.editor.highlightModifiedTabs": true
    // Got to enable auto-save, otherwise we're losing it all!
            "files.autoSave": "onWindowChange"
    // We set the editor to sort by modified: 
            "explorer.sortOrder": "modified" 
    // Because we're useless, we get VSCode to trim blank lines at the end of our files:
            "files.trimTrailingWhitespace": true 
    // We enable BreadCrumbs for multi-file projects as required:
            "breadcrumbs.enabled": true     
}

Get-Process, basic explanation

On a Window’s based system, there are a plethora of methods to ascertain process information – task manager, namely being the common. In my time as a system administrator, I had the agenda to try to automate everything, and become as “efficient” as possible in all tasks – not a good idea! Whilst there are a number of tools readily available, I opted for the “in-built” and actively developed tool, and as such, PowerShell became my go to.

Gathering Process Information

To ascertain process running on a Windows device, you can run the following command:

Get-Process

This will simply return an unfiltered table of all running process on an end-point. Whilst useful, on a “busy” system, it’s too hard to monitor anything.

For me, I’d like to manipulate the data to perform the following:

– Sort the CPU Utilization;
– Only select the top $x process’ on the host;
– Return the Process ID, Name and CPU usage

This is quite simple to perform in a “one-liner”, or even storing it as a variable for your PowerShell Profile:

# Storing this as a variable:
$proc = Get-Process | Sort CPU -descending | Select -first 5 -Property ID,ProcessName,CPU

# Calling the above mentioned variable, as opposed to the command:
$proc

This seems like a lot of work, just to get some process information back – but when trying to fault-find, or look at compromised systems, this can be a great starting point to finding out what went wrong on a system.

The other handy thing is that you can take this data, and pipe in additional (or supplementary) commands to make things easier. For example, to make viewing easier, you could format the output as a table:

Get-Process | Sort CPU -descending | Select -first 5 -Property ID,ProcessName,CPU | Format-Table -Wide

Terminating Process with Filters

Now the fun comes into play. Using some ‘logic’ (i.e. RAM utilization) we can automatically end process we deem as non-important. Let’s say Google Chrome Update Services or OneDrive as an alternative. Of course, I’m not going to dive into detail here on how to do this – but I will supply a GitLab repository for this later.

For now, let’s assume we simply wish to kill the top 5 CPU process’ on a device in real time. The command remains the same as before, however we pipe in a Stop-Process to terminate each item.

Get-Process | Sort CPU -descending | Select -first 5 -Property ID,ProcessName,CPU | Stop-Process -Verbose

This will, unless you add parameters, prompt you for confirmation as required (because, well, we don’t necessarily trust it otherwise).