Linux is an incredible (and FREE) way to run a low-resource operating system. For a long time, my personal laptop was running Canonical's Ubuntu. That's one of the more bloated OSs, but it still ran faster than Windows 10 with 4GB of RAM.
It can be fun (though sometimes stressful) to "distro-hop"— spending time on one OS before installing another.I had been using the Regolith distro. This is pre-configured Ubuntu and i3 — a tiling window manager.
Now I've delved into the realm of fancy Apple hardware, and I'm using AeroSpace — an i3 tiling WM for MacOS.
Terminals
One of my favorite part about MacOS is that it is built from UNIX. And my favorite part about UNIX is that it is pretty indistinguishable from Linux when it comes to the command line.
In addition to the desktop tiling, I multi-task in TMux — a terminal "multiplexer"— and edit/write in Vim (now, Neovim ). Here I'll link to my various dotfile setups and resources for setting up a local development environment.
BASH
Click here to view my full .bashrc
file. The items below aren't always up-to-date, but I'll work on a way to fix that...
Emacs vs. Vi modes
Two options that can be set using the set command that will be of some interest to the common user are "-o vi" and "-o emacs". As with all of the environment modifying commands these can be typed at the command prompt or inserted into the appropriate file mentioned above.
Emacs Mode
set -o emacs
- This is usually the default editing mode when in the bash environment and means that you are able to use commands like those in Emacs (defined in the Readline library) to move the cursor, cut and paste text, or undo editing.
- Commands to take advantage of bash's Emacs Mode:
ctrl-a
Move cursor to beginning of linectrl-e
Move cursor to end of linemeta-b
Move cursor back one wordmeta-f
Move cursor forward one wordctrl-w
Cut the last wordctrl-u
Cut everything before the cursorctrl-k
Cut everything after the cursorctrl-y
Paste the last thing to be cutctrl-_
Undo
- NOTE:
ctrl-
= hold control,meta-
= hold meta (where meta is usually the alt or escape key). - A combination of
ctrl-u
to cut the line combined withctrl-y
can be very helpful. If you are in middle of typing a command and need to return to the prompt to retrieve more information you can usectrl-u
to save what you have typed in and after you retrieve the needed informationctrl-y
will recover what was cut.
Vi Mode
set -o vi
- Vi mode allows for the use of
vi
like commands when at the bash prompt. When set to this mode initially you will be in insert mode (be able to type at the prompt unlike when you entervi
). Hitting the escape key takes you into command mode. - Commands to take advantage of bash's Vi Mode:
h
Move cursor leftl
Move cursor rightA
Move cursor to end of line and put in insert mode0
(zero) Move cursor to beginning of line (doesn't put in insert mode)i
Put into insert mode at current positiona
Put into insert mode after current positiondd
Delete line (saved for pasting)D
Delete text after current cursor position (saved for pasting)p
Paste text that was deletedj
Move up through history commandsk
Move down through history commandsu
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└───▶ "
Handy Aliases
Local HTTP Server
For a simple— Node.js-powered— HTTP server, I recommend browser-sync
. It has a watch feature to auto-refresh the browser if it detects changes. Setup a shell alias to run the longer command by simply typing serve
.
npm install -g browser-sync
# 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"
For a simple (Python-powered) server, you can alias the python3
command:
# Run the HTTP server on port 80
alias serve="python3 -m http.server"
Terminal Multiplexer
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"
FFMpeg
# 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
Another tool I found— gifski — makes it easier to get good results, but requires Rust to install.
Low-Quality Image Placeholders (LQIP)
- Must install GO
- Uses the primitive command-line utility
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
polyAll () {
for image in *;
do
poly "$image"
done
}
export -f polyAll
Rofi Notes (RONO)
- Customization of Rofi Notes with Alacritty
- Save script as
rofi_notes.sh
to use with the i3 binding:
#!/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
Browsers
Firefox
Disable Keyboard Shortcuts
First, change the Firefox shortcut settings:
- In Firefox, navigate to
about:config
- Read through the disclaimer and click the "Accept the Risk and Continue" button
- Search for
permissions.default.shortcuts
and click the pencil icon to edit the value - Change the "0" to "2" to allow overriding existing shortcuts
Next, install the Shortkeys Firefox plugin:
- After installing, restart Firefox. Quit and re-open.
- Click the add-on puzzle piece icon and find "Manage extensions" at the bottom, click it.
- Click the gear icon to the right of the "Manage Your Extensions" heading.
- In the dropdown, click "Manage Extension Shortcuts"
- Scroll down the list to the Shortkeys extension and setup your shortcuts!
- I like
Cmd+,
andCmd+.
for navigating prev/next tab, respectively.
- I like
Editors
Vim
You can find my full .vimrc
here
Status lines
This is a configuration example for vim-airline
let g:airline_powerline_fonts=1
let g:airline#extensions#tabline#enabled=1
let g:airline_theme='luna'
You might also try Lightline
let g:lightline = {
\ 'colorscheme' : 'seoul256'
\ }
Other Nice Plugins
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()
Colorschemes
Take a look at vim-colors for some awesome 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'}]
Mobile
You must install scrcpy and connect your Android device to your computer with USB-debugging enabled .
alias android='scrcpy --max-size 1080 --window-x 1920 --window-y 1080 --window-borderless -S'
alias androidF='android --fullscreen'