diff --git a/.tmux.conf b/.tmux.conf new file mode 100644 index 00000000..a274275c --- /dev/null +++ b/.tmux.conf @@ -0,0 +1,27 @@ +bind-key -r f run-shell "tmux neww ~/repo/config/tmux-s" + +set-option -g prefix C-Space +unbind C-b +bind C-Space send-prefix + +setw -g mode-keys vi +bind -T copy-mode-vi v send -X begin-selection +bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" +bind P paste-buffer +bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy" + +set -g mouse on +set -g base-index 1 + +set -g status-style 'fg=red' +set -g status-left ' #S ' +set -g status-left-length 20 +set -g status-right '' +set -g status-bg black + +setw -g window-status-current-style 'fg=black bg=red' +setw -g window-status-current-format ' #I #W #F ' +setw -g window-status-style 'fg=red bg=black' +setw -g window-status-format ' #I #[fg=white]#W #[fg=yellow]#F ' +setw -g window-status-bell-style 'fg=yellow bg=red bold' + diff --git a/tmux-s b/tmux-s new file mode 100755 index 00000000..4a0bfa57 --- /dev/null +++ b/tmux-s @@ -0,0 +1,67 @@ +#!/bin/bash + +TS_SEARCH_PATHS=("$HOME/repo:1" "$HOME/repo/astro:2") +TS_MAX_DEPTH=2 + +find_dirs() { + # list TMUX sessions + if [[ -n "${TMUX}" ]]; then + current_session=$(tmux display-message -p '#S') + tmux list-sessions -F "[TMUX] #{session_name}" 2>/dev/null | grep -vFx "[TMUX] $current_session" + else + tmux list-sessions -F "[TMUX] #{session_name}" 2>/dev/null + fi + + # if the path ends with :number, it will search for directories with a max depth of number ;) + # if there is no number, it will search for directories with a max depth defined by TS_MAX_DEPTH or 1 if not set + for entry in "${TS_SEARCH_PATHS[@]}"; do + # Check if entry as :number as suffix then adapt the maxdepth parameter + if [[ "$entry" =~ ^([^:]+):([0-9]+)$ ]]; then + path="${BASH_REMATCH[1]}" + depth="${BASH_REMATCH[2]}" + else + path="$entry" + fi + + depth="${depth:-${TS_MAX_DEPTH:-1}}" + + [[ -d "$path" ]] && find "$path" -mindepth 1 -maxdepth "$depth" \( -path '*/.git' -o -path '*/node_modules' \) -prune -o -type d -print | sed "s|^$HOME/||" + done +} + +has_session() { + tmux list-sessions | grep -q "^$1:" +} + +switch_to() { + if [[ -z $TMUX ]]; then + log "attaching to session $1" + tmux attach-session -t "$1" + else + log "switching to session $1" + tmux switch-client -t "$1" + fi +} + +selected=$(find_dirs | fzf) + +if [[ "$selected" =~ ^\[TMUX\]\ (.+)$ ]]; then + selected="${BASH_REMATCH[1]}" +fi + +selected_name=$(basename "$selected") + +if ! has_session "$selected_name"; then + cd "$HOME/$selected" + tmux new-session -ds "$selected_name" -c "$HOME/$selected" + + tmux rename-window -t "$selected_name":1 "Code" + tmux send-keys -t "$selected_name":1 "nvim" C-m + tmux new-window -t "$selected_name":2 -n "Server" + tmux new-window -t "$selected_name":3 -n "Claude" + tmux new-window -t "$selected_name":4 -n "Whatever" +fi + +switch_to "$selected_name" + +