My Pop! OS setup

I’m keeping a log of my System76 / Pop! OS setup as a reminder to myself as well as to provide others with helpful settings and snippets

Command line tools

Working on the command line is my most fun and efficient way of interacting with the computer. Coming from macOS, I was used to the package manager brew to install and update command line tools. Since apt-get doesn’t provide recent versions of many CLI tools, I’m continuing to use brew on Linux as well.

Tools available in brew

Firstly, installing brew itself:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> ~/.profile
source ~/.profile

And then installing cli tools available via brew:

# fzf - general-purpose command-line fuzzy finder
brew install fzf
/home/linuxbrew/.linuxbrew/opt/fzf/install --key-bindings --completion --update-rc # installs useful keybindings and fuzzy completion
source ~/.bashrc   # source settings made by previous install command

brew install docker-compose
brew install doctl              # DigitalOcean CLI
brew install helm               # K8s package manager
brew install imagemagick        # Image processing
brew install jq                 # JSON processing
brew install kubectl            # Kubernetes CLI
brew install neovim             # My favorite text editor
brew install postgres
brew install ripgrep            # Better grep

Other tools, not available in brew

sudo apt install docker.io                            # docker is also available via brew but I had issues installing it
sudo apt install gnome-shell-extension-autohidetopbar # hides system's top bar
sudo apt install tlp tlp-rdw --no-install-recommends  # incrases battery life: https://support.system76.com/articles/battery/

~/.profile exports

export FZF_DEFAULT_COMMAND='rg --files --follow --hidden -g "!{node_modules/,.git/}"'
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

~/.bashrc aliases and functions

alias awkp1="awk '{print \$1}'"
alias decode_ssl='openssl x509 -text -noout -in'

Startup scripts

I want to run a few scripts on system start, such as setting the initial screen brightness:

sudo tee /etc/rc.local << EOF > /dev/null
#!/bin/sh

# Set screen brightness to minimum value
echo 1 > /sys/class/backlight/intel_backlight/brightness

# Enable audio codec power saving
echo '1' > /sys/module/snd_hda_intel/parameters/power_save

exit 0
EOF
sudo chmod -v +x /etc/rc.local
sudo tee /etc/systemd/system/rc-local.service << EOF > /dev/null
[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
 WantedBy=multi-user.target
EOF
sudo systemctl enable rc-local.service

Neovim setup

Many programmers prefer neovim over the original vim and here’s my personal neovim setup:

Installation

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Configuration

Editor settings and plugins go to ~/.config/nvim/init.vim. Run nvim -c "PlugInstall" -c "qa" to install the plugins from your command line, having nvim quit right after.

set backspace=indent,eol,start
set clipboard=unnamedplus
set colorcolumn=91
set nocompatible
set number relativenumber
set ruler
set runtimepath+=~/.vim
set runtimepath+=/home/linuxbrew/.linuxbrew/opt/fzf
set shell=/bin/bash
set whichwrap+=<,>,[,]

let g:ctrlp_max_files=0
let g:ctrlp_max_depth=100
let g:ctrlp_working_path_mode = 'ra'
let g:mapleader = "\<Space>"
let NERDTreeShowHidden=1

call plug#begin()
Plug 'tpope/vim-sensible'
Plug 'editorconfig/editorconfig-vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'Vimjas/vim-python-pep8-indent'
Plug 'yuezk/vim-js'
call plug#end()

filetype plugin indent on

nnoremap <silent> <leader><space> :Files<CR>
" Don't overwrite register with selected text when pasting
" See also: https://stackoverflow.com/questions/290465/#comment71467536_5093286
xnoremap <expr> p 'pgv"'.v:register.'y`>'

" Auto-reload buffer on file change
" https://unix.stackexchange.com/a/383044/79184
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost * echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None

Git configuration

Here’s my .gitconfig. Noteably, it doesn’t provide an alias for git checkout as I prefer its newer “replacements” git restore and git switch.

[alias]
a = add
aa = add .
b = branch
c = commit -m
ca = commit --amend
can = commit --amend --no-edit
d = diff
ds = diff --staged
f = fetch
find = "!git log --color -p -S "
g = log --pretty=oneline --abbrev-commit --graph
gg = log --graph
l = log --pretty=oneline --abbrev-commit
ll = log
p = push
pf = push --force
pl = pull
r = restore
rb = rebase
rba = rebase --abort
rbc = rebase --continue
s = status --short
sh = show
shno = show --name-only
sw = switch
swc = switch -c

[pull]
rebase = false

Some aliases I need so frequently that I make them available as single or two letter shell aliases via .bashrc:

alias a='git a'
alias b='git b'
alias c='git c'
alias d='git d'
alias g='git'
alias p='git p'
alias ll='ls -al'
alias s='git s'
alias sw='git sw'
alias swb='git switch $(git branch | grep -v \* | fzf)'

Hardware settings

Keyboard

As an avid user of Vim, the escape key is essential to escape edit mode. As the caps lock key is useless to me but easier to reach than the escape key this shell command permantly maps it to the escape key:

gsettings set org.gnome.desktop.input-sources xkb-options "['caps:escape']"

Bluetooth and Wi-Fi

To restore the previous power state of Bluetooth and Wi-Fi on restarts, apply the follow setting. Requires tlp to be installed (see above)

sudo sed -i 's/#\(RESTORE_DEVICE_STATE_ON_STARTUP\)=0/\1=1/' /etc/tlp.conf

CPU performance

In circumstances that require a extra long battery autonomy, I want to the processor to consume as little energy as possible. Therefor I’ve added a function called cpuper to ~/.bashrc which allows setting lower and upper boundaries for the CPU performance as well as enabling/disabling good old turbo mode.

To change the display brightness even below the minimum value, call the following function followed by a brightness value. It defaults to 300 which is pretty low on my system but still readable.

cpuperf() {
  local cpu_vars="min_perf_pct max_perf_pct no_turbo"
  if [ -z "$1" ]; then
    for var in ${cpu_vars}; do
      echo ${var}=$(cat /sys/devices/system/cpu/intel_pstate/${var})
    done
    return 0
  fi
  local min_perf_pct
  local max_perf_pct
  local no_turbo
  case "$1" in
  lowest)
    min_perf_pct=8
    max_perf_pct=25
    no_turbo=1
  ;;
  low)
    min_perf_pct=8
    max_perf_pct=50
    no_turbo=1
  ;;
  high)
    min_perf_pct=50
    max_perf_pct=100
    no_turbo=0
  ;;
  *)
    echo "Invalid value. Possible values are: lowest, low, high"
    return 1
  ;;
  esac
  echo "Applying the following CPU performance settings:"
  for var in ${cpu_vars}; do
    echo $var=${!var}
    echo ${!var} | sudo tee /sys/devices/system/cpu/intel_pstate/${var} > /dev/null
  done
}

Screen

In addition to save on CPU energy consumption, I want to manually control the screen brightness and be able to set it to the lowest value possible - a brightness level that is not available via the systems brightness sliders/hot keys.

brightness() {
  local f="/sys/class/backlight/intel_backlight/brightness"
  if [ -z "$1" ]; then
    cat $f
  else
    local value=$(($1 < 1 ? 1 : $1))
    sudo su -c "echo $value > $f"
  fi
}
comments powered by Disqus