fish: moved tmux-sessionizer inside fish functions

This commit is contained in:
2025-07-10 23:36:48 +02:00
parent f2a1fc853f
commit 413e60fbfa
5 changed files with 36 additions and 41 deletions

View File

@@ -1,6 +1,5 @@
#!/usr/bin/env fish
fish_add_path --path ~/go/bin
fish_add_path --path ~/.local/scripts
set EDITOR nvim

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 "$*"