From 413e60fbfa38582accb67a40dedb6ba9d31fa9eb Mon Sep 17 00:00:00 2001 From: Daniele Pintore Date: Thu, 10 Jul 2025 23:36:48 +0200 Subject: [PATCH] fish: moved tmux-sessionizer inside fish functions --- .config/fish/conf.d/01_env.fish | 1 - .config/fish/conf.d/04_keybinds.fish | 4 +-- .config/fish/functions/tmux-sessionizer.fish | 34 ++++++++++++++++++++ .local/scripts/tmux-sessionizer | 25 -------------- .local/scripts/tmux-windowizer | 13 -------- 5 files changed, 36 insertions(+), 41 deletions(-) create mode 100644 .config/fish/functions/tmux-sessionizer.fish delete mode 100755 .local/scripts/tmux-sessionizer delete mode 100755 .local/scripts/tmux-windowizer diff --git a/.config/fish/conf.d/01_env.fish b/.config/fish/conf.d/01_env.fish index ac2f0ab..b574b36 100644 --- a/.config/fish/conf.d/01_env.fish +++ b/.config/fish/conf.d/01_env.fish @@ -1,6 +1,5 @@ #!/usr/bin/env fish fish_add_path --path ~/go/bin -fish_add_path --path ~/.local/scripts set EDITOR nvim diff --git a/.config/fish/conf.d/04_keybinds.fish b/.config/fish/conf.d/04_keybinds.fish index a00ed49..7ccda3f 100644 --- a/.config/fish/conf.d/04_keybinds.fish +++ b/.config/fish/conf.d/04_keybinds.fish @@ -6,7 +6,7 @@ bind j 'if commandline --paging-mode; commandline --function down-line; else; co bind k 'if commandline --paging-mode; commandline --function up-line; else; commandline --insert k; end' # tmux-sessionizer (Ctrl+n) -bind ctrl-n 'tmux-sessionizer' +bind ctrl-n tmux-sessionizer -bind : 'accept-autosuggestion' +bind : accept-autosuggestion diff --git a/.config/fish/functions/tmux-sessionizer.fish b/.config/fish/functions/tmux-sessionizer.fish new file mode 100644 index 0000000..c438dd7 --- /dev/null +++ b/.config/fish/functions/tmux-sessionizer.fish @@ -0,0 +1,34 @@ +#!/usr/bin/env fish +function tmux-sessionizer + # Check if an argument is passed + if test (count $argv) -eq 1 + set selected $argv[1] + else + # Use fzf to select a directory + set selected (find ~/Documents ~/Documents/projects ~/ -mindepth 1 -maxdepth 1 -type d | fzf) + end + + # Exit if no directory is selected + if test -z "$selected" + exit 0 + end + + # Get the basename of the selected directory and replace dots with underscores + #set selected_name (basename "$selected" | tr . _) + set selected_name angelo + if set -q TMUX # we are inside tmux + if not tmux has-session -t=$selected_name 2>/dev/null + tmux new-session -ds $selected_name -c $selected + end + tmux switch-client -t$selected_name + else + # outside tmux + if not tmux has-session -t=$selected_name 2&>/dev/null + tmux new-session -ds $selected_name -c $selected + end + tmux attach-session -t$selected_name + end + # Force repaint the prompt/commandline to fix redraw issues after tmux/fzf + # # fish specific problem + commandline -f repaint +end diff --git a/.local/scripts/tmux-sessionizer b/.local/scripts/tmux-sessionizer deleted file mode 100755 index 355182d..0000000 --- a/.local/scripts/tmux-sessionizer +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -if [[ $# -eq 1 ]]; then - selected=$1 -else - selected=$(find ~/Documents ~/Documents/projects ~/ -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/.local/scripts/tmux-windowizer b/.local/scripts/tmux-windowizer deleted file mode 100755 index 5a147d5..0000000 --- a/.local/scripts/tmux-windowizer +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -branch_name=$(basename $1) -session_name=$(tmux display-message -p "#S") -clean_name=$(echo $branch_name | tr "./" "__") -target="$session_name:$clean_name" - -if ! tmux has-session -t $target 2> /dev/null; then - tmux neww -dn $clean_name -fi - -shift -tmux send-keys -t $target "$*"