From 75118befd94baa95be0da4e9981882ae7b5570f9 Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Wed, 24 Apr 2024 10:36:12 +0930 Subject: [PATCH] feat: add tmux-sessionizer --- .config/tmux/plugins/tmux | 1 - .config/tmux/plugins/tmux-sensible | 1 - .config/tmux/plugins/tmux-tokyo-night | 1 - .config/tmux/plugins/tpm | 1 - .local/bin/tmux-sessionizer | 25 ++++++++++++++++ .config/tmux/tmux.conf => .tmux.conf | 41 ++++++++++++++++----------- .zshrc | 3 ++ 7 files changed, 53 insertions(+), 20 deletions(-) delete mode 160000 .config/tmux/plugins/tmux delete mode 160000 .config/tmux/plugins/tmux-sensible delete mode 160000 .config/tmux/plugins/tmux-tokyo-night delete mode 160000 .config/tmux/plugins/tpm create mode 100755 .local/bin/tmux-sessionizer rename .config/tmux/tmux.conf => .tmux.conf (78%) diff --git a/.config/tmux/plugins/tmux b/.config/tmux/plugins/tmux deleted file mode 160000 index a556353..0000000 --- a/.config/tmux/plugins/tmux +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a556353d60833367b13739e660d4057a96f2f4fe diff --git a/.config/tmux/plugins/tmux-sensible b/.config/tmux/plugins/tmux-sensible deleted file mode 160000 index 25cb91f..0000000 --- a/.config/tmux/plugins/tmux-sensible +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 25cb91f42d020f675bb0a2ce3fbd3a5d96119efa diff --git a/.config/tmux/plugins/tmux-tokyo-night b/.config/tmux/plugins/tmux-tokyo-night deleted file mode 160000 index ee73d4a..0000000 --- a/.config/tmux/plugins/tmux-tokyo-night +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ee73d4a9ba6222d7d51492a4e0e797c9249a879c diff --git a/.config/tmux/plugins/tpm b/.config/tmux/plugins/tpm deleted file mode 160000 index 99469c4..0000000 --- a/.config/tmux/plugins/tpm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 99469c4a9b1ccf77fade25842dc7bafbc8ce9946 diff --git a/.local/bin/tmux-sessionizer b/.local/bin/tmux-sessionizer new file mode 100755 index 0000000..a6932e4 --- /dev/null +++ b/.local/bin/tmux-sessionizer @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +if [[ $# -eq 1 ]]; then + selected=$1 +else + selected=$(find ~/Projects ~/go/src/git.tovijaeschke.xyz ~/ -mindepth 1 -maxdepth 1 -type d | fzf) +fi + +if [[ -z $selected ]]; then + exit 0 +fi + +selected_name=$(basename "$selected" | tr . _) +tmux_running=$(pgrep tmux) + +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 + +tmux switch-client -t $selected_name diff --git a/.config/tmux/tmux.conf b/.tmux.conf similarity index 78% rename from .config/tmux/tmux.conf rename to .tmux.conf index 5d0c5e5..097ec55 100644 --- a/.config/tmux/tmux.conf +++ b/.tmux.conf @@ -1,21 +1,7 @@ -# List of plugins -set -g @plugin 'tmux-plugins/tpm' -set -g @plugin 'tmux-plugins/tmux-sensible' - -set -g @plugin 'catppuccin/tmux' -# set -g @plugin 'fabioluciano/tmux-tokyo-night' - -# Colour scheme -# set -g @theme_variation 'moon' -# set -g @theme_left_separator ' ' -# set -g @theme_right_separator ' ' - -set -g @catppuccin_flavour 'mocha' # or frappe, macchiato, mocha -set -g @catppuccin_status_left_separator " " -set -g @catppuccin_status_right_separator "" +set -g default-terminal "screen-256color" # easy reload config -bind-key r source-file ~/.config/tmux/tmux.conf \; display-message "~/.config/tmux/tmux.conf reloaded." +bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded." set-option -g status-position top @@ -52,12 +38,35 @@ bind-key -T copy-mode-vi 'C-l' if -F '#{pane_at_right}' '' 'select-pane -R' bind-key C command-prompt -p "Name of new window: " "new-window -n '%%'" +bind -r j resize-pane -D 5 +bind -r k resize-pane -U 5 +bind -r l resize-pane -R 5 +bind -r h resize-pane -L 5 + set-window-option -g mode-keys vi +bind-key -T copy-mode-vi 'v' send -X begin-selection +bind-key -T copy-mode-vi 'y' send -X copy-selection + bind 'V' copy-mode # Enable mouse control (clickable windows, panes, resizable panes) set -g mouse on +unbind -T copy-mode-vi MouseDragEnd1Pane + +bind S command-prompt -p "New Session:" "new-session -A -s '%%'" +bind K confirm kill-session + +bind-key -r f run-shell "tmux neww ~/.local/bin/tmux-sessionizer" + +# List of plugins +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' + +set -g @plugin 'catppuccin/tmux' + +set -g @catppuccin_flavour 'mocha' # or frappe, macchiato, mocha + # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) run '~/.tmux/plugins/tpm/tpm' diff --git a/.zshrc b/.zshrc index 1b498a5..649c70f 100644 --- a/.zshrc +++ b/.zshrc @@ -36,6 +36,9 @@ SAVEHIST=$HISTSIZE # Beep on error setopt BEEP +export PATH="~/.local/bin/:$PATH" +export PATH="~/dotfiles/.local/bin/:$PATH" + # Use keycodes (generated via zkbd) if present, otherwise fallback on # values from terminfo if [[ -r ${ZDOTDIR:-$HOME}/.zkbd/${TERM}-${VENDOR} ]] ; then