yay.nix/share/fish/completions/yay.fish

156 lines
6.1 KiB
Fish

# Fallback functions for older fish versions
function __fish_seen_subcommand_from_fallback
set -l cmd (commandline -poc)
set -e cmd[1] # Remove the main command
contains -- $argv[1] $cmd
and return 0
return 1
end
function __fish_seen_option_fallback
set -l cmd (commandline -poc)
for opt in $argv
if contains -- $opt $cmd
return 0
end
end
return 1
end
function __fish_is_token_n_fallback
set -l cmd (commandline -poc)
test (count $cmd) -eq $argv[1]
and return 0
return 1
end
# Use built-in functions if they exist, otherwise use our fallbacks
function __yay_seen_subcommand_from
if type -q __fish_seen_subcommand_from
__fish_seen_subcommand_from $argv
else
__fish_seen_subcommand_from_fallback $argv
end
end
function __yay_seen_option
if type -q __fish_seen_option
__fish_seen_option $argv
else
__fish_seen_option_fallback $argv
end
end
function __yay_is_token_n
if type -q __fish_is_token_n
__fish_is_token_n $argv
else
__fish_is_token_n_fallback $argv
end
end
# Complete the main command
complete -c yay -f
# Complete the top-level subcommands
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a rebuild -d "Rebuild the NixOS configuration"
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a update -d "Update flake inputs"
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a garbage -d "Clean up the Nix store"
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a try -d "Create a shell with the specified package(s)"
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a tar -d "Create compressed tar archives"
complete -c yay -n "not __yay_seen_subcommand_from rebuild update garbage try tar untar" -a untar -d "Extract tar archives"
# Options for 'rebuild'
complete -c yay -n "__yay_seen_subcommand_from rebuild" -s p -l path -r -d "Path to the Nix configuration"
complete -c yay -n "__yay_seen_subcommand_from rebuild" -s H -l host -r -d "Hostname to build for"
complete -c yay -n "__yay_seen_subcommand_from rebuild" -s t -l trace -d "Enable trace output"
complete -c yay -n "__yay_seen_subcommand_from rebuild" -s h -l help -d "Show help message"
# Options for 'update'
complete -c yay -n "__yay_seen_subcommand_from update" -s p -l path -r -d "Path to the Nix configuration"
complete -c yay -n "__yay_seen_subcommand_from update" -s h -l help -d "Show help message"
# Options for 'garbage'
complete -c yay -n "__yay_seen_subcommand_from garbage" -s h -l help -d "Show help message"
# Options for 'try'
complete -c yay -n "__yay_seen_subcommand_from try" -s h -l help -d "Show help message"
# Package suggestions for 'try'
function __yay_list_packages
# Use persistent cache file in /tmp (lasts until reboot)
set -l cache_file /tmp/yay_packages_cache
# Load from cache if it exists
if test -f "$cache_file"
cat "$cache_file"
return 0
end
# Otherwise, fetch packages and store in cache
echo -n "Loading packages..." >&2
# Run nix-env but redirect warnings to /dev/null
set -l packages (nix-env -qa --json 2>/dev/null | jq -r 'keys[]' 2>/dev/null)
# Process packages to remove namespace prefix (like "nixos.", "nixpkgs.", etc.)
set -l cleaned_packages
for pkg in $packages
set -l cleaned_pkg (string replace -r '^[^.]+\.' ''\'''\' $pkg)
set -a cleaned_packages $cleaned_pkg
end
# Save to cache file for future shell sessions
printf "%s\n" $cleaned_packages >"$cache_file"
echo " done!" >&2
# Output the packages
printf "%s\n" $cleaned_packages
end
# Options for 'tar'
complete -c yay -n "__yay_seen_subcommand_from tar" -s o -l output -r -d "Output file path"
complete -c yay -n "__yay_seen_subcommand_from tar" -s c -l compression -r -a "zstd gzip bzip2 bzip3 7zip tar" -d "Compression type"
complete -c yay -n "__yay_seen_subcommand_from tar" -s l -l level -r -d "Compression level"
complete -c yay -n "__yay_seen_subcommand_from tar" -s t -l threads -r -d "Thread count"
complete -c yay -n "__yay_seen_subcommand_from tar" -s v -l verbose -d "Enable verbose output"
complete -c yay -n "__yay_seen_subcommand_from tar" -s h -l help -d "Show help message"
# File path completion for tar input (simplified)
function __yay_tar_needs_input
__yay_seen_subcommand_from tar
and count (commandline -poc) = 2
and not __yay_seen_option -o --output -c --compression -l --level -t --threads -v --verbose -h --help
end
complete -c yay -n __yay_tar_needs_input -r -d "Input path"
# File path completion for tar output (simplified)
function __yay_tar_needs_output
__yay_seen_subcommand_from tar
and count (commandline -poc) = 3
and not __yay_seen_option -o --output
end
complete -c yay -n __yay_tar_needs_output -r -d "Output file"
# Options for 'untar'
complete -c yay -n "__yay_seen_subcommand_from untar" -s o -l output -r -d "Output directory"
complete -c yay -n "__yay_seen_subcommand_from untar" -s v -l verbose -d "Enable verbose output"
complete -c yay -n "__yay_seen_subcommand_from untar" -s h -l help -d "Show help message"
# File path completion for untar with archive extensions (simplified)
function __yay_untar_needs_input
__yay_seen_subcommand_from untar
and count (commandline -poc) = 2
and not __yay_seen_option -o --output -v --verbose -h --help
end
complete -c yay -n __yay_untar_needs_input -r -a "*.tar *.tar.gz *.tgz *.tar.zst *.tzst *.tar.bz2 *.tbz *.tbz2 *.tb2 *.tz2 *.tar.bz3 *.7z *.tar.7z *.rar" -d "Archive file"
# Directory completion for untar output directory (simplified)
function __yay_untar_needs_output
__yay_seen_subcommand_from untar
and count (commandline -poc) = 3
and not __yay_seen_option -o --output
end
complete -c yay -n __yay_untar_needs_output -r -a "(__fish_complete_directories)" -d "Output directory"
# Package completion for try
complete -c yay -n "__yay_seen_subcommand_from try; and not string match -r -- '^-' (commandline -ct)" -a "(__yay_list_packages)" -d "Nix package"