En­vi­ron­ments

10:12AMJune 7 2020Daniel Tompkins

Archive KB

Linux is an in­cred­ible (and FREE) way to run a low-re­source op­er­ating system. For a long time, my per­sonal laptop was run­ning Canon­ical's Ubuntu. That's one of the more bloated OSs, but it still ran faster than Win­dows 10 with 4GB of RAM.

It can be fun (though some­times stressful) to "distro-hop"— spending time on one OS be­fore in­stalling an­other.I had been using the Re­golith distro. This is pre-con­fig­ured Ubuntu and i3 — a tiling window man­ager.

Now I've delved into the realm of fancy Apple hard­ware, and I'm using Aero­Space — an i3 tiling WM for MacOS.

Ter­mi­nals

One of my fa­vorite part about MacOS is that it is built from UNIX. And my fa­vorite part about UNIX is that it is pretty in­dis­tin­guish­able from Linux when it comes to the com­mand line.

Jurrasic Park (1993)

In ad­di­tion to the desktop tiling, I multi-task in TMux — a ter­minal "mul­ti­plexer"— and edit/​write in Vim (now, Neovim ). Here I'll link to my var­ious dot­file se­tups and re­sources for set­ting up a local de­vel­op­ment en­vi­ron­ment.

BASH

Click here to view my full .bashrc file. The items below aren't al­ways up-to-date, but I'll work on a way to fix that...

Emacs vs. Vi modes

Two op­tions that can be set using the set com­mand that will be of some in­terest to the common user are "-o vi" and "-o emacs". As with all of the en­vi­ron­ment mod­i­fying com­mands these can be typed at the com­mand prompt or in­serted into the ap­pro­priate file men­tioned above.

Emacs Mode

set -o emacs
bash
  • This is usu­ally the de­fault editing mode when in the bash en­vi­ron­ment and means that you are able to use com­mands like those in Emacs (de­fined in the Read­line li­brary) to move the cursor, cut and paste text, or undo editing.
  • Com­mands to take ad­van­tage of bash's Emacs Mode:
    • ctrl-a Move cursor to be­gin­ning of line
    • ctrl-e Move cursor to end of line
    • meta-b Move cursor back one word
    • meta-f Move cursor for­ward one word
    • ctrl-w Cut the last word
    • ctrl-u Cut every­thing be­fore the cursor
    • ctrl-k Cut every­thing after the cursor
    • ctrl-y Paste the last thing to be cut
    • ctrl-_ Undo
  • NOTE: ctrl- = hold con­trol, meta- = hold meta (where meta is usu­ally the alt or es­cape key).
  • A com­bi­na­tion of ctrl-u to cut the line com­bined with ctrl-y can be very helpful. If you are in middle of typing a com­mand and need to re­turn to the prompt to re­trieve more in­for­ma­tion you can use ctrl-u to save what you have typed in and after you re­trieve the needed in­for­ma­tion ctrl-y will re­cover what was cut.

Vi Mode

set -o vi
bash
  • Vi mode al­lows for the use of vi like com­mands when at the bash prompt. When set to this mode ini­tially you will be in in­sert mode (be able to type at the prompt un­like when you enter vi). Hit­ting the es­cape key takes you into com­mand mode.
  • Com­mands to take ad­van­tage of bash's Vi Mode:
    • h Move cursor left
    • l Move cursor right
    • A Move cursor to end of line and put in in­sert mode
    • 0 (zero) Move cursor to be­gin­ning of line (doesn't put in in­sert mode)
    • i Put into in­sert mode at cur­rent po­si­tion
    • a Put into in­sert mode after cur­rent po­si­tion
    • dd Delete line (saved for pasting)
    • D Delete text after cur­rent cursor po­si­tion (saved for pasting)
    • p Paste text that was deleted
    • j Move up through his­tory com­mands
    • k Move down through his­tory com­mands
    • u Undo

Pretty Bash Prompts

RCol='\033[0m' Gre='\033[32m' Red='\033[31m' Blu='\033[34m' Yel='\033[33m' PS1="${RCol}┌─[\`if [ \$? = 0 ]; then echo "${Gre}"; else echo "${Red}"; fi\`\T\[${Rcol}\] \[${Blu}\]\u@\h\[${RCol}\] \[${Yel}\]\w\[${RCol}\]\$(__git_ps1)]\n└───▶ "
bash

Handy Aliases

Local HTTP Server

For a simple— Node.js-pow­ered— HTTP server, I rec­om­mend browser-sync. It has a watch fea­ture to auto-re­fresh the browser if it de­tects changes. Setup a shell alias to run the longer com­mand by simply typing serve.

Install Browser Sync
npm install -g browser-sync
shell
Setup a shell alias
# If using a virtual environment (or WSL), you can set your local IP address to the "host" argument like so: export ip4=$(ifdata -pa wlp2s0) # Set the full command to an alias (in your ~/.bashrc) for ease-of-use: alias serve="browser-sync start -s -f . --no-notify --extensions 'html' --host $ip4 --port 9000"
bash

For a simple (Python-pow­ered) server, you can alias the python3 com­mand:

Simple local server alias (Python).
# Run the HTTP server on port 80 alias serve="python3 -m http.server"
bash

Ter­minal Mul­ti­plexer

Quick and simple Tmux aliases
alias td="tmux detach" alias t0="tmux attach -t 0" alias t1="tmux attach -t 1" alias t2="tmux attach -t 2" alias tmain="tmux attach -t main"
bash

FFMpeg

Make GIFs from the terminal with these bash aliases
# Make a video from a folder of PNG frames alias mkvid="ffmpeg -r 1 -f image2 -pattern_type glob -i "*.png" -vf scale=720:480 -filter:v "crop=in_w:480" -vcodec libx264 -crf 0 -pix_fmt yuv444p test.mp4" # Convert an mp4 video to GIF format alias convgif="ffmpeg -i test.mp4 -vf scale=iw/2:ih/2 -f gif test.gif" # Make a GIF from a folder of images function mkgif() { ffmpeg -pattern_type glob -r 1 -i "$1" -vf "scale='min(640,iw)':'min(480,ih)':force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2" -pix_fmt yuv420p -f gif output.gif } export -f mkgif
bash

An­other tool I found— gifski — makes it easier to get good re­sults, but re­quires Rust to in­stall.

Low-Quality Image Place­holders (LQIP)

Polygonized LQIP image for single file
function poly() { if [ ${1##*.} != "gif" ] then primitive -i $1 -o lqip/${1%.*}-lqip.${1##*.} -r 64 -s 64 -bg 'avg' -n 150 -v fi if [ ${1##*.} = "gif" ] then convert "$1[0]" temp.gif primitive -i temp.gif -o lqip/${1%.*}-lqip.jpg -bg 'avg' -r 64 -s 64 -n 150 -v rm temp.gif fi } export -f poly
bash
Polygonized LQIP images for all images in a directory
polyAll () { for image in *; do poly "$image" done } export -f polyAll
bash

Rofi Notes (RONO)

  • Cus­tomiza­tion of Rofi Notes with Alacritty
  • Save script as rofi_notes.sh to use with the i3 binding:
bindsym $mod+s exec rofi_notes.sh -a 'Daniel Tompkins' -e 'nvim' -o $HOME/.scratch/
#!/usr/bin/env bash while getopts ":a:e:l:o:" opt; do case $opt in a) AUTHOR="$OPTARG" ;; e) EDITOR="$OPTARG" ;; l) LOOK="$OPTARG" ;; o) NOTES_FOLDER="$OPTARG" ;; \?) echo "Invalid option -$OPTARG" >&2 ;; esac done if [[ ! -d "${NOTES_FOLDER}" ]]; then mkdir -p "$NOTES_FOLDER" fi get_notes() { ls "${NOTES_FOLDER}" } edit_note() { note_location=$1 alacritty -t 'alacritty-floating' -e $EDITOR -c "${LOOK}" "$note_location" } delete_note() { local note=$1 local action=$(echo -e "yes\nno" | rofi -dmenu -p "Are you sure you want to delete $note? ") case $action in "yes") rm "$NOTES_FOLDER/$note" main ;; "no") main esac } note_context() { local note=$1 local note_location="$NOTES_FOLDER/$note" local action=$(echo -e "edit\ndelete" | rofi -dmenu -p "$note ") case $action in "edit") edit_note "$note_location" ;; "delete") delete_note "$note" esac } new_note() { local title=$(echo -e "cancel" | rofi -dmenu -p "input title ") case "$title" in "cancel") main ;; *) local file=$(echo "$title" | sed 's/ /_/g;s/\(.*\)/\L\1/g') local template=$(cat <<- END --- title: $title date: $(date --rfc-3339=seconds) author: $AUTHOR --- # $title END ) note_location="$NOTES_FOLDER/$file.md" if [ "$title" != "" ]; then echo "$template" > "$note_location" | edit_note "$note_location" fi ;; esac } main() { local all_notes="$(get_notes)" local first_menu="NEW" if [ "$all_notes" ];then first_menu="NEW\n${all_notes}" fi local note=$(echo -e "$first_menu" | rofi -dmenu -p "notes ") case $note in "NEW") new_note ;; "") ;; *) note_context "$note" esac } main
bash

Browsers

Firefox

Dis­able Key­board Short­cuts

First, change the Firefox shortcut set­tings:

  • In Firefox, nav­i­gate to about:config
  • Read through the dis­claimer and click the "Ac­cept the Risk and Con­tinue" button
  • Search for permissions.default.shortcuts and click the pencil icon to edit the value
  • Change the "0" to "2" to allow over­riding ex­isting short­cuts

Next, in­stall the Short­keys Firefox plugin:

  • After in­stalling, restart Firefox. Quit and re-open.
  • Click the add-on puzzle piece icon and find "Manage ex­ten­sions" at the bottom, click it.
  • Click the gear icon to the right of the "Manage Your Ex­ten­sions" heading.
    • In the drop­down, click "Manage Ex­ten­sion Short­cuts"
  • Scroll down the list to the Short­keys ex­ten­sion and setup your short­cuts!
    • I like Cmd+, and Cmd+. for nav­i­gating prev/​next tab, re­spec­tively.

Ed­i­tors

Vim

You can find my full .vimrc here

Status lines

This is a con­fig­u­ra­tion ex­ample for vim-air­line

let g:airline_powerline_fonts=1 let g:airline#extensions#tabline#enabled=1 let g:airline_theme='luna'
vimscript

You might also try Light­line

let g:lightline = { \ 'colorscheme' : 'seoul256' \ }
vimscript

Other Nice Plu­gins

call plug#begin('~/.vim/plugged') Plug 'vimwiki/vimwiki' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' Plug 'edkolev/tmuxline.vim' Plug 'junegunn/goyo.vim' Plug 'scrooloose/nerdtree' Plug 'inkarkat/vim-SpellCheck' Plug 'inkarkat/vim-ingo-library' Plug 'etdev/vim-hexcolor' Plug 'chrisbra/Colorizer' Plug 'junegunn/vim-emoji' Plug 'vim-scripts/AutoComplPop' call plug#end()
vimscript

Col­orschemes

Take a look at vim-colors for some awe­some color schemes that will spruce up your edits.

VimWiki

let g:vimwiki_list = [{'path': '~/vimwiki/', \ 'syntax': 'markdown', \ 'template_path': '~/vimwiki/templates/', \ 'template_default': 'default', \ 'ext': '.md', \ 'path_html': '/var/www/l-o-o-s-e-d/html/knowledge-base/', \ 'custom_wiki2html': 'vimwiki_markdown', \ 'template_ext': '.tpl'}]
vimscript

Mo­bile

You must in­stall scrcpy and con­nect your An­droid de­vice to your com­puter with USB-de­bug­ging en­abled .

Mirror a USB-connected Android device
alias android='scrcpy --max-size 1080 --window-x 1920 --window-y 1080 --window-borderless -S' alias androidF='android --fullscreen'
bash