Developer Tools
My preferred dev setup, regardless of projects:
macOS + iTerm2 + Zsh + mosh + tmux + vim + vscode
iTerm2
- Go to iTerm2 Preferences.
- Show Additional Info -
Preferences -> Profiles -> Session -> Status bar enabled -> Configure Status Bar
- Adjust Additional Info Location -
Preferences -> Apperance -> Status bar location
. - Adjust Blinking Cursor -
Preferences -> Profiles -> Text -> Blinking cursor
. You can also select Cursor type between Underline / Vertical bar / Box. - Choose a Font - After Powerlevel10k installation,
Preferences -> Profiles -> Text
, click Change under Font and select MesloLGS NF family. - Choose a color scheme -
Preferences -> Profiles -> Colors -> Color Presets
. For customization, please go to iTerm2-color, choose a color scheme you prefer, click the name and right click to save the file as.itermcolors
(you may need to delete .txt). Then, you can import at Color Presets.
Zsh
Install Oh My Zsh
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Powerlevel10k
$ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
modify ~/.zshrc
ZSH_THEME="powerlevel10k/powerlevel10k"
Plugins
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Add the following to ~/.zshrc
plugins=(
# other plugins...
zsh-autosuggestions
zsh-syntax-highlighting
)
mosh
Use mosh instead of ssh
mosh + tmux
$ mosh -6 [dev-server-address or ssh alias] -- tmux a
You can create an alias in your bash profile so you don't need to type the above command
alias dev="mosh -6 [dev-server-address or ssh alias] -- tmux a"
Detached Sessions
You may see messages like this:
Mosh: You have a detached Mosh session on this server (mosh [12345]).
For security reasons, you can not reattach.
To kill the session:
$ kill 12345
To kill all mosh connections:
$ kill `pidof mosh-server`
Alternative: Eternal Terminal (et) https://github.com/MisterTea/EternalTerminal
tmux
2 big features:
- Window management: could be achieved by using modern terminals like iTerm2
- Session management: detaching from and attaching to sessions; very useful for remote working (running jobs on remote / cloud dev servers).
Why does using a terminal multiplexer help?
- Upon laptop crash/reboot, you lose no state from the multiplexed terminal sessions on your (dev) server
- you can search scrolled screen content quickly and mechanically
- you can easily disconnect/reconnect a "session" -- no more HUPs
- platform independence: use tmux on Macbook, Linux notebook / desktop, servers, Raspberry Pis, etc.
- customizable: customize the look and behavior of the tmux environment. And sync this across different platforms using a simple dotfile
- share screens: it can "mirror" its session on multiple screens. If two users log into the same Tmux session, then they both see the same output on their screens in real time. (e.g. for training someone remotely, debugging a command that isn't working for them, reviewing text, monitoring services or processes)
e.g., you're in the middle of a 20-minute run that you did not protect via nohup, when you need to go to a meeting or catch a bus. With neither mosh nor screen/tmux, you'd lose the ssh connection.
tmux is based on a client-server architecture. The tmux server keeps track of all the running sessions. You will only ever work with the tmux client and create new sessions or connect to existing ones.
Concepts:
- Sessions are collections of windows that can be detached and reattached later.
- Windows may contain one or more panes.
Configuration
Enable scrollback: Create or edit ~/.tmux.conf
on the server and add the following commands:
new-session
set-option -g mouse on
set -g history-limit 30000
Session
#S
: name of the session.
If not named, the name is a number, shown at the bottom left in status bar like [0]
Essential Command line Tools
- bash scripting: for hacky-small tools as well as command line use learn how to use
&&
and||
-- much more concise thanif/then/else/fi
find
+xargs
sed
,grep
(-A,-B,-C,-v),awk
for extracting columns- use
&&
to concat commands instead of;
so right hand command will only run if left hand command succeeds - Query JSON: https://stedolan.github.io/jq/download/
- Query YAML: https://github.com/mikefarah/yq
htop
: A better topranger
: A better file browser- Copy files:
pv
(pipe view) - fundamental eight: Learn
grep
,sed
,cut
,sort
,uniq
,head
,tai
l, andxargs
. These eight tools make up the commands you'll be running most often on the command line when doing text processing.
Use Vim keystrokes on the command line
"vi editing mode" (the default is "emacs mode")
set -o vi
add this to ~/.bashrc
# Enable Vi key bindings
set -o vi
Tell tools to save your history
echo HISTSIZE=130000 HISTFILESIZE=-1 >> ~/.bashrc
echo set -g history-limit 30000 >> ~/.tmux.conf
Avoid unnecessary prompts (avoid slow-down and risk of wrong answer)
Use --backup
options to cp
, ln
, mv
:
alias cp='cp --backup=numbered'
alias ln='ln --backup=numbered'
alias mv='mv -f --backup=numbered'
This option is only supported by GNU coreutils
, not by the BSD versions that come with OS X. It’s possible to install GNU coreutils
, e.g. with brew install coreutils
. To override the builtins, follow the instructions printed by brew info coreutils.
Use the env
prefix to avoid the alias and instead invoke the bare program.
Use incremental search (^R, aka Control-R)
- in your editor
- when searching shell history
- when searching through contents of scrolled screen log
- in gdb
- in any other readline-based tool (they all honor ~/.inputrc)
If you use vi/vim, run this and restart any existing bash shell:
echo set editing-mode vi >> ~/.inputrc
If you use zsh in vi mode, add this to ensure ^R
still does what we expect:
echo 'bindkey "^R" history-incremental-search-backward' >> ~/.zshrc
Some custom key bindings
~/.inputrc
is the config file for readline, which is used in many interactive programs such as bash and gdb. The following key bindings will make your life easier.
Remember to restart bash after modifying ~/.inputrc
.
Cycle through commands to a partial match
Add the following two lines to your ~/.inputrc (note all the quotation marks, don't echo it!).
echo '"\e[A": history-search-backward' >> ~/.inputrc
echo '"\e[B": history-search-forward' >> ~/.inputrc
Type in a few chars of a command in history and use arrow (up/down) keys to cycle through all commands that start with the typed in chars.
Delete word for bash command line (^W, aka Control-W)
echo '"\C-w": backward-delete-word' >> ~/.inputrc
Setting vim as your default
Many command-line utilities check the $EDITOR
and $VISUAL
environment variables to determine how to open files for editing or display.
export EDITOR=vim
export VISUAL=vim
to your ~/.profile
or ~/.bashrc
.
To use vim for git, add
[core]
editor=vim
to your ~/.gitconfig
.