feat(tmux): add fish completions

This commit is contained in:
Moritz Böhme 2023-07-04 11:44:55 +02:00
parent 3e8ff2e064
commit b8be6a3a4e
No known key found for this signature in database
GPG key ID: 970C6E89EB0547A9
6 changed files with 77 additions and 22 deletions

View file

@ -41,32 +41,18 @@ let
'';
};
tmux-sessionizer = pkgs.writeShellApplication {
tmux-sessionizer = pkgs.writeFishApplication {
name = "ts";
runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd fzf ];
text = ''
#!/usr/bin/env bash
selected=$(fd -HIg '.git' ~/ --min-depth 1 --max-depth 5 --type d --prune --exec dirname {} | ${getExe fzf1} "$*")
selected_name=$(basename "$selected" | tr . _)
if ! tmux has-session -t="$selected_name" 2> /dev/null; then
tmux new-session -ds "$selected_name" -c "$selected"
fi
${getExe tmux-switch} "$selected_name"
'';
runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd fzf1 tmux-switch ];
text = readFile ./tmux-sessionizer/script.fish;
completions = readFile ./tmux-sessionizer/completions.fish;
};
tmux-attach = pkgs.writeShellApplication {
tmux-attach = pkgs.writeFishApplication {
name = "ta";
runtimeInputs = with pkgs; [ tmux ];
text = ''
#!/usr/bin/env bash
selected=$(tmux list-sessions -F '#{session_name}' | ${getExe fzf1} "$*")
${getExe tmux-switch} "$selected"
'';
runtimeInputs = with pkgs; [ tmux fzf1 tmux-switch ];
text = readFile ./tmux-attach/script.fish;
completions = readFile ./tmux-attach/completions.fish;
};
in

View file

@ -0,0 +1 @@
complete -c ta -f -a '(tmux list-sessions -F "#{session_name}" 2>/dev/null)'

View file

@ -0,0 +1,5 @@
set selected (tmux list-sessions -F '#{session_name}' 2>/dev/null | fzf1 $argv)
if not test -n "$selected"
exit 1
end
tmux-switch "$selected"

View file

@ -0,0 +1 @@
complete -c ts -f -a '(fd -HIg '.git' ~/ --min-depth 1 --max-depth 5 --type d --prune --exec realpath "{}/.." | xargs -I{} basename {} | string replace "." "")'

View file

@ -0,0 +1,13 @@
set selected (fd -HIg '.git' ~/ --min-depth 1 --max-depth 5 --type d --prune --exec dirname {} | fzf1 $argv)
set selected_name (basename $selected 2>/dev/null | string replace "." "_")
if not test -n "$selected_name"
exit 1
end
if ! tmux has-session -t $selected_name 2> /dev/null
tmux new-session -ds $selected_name -c $selected
end
tmux-switch $selected_name