From 31ba966020616a3b7fe0feefc265f8cb89f5cad2 Mon Sep 17 00:00:00 2001 From: pr0c3550r Date: Sat, 21 Oct 2023 19:41:51 +0200 Subject: [PATCH] Tmux: improve tmux-sessionizer-script --- tmux/.config/tmux/tmux-sessionizer | 27 +++++++++++++++++++-------- tmux/.config/tmux/tmux.conf | 19 ++++++++++++------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/tmux/.config/tmux/tmux-sessionizer b/tmux/.config/tmux/tmux-sessionizer index 62b2e63..86048ec 100755 --- a/tmux/.config/tmux/tmux-sessionizer +++ b/tmux/.config/tmux/tmux-sessionizer @@ -1,12 +1,23 @@ #!/usr/bin/bash -read -p "New session name: " SEL -if [[ -z $SEL ]]; then - echo "No session name specified" - exit 1 -fi -SEL_NAME=$(tr "[:lower:]" "[:upper:]" <<< "$SEL") -WORK_DIR=$(find ~ -not -path "*/.*" -type d -print 2>/dev/null | fzf) +HOMEDIR=~ +SEL_DIR=$(find ~ -not -path "*/.*" -type d -print 2>/dev/null | fzf) +SEL_NAME=$(basename "$SEL_DIR") -tmux new-session -d -s "$SEL_NAME" -c "$WORK_DIR" +if [[ -z "$SEL_DIR" ]] || [[ -n "$SEL_DIR" ]] && [[ "$SEL_DIR" == "$HOMEDIR" ]]; then + RET=0 + while [[ $RET -eq 0 ]]; do + read -p "New session name: " SEL_NAME + if [[ -z "$SEL_NAME" ]]; then + clear + else + RET=1 + fi + done +fi + +SEL_NAME=$(tr "[:lower:]" "[:upper:]" <<< "$SEL_NAME") + +tmux new-session -d -s "$SEL_NAME" -c "$SEL_DIR" tmux switch-client -t "$SEL_NAME" + diff --git a/tmux/.config/tmux/tmux.conf b/tmux/.config/tmux/tmux.conf index 5265b96..800d7cd 100644 --- a/tmux/.config/tmux/tmux.conf +++ b/tmux/.config/tmux/tmux.conf @@ -20,15 +20,16 @@ bind - split-window -v -c '#{pane_current_path}' bind c new-window -c '#{pane_current_path}' +bind -r ^ last-window bind -r h select-pane -L bind -r j select-pane -D bind -r k select-pane -U bind -r l select-pane -R -bind -r H resize-pane -L 2 -bind -r J resize-pane -D 2 -bind -r K resize-pane -U 2 -bind -r L resize-pane -R 2 +bind -r H resize-pane -L 4 +bind -r J resize-pane -D 4 +bind -r K resize-pane -U 4 +bind -r L resize-pane -R 4 bind -r n next-window bind -r p previous-window @@ -36,7 +37,13 @@ bind -r p previous-window bind X confirm kill-window bind T confirm kill-session -bind M set -g mouse +bind -r M set -g mouse + +set-window-option -g mode-keys vi +bind -T copy-mode-vi v send-keys -X begin-selection +bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' + +bind -r S run-shell "tmux new-window ~/.config/tmux/tmux-sessionizer" set -g pane-border-indicators colour set -g pane-active-border-style fg="#d8a657",bg=default @@ -68,5 +75,3 @@ set -g cursor-style blinking-underline set -g focus-events on set -g visual-bell off - -set -g mouse on