mirror of
https://github.com/danielepintore/dotfiles.git
synced 2026-06-15 20:25:13 +02:00
fish: moved tmux-sessionizer inside fish functions
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env fish
|
||||
fish_add_path --path ~/go/bin
|
||||
fish_add_path --path ~/.local/scripts
|
||||
|
||||
set EDITOR nvim
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
34
.config/fish/functions/tmux-sessionizer.fish
Normal file
34
.config/fish/functions/tmux-sessionizer.fish
Normal 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
|
||||
@@ -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
|
||||
@@ -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 "$*"
|
||||
Reference in New Issue
Block a user