feat(fish): Add env autocompletions

This commit is contained in:
2025-09-22 14:25:40 +02:00
parent 74f3b90c7d
commit be228a669a
2 changed files with 97 additions and 1 deletions

3
.gitignore vendored
View File

@@ -13,11 +13,12 @@
!fish/config.fish
!fish/functions
!fish/functions/env.fish
!fish/completions
!fish/completions/env.fish
!fish/environments
!fish/environments/templates
!fish/environments/templates/*
!ranger
!ranger/rc.conf
!ranger/rifle.conf

95
fish/completions/env.fish Normal file
View File

@@ -0,0 +1,95 @@
# Fish completions for env command
# Complete subcommands with descriptions
complete -c env -n "__fish_use_subcommand" -xa "create" -d "Create a new environment"
complete -c env -n "__fish_use_subcommand" -xa "new" -d "Create a new environment"
complete -c env -n "__fish_use_subcommand" -xa "list" -d "List all environments"
complete -c env -n "__fish_use_subcommand" -xa "ls" -d "List all environments"
complete -c env -n "__fish_use_subcommand" -xa "activate" -d "Activate an environment"
complete -c env -n "__fish_use_subcommand" -xa "use" -d "Activate an environment"
complete -c env -n "__fish_use_subcommand" -xa "deactivate" -d "Deactivate current environment"
complete -c env -n "__fish_use_subcommand" -xa "exit" -d "Deactivate current environment"
complete -c env -n "__fish_use_subcommand" -xa "remove" -d "Remove an environment"
complete -c env -n "__fish_use_subcommand" -xa "rm" -d "Remove an environment"
complete -c env -n "__fish_use_subcommand" -xa "delete" -d "Remove an environment"
complete -c env -n "__fish_use_subcommand" -xa "link" -d "Link environment to directory"
complete -c env -n "__fish_use_subcommand" -xa "ln" -d "Link environment to directory"
complete -c env -n "__fish_use_subcommand" -xa "info" -d "Show environment information"
complete -c env -n "__fish_use_subcommand" -xa "show" -d "Show environment information"
complete -c env -n "__fish_use_subcommand" -xa "edit" -d "Edit environment configuration"
complete -c env -n "__fish_use_subcommand" -xa "copy" -d "Copy an environment"
complete -c env -n "__fish_use_subcommand" -xa "clone" -d "Copy an environment"
complete -c env -n "__fish_use_subcommand" -xa "export" -d "Export environment to directory"
complete -c env -n "__fish_use_subcommand" -xa "help" -d "Show help"
# Complete environment names with template info
function __env_complete_environments
set -l env_dir "$HOME/.config/fish/environments/configs"
if test -d "$env_dir"
for env_path in "$env_dir"/*
if test -d "$env_path"
set env_name (basename "$env_path")
set config_file "$env_path/config.toml"
if test -f "$config_file"
set template (grep "template =" "$config_file" | cut -d'"' -f2 2>/dev/null)
if test -n "$template"
echo -e "$env_name\t($template template)"
else
echo "$env_name"
end
else
echo "$env_name"
end
end
end
end
end
# Complete template names with descriptions
function __env_complete_templates
set -l template_dir "$HOME/.config/fish/environments/templates"
if test -d "$template_dir"
for template_file in "$template_dir"/*.fish
if test -f "$template_file"
set template_name (basename "$template_file" .fish)
# Extract description from first comment line
set description (head -n 5 "$template_file" | grep -E "^#[^!]" | head -n 1 | sed 's/^# *//')
if test -n "$description"
echo -e "$template_name\t$description"
else
echo "$template_name"
end
end
end
end
end
# Completions for create/new - second argument should be template
complete -c env -n "__fish_seen_subcommand_from create new" -n "test (count (commandline -opc)) -eq 3" -xa "(__env_complete_templates)"
# Completions for activate/use - complete with environment names
complete -c env -n "__fish_seen_subcommand_from activate use" -xa "(__env_complete_environments)"
# Completions for remove/rm/delete - complete with environment names
complete -c env -n "__fish_seen_subcommand_from remove rm delete" -xa "(__env_complete_environments)"
# Completions for link/ln - complete with environment names, then directories
complete -c env -n "__fish_seen_subcommand_from link ln" -n "test (count (commandline -opc)) -eq 3" -xa "(__env_complete_environments)"
complete -c env -n "__fish_seen_subcommand_from link ln" -n "test (count (commandline -opc)) -ge 4" -xa "(__fish_complete_directories)"
# Completions for info/show - complete with environment names
complete -c env -n "__fish_seen_subcommand_from info show" -xa "(__env_complete_environments)"
# Completions for edit - complete with environment names
complete -c env -n "__fish_seen_subcommand_from edit" -xa "(__env_complete_environments)"
# Completions for copy/clone - complete with environment names for both source and destination
complete -c env -n "__fish_seen_subcommand_from copy clone" -n "test (count (commandline -opc)) -eq 3" -xa "(__env_complete_environments)"
# Completions for export - complete with environment names, then directories
complete -c env -n "__fish_seen_subcommand_from export" -n "test (count (commandline -opc)) -eq 3" -xa "(__env_complete_environments)"
complete -c env -n "__fish_seen_subcommand_from export" -n "test (count (commandline -opc)) -ge 4" -xa "(__fish_complete_directories)"
# Help options
complete -c env -n "__fish_use_subcommand" -s h -l help -d "Show help"
complete -c env -n "__fish_seen_subcommand_from help" -xa "create list activate deactivate remove link info edit copy export"