diff options
-rwxr-xr-x | bin/extra/tmux-sessionizer | 36 | ||||
-rwxr-xr-x | config/common/tmux/tmux.conf | 2 | ||||
-rw-r--r-- | config/essentials/zsh/widgets.zsh | 2 |
3 files changed, 40 insertions, 0 deletions
diff --git a/bin/extra/tmux-sessionizer b/bin/extra/tmux-sessionizer new file mode 100755 index 0000000..8b04b0b --- /dev/null +++ b/bin/extra/tmux-sessionizer @@ -0,0 +1,36 @@ +#!/bin/sh + +if [ $# -eq 1 ]; then + selected="$1" +else + pfx="$HOME/proj" + d="$(find "$pfx" -mindepth 1 -maxdepth 1 -type d | sed "s@$pfx/@@" | fzf)" + { [ "$d" ] && [ -d "$pfx/$d" ]; } || exit 1 + selected="${d##*/}" +fi +>&2 printf 'selected: %s\n' "$selected" + +if [ -z "$selected" ]; then + exit 0 +fi + +selected_name="$(basename "$selected" | tr '.' '_')" +tmux_running="$(pgrep "tmux" | head -n1)" + +>&2 printf 'tmux_running: "%s"\n' "$tmux_running" +>&2 printf 'selected_name: %s\n' "$selected_name" + +if [ -z $TMUX ] && [ -z "$tmux_running" ]; then + tmux new-session -s "$selected_name" -c "$selected" + exit 0 +fi + +if ! tmux has-session -t="$selected_name" 2> /dev/null; then + tmux new-session -ds "$selected_name" -c "$selected" +fi + +if [ -z $TMUX ]; then + tmux attach -t "$selected_name" +else + tmux switch-client -t "$selected_name" +fi diff --git a/config/common/tmux/tmux.conf b/config/common/tmux/tmux.conf index 0f35fb9..7fc73b0 100755 --- a/config/common/tmux/tmux.conf +++ b/config/common/tmux/tmux.conf @@ -106,6 +106,8 @@ bind S choose-tree -Z # Menu for mounting and ejecting devices. bind E display-menu -T "#[align=centre]#I:#W" -x W -y W '' Mount 0 "display-popup -E 'amount'" +bind-key -r f run-shell "tmux neww tmux-sessionizer" + # Theme #+---------+ diff --git a/config/essentials/zsh/widgets.zsh b/config/essentials/zsh/widgets.zsh index cce9fbc..71d33cf 100644 --- a/config/essentials/zsh/widgets.zsh +++ b/config/essentials/zsh/widgets.zsh @@ -13,3 +13,5 @@ insert-last-command-output() { } zle -N insert-last-command-output bindkey "^Xl" insert-last-command-output + +bindkey -s "^f" "tmux-sessionizer\n" |