From 73e76b4d97a33ac86e01a01bde687d0264c122c5 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 17 Sep 2021 19:42:11 +0100 Subject: [PATCH] feat: add tmux-sessioner script Add a script for quickly navigating between directories using fzf and tmux sessions. Executable within zsh and Vim. --- bin/bin/tmux-sessioniser | 29 +++++++++++++++++++++++++++++ nvim/.config/nvim/init.vim | 2 ++ zsh/.zshrc | 2 ++ 3 files changed, 33 insertions(+) create mode 100755 bin/bin/tmux-sessioniser diff --git a/bin/bin/tmux-sessioniser b/bin/bin/tmux-sessioniser new file mode 100755 index 0000000..9c53b51 --- /dev/null +++ b/bin/bin/tmux-sessioniser @@ -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 diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim index 76be301..1936dc9 100644 --- a/nvim/.config/nvim/init.vim +++ b/nvim/.config/nvim/init.vim @@ -55,4 +55,6 @@ autocmd FileType gitcommit setlocal spell " Display extra whitespace set list listchars=tab:»·,trail:· +nnoremap :silent !tmux neww tmux-sessioniser + lua require("opdavies") diff --git a/zsh/.zshrc b/zsh/.zshrc index bc2b3e8..85a7ff1 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -33,5 +33,7 @@ _load_settings() { _load_settings "$HOME/.zsh/configs" +bindkey -s "^f" "tmux-sessioniser\n" + # Local config [[ -f ~/.zshrc.local ]] && source ~/.zshrc.local