Switch to previous session in tmux


I recently setup <prefix> + to switch to the previous tmux session. Super handy to switch fast between two projects, for example backend and frontend.

bind + switch-client -l



I have recently been trying to do a proper setup of tmux and as a part of it i made this little shell function to make re-attaching sessions a bit easier. It will give fzf prompt with available sessions if called without a session name. On the other hand when called with a session name it will check if it exists and attach or create based on the result.

tx() {
if [ -z ${1+x} ]; then
session=$(tmux list-sessions | fzf | awk '{print $1}' | sed 's/:$//' )
tmux a -t $session
if tmux list-sessions | grep $1 2>&1 > /dev/null; then
tmux a -t $1
tmux new -s $1
_tx() {
sessions=$(tmux list-sessions 2>/dev/null)
if [[ -z "$1" ]]; then
echo $sessions | awk '{split($0,a,":"); print a[1]}'
echo $sessions | awk '{split($0,a,":"); print a[1]}' | grep --color=never $1
complete -C _tx tx

Alias filetypes


Creating aliases with -s enables aliasing commands too files types. Thus, with the alias alias -s txt=less turns ./file.txt into less ./file.txt

Other examples:

alias -s md=glow
alias -s html=open
alias -s txt=less
alias -s json=jq

Recent branches with fzf


Not something I learned today, but i recently configured a alias for recent branches with fuzzy search with fzf. It will show the branches sorted by the date of the head commit when doing git recent. Selecting one with fzf will then do a git checkout of that branch.

Add the following under aliases in gitconfig:

recent = "!git branch --sort=-committerdate --format=\"%(committerdate:relative)%09%(refname:short)\" | fzf --ansi | awk 'BEGIN{FS=\"\t\"} {print $2}' | xargs git checkout"

zz in vim centers line on screen


Learned today that in normal mode in vim typing zz will center the active line in the middle of the screen.