From ffc1d51d78dc86a8540d0e9d56e81096120ef972 Mon Sep 17 00:00:00 2001 From: Max Bucknell Date: Sun, 10 Mar 2019 11:54:54 +0000 Subject: [PATCH] Automatically sign me into Tmux --- zsh/zshrc.symlink | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/zsh/zshrc.symlink b/zsh/zshrc.symlink index bc23f2b..8e249f1 100644 --- a/zsh/zshrc.symlink +++ b/zsh/zshrc.symlink @@ -159,3 +159,33 @@ source "$HOME/.zsh/liquidprompt/liquidprompt" # Vim! alias vim=nvim + +# Use fzf to select a running tmux session to attach to +function select_session_interactive { + tmux list-sessions | + cut -d":" -f 1 | + cat - <(echo "Create new session") | + fzf --height 30% --layout=reverse --border +} + +# On startup, I want to be prompted to join a Tmux session. +# +# Simply cancelling the command will leave me in native terminal mode. +function select_session { + if [ -z "$TMUX" ] + then + local selected_session=$(select_session_interactive) + + if [[ "$selected_session" == "Create new session" ]] + then + echo -n "Session name: " + read new_session_name + tmux new-session -s "$new_session_name" + elif [[ -n "$selected_session" ]] + then + tmux attach -t "$selected_session" + fi + fi +} + +select_session