feat: add tmux-sessioner script

Add a script for quickly navigating between directories using fzf and
tmux sessions. Executable within zsh and Vim.
This commit is contained in:
Oliver Davies 2021-09-17 19:42:11 +01:00
parent 2f2c020719
commit 73e76b4d97
3 changed files with 33 additions and 0 deletions

29
bin/bin/tmux-sessioniser Executable file
View file

@ -0,0 +1,29 @@
#!/bin/bash
# Quickly navigate between different directories using fzf and tmux sessions
# (Thanks, ThePrimeagen!).
#
# https://github.com/ThePrimeagen/.dotfiles/blob/master/bin/.local/bin/tmux-sessionizer
# https://frontendmasters.com/workshops/dev-productivity
if [[ $# -eq 1 ]]; then
selected=$1
else
# Get the session name from fuzzy-finding list of directories and generating a
# tmux-safe version.
selected=$(find ~/ ~/Code ~/Code/clients ~/Code/os ~/Code/Personal ~/Documents/Talks/ -mindepth 1 -maxdepth 1 -type d | fzf)
fi
selected_name=$(basename "$selected" | tr . -)
if [[ -z $selected ]]; then
exit 0
fi
# Create a new session if tmux does not already have a session matching the
# selected session name.
if ! tmux has-session -t $selected_name 2> /dev/null; then
tmux new-session -s $selected_name -c $selected -d
fi
tmux switch-client -t $selected_name

View file

@ -55,4 +55,6 @@ autocmd FileType gitcommit setlocal spell
" Display extra whitespace " Display extra whitespace
set list listchars=tab:»·,trail set list listchars=tab:»·,trail
nnoremap <silent> <C-f> :silent !tmux neww tmux-sessioniser<CR>
lua require("opdavies") lua require("opdavies")

View file

@ -33,5 +33,7 @@ _load_settings() {
_load_settings "$HOME/.zsh/configs" _load_settings "$HOME/.zsh/configs"
bindkey -s "^f" "tmux-sessioniser\n"
# Local config # Local config
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local [[ -f ~/.zshrc.local ]] && source ~/.zshrc.local