feat(tmux): add fish completions
This commit is contained in:
parent
3e8ff2e064
commit
b8be6a3a4e
6 changed files with 77 additions and 22 deletions
|
@ -41,32 +41,18 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
tmux-sessionizer = pkgs.writeShellApplication {
|
tmux-sessionizer = pkgs.writeFishApplication {
|
||||||
name = "ts";
|
name = "ts";
|
||||||
runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd fzf ];
|
runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd fzf1 tmux-switch ];
|
||||||
text = ''
|
text = readFile ./tmux-sessionizer/script.fish;
|
||||||
#!/usr/bin/env bash
|
completions = readFile ./tmux-sessionizer/completions.fish;
|
||||||
|
|
||||||
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"
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
tmux-attach = pkgs.writeShellApplication {
|
tmux-attach = pkgs.writeFishApplication {
|
||||||
name = "ta";
|
name = "ta";
|
||||||
runtimeInputs = with pkgs; [ tmux ];
|
runtimeInputs = with pkgs; [ tmux fzf1 tmux-switch ];
|
||||||
text = ''
|
text = readFile ./tmux-attach/script.fish;
|
||||||
#!/usr/bin/env bash
|
completions = readFile ./tmux-attach/completions.fish;
|
||||||
selected=$(tmux list-sessions -F '#{session_name}' | ${getExe fzf1} "$*")
|
|
||||||
${getExe tmux-switch} "$selected"
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
in
|
in
|
1
modules/programs/tmux/tmux-attach/completions.fish
Normal file
1
modules/programs/tmux/tmux-attach/completions.fish
Normal file
|
@ -0,0 +1 @@
|
||||||
|
complete -c ta -f -a '(tmux list-sessions -F "#{session_name}" 2>/dev/null)'
|
5
modules/programs/tmux/tmux-attach/script.fish
Normal file
5
modules/programs/tmux/tmux-attach/script.fish
Normal 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"
|
1
modules/programs/tmux/tmux-sessionizer/completions.fish
Normal file
1
modules/programs/tmux/tmux-sessionizer/completions.fish
Normal 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 "." "")'
|
13
modules/programs/tmux/tmux-sessionizer/script.fish
Normal file
13
modules/programs/tmux/tmux-sessionizer/script.fish
Normal 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
|
49
overlays/builders.nix
Normal file
49
overlays/builders.nix
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
_:
|
||||||
|
|
||||||
|
final: _:
|
||||||
|
with final.lib;
|
||||||
|
{
|
||||||
|
writeFishApplication =
|
||||||
|
{ name
|
||||||
|
, text
|
||||||
|
, completions ? null
|
||||||
|
, runtimeInputs ? [ ]
|
||||||
|
, checkPhase ? null
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
fishFile = destination: content: final.writeTextFile {
|
||||||
|
inherit name destination;
|
||||||
|
executable = true;
|
||||||
|
allowSubstitutes = true;
|
||||||
|
preferLocalBuild = false;
|
||||||
|
text = ''
|
||||||
|
#!${getExe final.fish}
|
||||||
|
'' + optionalString (runtimeInputs != [ ]) ''
|
||||||
|
|
||||||
|
export PATH="${makeBinPath runtimeInputs}:$PATH"
|
||||||
|
'' + ''
|
||||||
|
|
||||||
|
${content}
|
||||||
|
'';
|
||||||
|
|
||||||
|
checkPhase =
|
||||||
|
if checkPhase == null then ''
|
||||||
|
runHook preCheck
|
||||||
|
${getExe final.fish} -n "$target"
|
||||||
|
runHook postCheck
|
||||||
|
''
|
||||||
|
else checkPhase;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
script = fishFile "/bin/${name}" text;
|
||||||
|
|
||||||
|
completions_file = fishFile "/share/fish/vendor_completions.d/${name}.fish" completions;
|
||||||
|
in
|
||||||
|
final.symlinkJoin {
|
||||||
|
inherit name;
|
||||||
|
paths = [
|
||||||
|
script
|
||||||
|
] ++ optional (completions != null) completions_file;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue