From 3bf6ab23da37891cfa669147c1a16c9c83b98b4c Mon Sep 17 00:00:00 2001 From: hydrauluu Date: Sun, 3 May 2026 23:45:58 +0600 Subject: [PATCH] feat: add fish shell completion support (#263) --- README.md | 33 +++++++++++- completions/my-unicorn.fish | 102 ++++++++++++++++++++++++++++++++++++ install.sh | 31 +++++++++-- 3 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 completions/my-unicorn.fish diff --git a/README.md b/README.md index 83cf6520..2dc65470 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ curl -LsSf https://astral.sh/uv/install.sh | sh #### Method 1: Using install.sh (recommended)** > > [!NOTE] -> This method also setup autocomplete for bash/zsh shells automatically. +> This method also setup autocomplete for bash/zsh/fish shells automatically. ```bash cd ~/Downloads @@ -170,6 +170,37 @@ Changes to the source code will be reflected immediately without reinstalling. my-unicorn --help # to see the command options ``` +## Shell Completions + +### Bash / Zsh + +> [!NOTE] +> Completions are automatically configured when using `install.sh`. + +To manually enable: + +```bash +# Bash +sudo cp autocomplete/bash_autocomplete /etc/bash_completion.d/my-unicorn + +# Zsh +sudo cp autocomplete/zsh_autocomplete /usr/local/share/zsh/site-functions/_my-unicorn +``` + +### Fish shell + +> [!NOTE] +> Completions are automatically configured when using `install.sh`. + +To manually enable: + +```fish +mkdir -p ~/.config/fish/completions +cp completions/my-unicorn.fish ~/.config/fish/completions/ +``` + +Restart your shell or run `source ~/.config/fish/completions/my-unicorn.fish` to enable. + ## For using uncompatible apps (installing with URL) > [!IMPORTANT] diff --git a/completions/my-unicorn.fish b/completions/my-unicorn.fish new file mode 100644 index 00000000..0e775fa6 --- /dev/null +++ b/completions/my-unicorn.fish @@ -0,0 +1,102 @@ +# my-unicorn fish completion script +# ------------------------------------------------ +# Install: cp completions/my-unicorn.fish ~/.config/fish/completions/ +# ------------------------------------------------ + +complete -c my-unicorn -f + +# -- Global options ----------------------------------------------------------- + +complete -c my-unicorn -l version -d 'Show my-unicorn version and exit' +complete -c my-unicorn -s h -l help -d 'Show help message and exit' + +# -- Subcommands -------------------------------------------------------------- + +complete -c my-unicorn -n __fish_use_subcommand -a install -d 'Install AppImages from catalog or URLs' +complete -c my-unicorn -n __fish_use_subcommand -a update -d 'Update installed AppImages' +complete -c my-unicorn -n __fish_use_subcommand -a upgrade -d 'Upgrade my-unicorn CLI' +complete -c my-unicorn -n __fish_use_subcommand -a catalog -d 'Browse AppImage catalog' +complete -c my-unicorn -n __fish_use_subcommand -a migrate -d 'Migrate configs to latest version' +complete -c my-unicorn -n __fish_use_subcommand -a remove -d 'Remove installed AppImages' +complete -c my-unicorn -n __fish_use_subcommand -a backup -d 'Manage AppImage backups and restore' +complete -c my-unicorn -n __fish_use_subcommand -a cache -d 'Manage release data cache' +complete -c my-unicorn -n __fish_use_subcommand -a token -d 'Manage GitHub authentication token' +complete -c my-unicorn -n __fish_use_subcommand -a auth -d 'Show GitHub authentication status' +complete -c my-unicorn -n __fish_use_subcommand -a config -d 'Manage configuration' + +# -- install ------------------------------------------------------------------ + +complete -c my-unicorn -n '__fish_seen_subcommand_from install' -l concurrency -d 'Maximum number of parallel installs' -r +complete -c my-unicorn -n '__fish_seen_subcommand_from install' -l no-icon -d 'Skip downloading application icons' +complete -c my-unicorn -n '__fish_seen_subcommand_from install' -l no-verify -d 'Skip AppImage verification' +complete -c my-unicorn -n '__fish_seen_subcommand_from install' -l no-desktop -d 'Skip desktop entry creation' +complete -c my-unicorn -n '__fish_seen_subcommand_from install' -l verbose -d 'Show detailed logging during installation' +complete -c my-unicorn -n '__fish_seen_subcommand_from install' -s h -l help -d 'Show help message and exit' + +# -- update ------------------------------------------------------------------- + +complete -c my-unicorn -n '__fish_seen_subcommand_from update' -l check-only -d 'Only check for updates without installing' +complete -c my-unicorn -n '__fish_seen_subcommand_from update' -l refresh-cache -d 'Bypass cache and fetch fresh data from GitHub API' +complete -c my-unicorn -n '__fish_seen_subcommand_from update' -l verbose -d 'Show detailed logging during update' +complete -c my-unicorn -n '__fish_seen_subcommand_from update' -s h -l help -d 'Show help message and exit' + +# -- upgrade ------------------------------------------------------------------ + +complete -c my-unicorn -n '__fish_seen_subcommand_from upgrade' -l check -d 'Check for available updates without performing the upgrade' +complete -c my-unicorn -n '__fish_seen_subcommand_from upgrade' -s h -l help -d 'Show help message and exit' + +# -- catalog ------------------------------------------------------------------ + +complete -c my-unicorn -n '__fish_seen_subcommand_from catalog' -l installed -d 'Show installed AppImages (default)' +complete -c my-unicorn -n '__fish_seen_subcommand_from catalog' -l available -d 'Show available applications from catalog with descriptions' +complete -c my-unicorn -n '__fish_seen_subcommand_from catalog' -l info -d 'Show detailed information about a specific app' -r +complete -c my-unicorn -n '__fish_seen_subcommand_from catalog' -s h -l help -d 'Show help message and exit' + +# -- migrate ------------------------------------------------------------------ + +complete -c my-unicorn -n '__fish_seen_subcommand_from migrate' -l dry-run -d 'Show what would be migrated without making changes' +complete -c my-unicorn -n '__fish_seen_subcommand_from migrate' -l force -d 'Force migration even if versions match' +complete -c my-unicorn -n '__fish_seen_subcommand_from migrate' -s h -l help -d 'Show help message and exit' + +# -- remove ------------------------------------------------------------------- + +complete -c my-unicorn -n '__fish_seen_subcommand_from remove' -l keep-config -d 'Keep configuration files' +complete -c my-unicorn -n '__fish_seen_subcommand_from remove' -s h -l help -d 'Show help message and exit' + +# -- backup ------------------------------------------------------------------- + +complete -c my-unicorn -n '__fish_seen_subcommand_from backup' -l restore-last -d 'Restore the latest backup version' +complete -c my-unicorn -n '__fish_seen_subcommand_from backup' -l restore-version -d 'Restore a specific version' -r +complete -c my-unicorn -n '__fish_seen_subcommand_from backup' -l list-backups -d 'List available backups for the specified app' +complete -c my-unicorn -n '__fish_seen_subcommand_from backup' -l cleanup -d 'Clean up old backups according to max_backup setting' +complete -c my-unicorn -n '__fish_seen_subcommand_from backup' -l info -d 'Show detailed backup information' +complete -c my-unicorn -n '__fish_seen_subcommand_from backup' -s h -l help -d 'Show help message and exit' + +# -- cache -------------------------------------------------------------------- + +complete -c my-unicorn -n '__fish_seen_subcommand_from cache' -a clear -d 'Clear cache entries' +complete -c my-unicorn -n '__fish_seen_subcommand_from cache' -a stats -d 'Show cache statistics and storage info' +complete -c my-unicorn -n '__fish_seen_subcommand_from cache' -s h -l help -d 'Show help message and exit' + +# -- cache clear subcommand --------------------------------------------------- + +complete -c my-unicorn -n '__fish_seen_subcommand_from cache; and contains -- (commandline -opc); and not contains clear -- (commandline -opc); and not contains stats -- (commandline -opc)' -a clear -d 'Clear cache entries' +complete -c my-unicorn -n '__fish_seen_subcommand_from cache; and string match -q clear -- (commandline -opc)[2]' -l all -d 'Clear all cache entries' +complete -c my-unicorn -n '__fish_seen_subcommand_from cache; and string match -q clear -- (commandline -opc)[2]' -s h -l help -d 'Show help message and exit' + +# -- token -------------------------------------------------------------------- + +complete -c my-unicorn -n '__fish_seen_subcommand_from token' -l save -d 'Save GitHub authentication token' +complete -c my-unicorn -n '__fish_seen_subcommand_from token' -l remove -d 'Remove GitHub authentication token' +complete -c my-unicorn -n '__fish_seen_subcommand_from token' -s h -l help -d 'Show help message and exit' + +# -- auth --------------------------------------------------------------------- + +complete -c my-unicorn -n '__fish_seen_subcommand_from auth' -l status -d 'Show authentication status (default action)' +complete -c my-unicorn -n '__fish_seen_subcommand_from auth' -s h -l help -d 'Show help message and exit' + +# -- config ------------------------------------------------------------------- + +complete -c my-unicorn -n '__fish_seen_subcommand_from config' -l show -d 'Show current configuration' +complete -c my-unicorn -n '__fish_seen_subcommand_from config' -l reset -d 'Reset configuration to defaults' +complete -c my-unicorn -n '__fish_seen_subcommand_from config' -s h -l help -d 'Show help message and exit' diff --git a/install.sh b/install.sh index 916a8e26..cd2bd876 100755 --- a/install.sh +++ b/install.sh @@ -6,7 +6,7 @@ # - Copies project files into XDG user data directory # - Creates/updates Python virtual environment # - Installs wrapper script and ensures PATH configuration -# - Sets up shell autocomplete (bash/zsh) +# - Sets up shell autocomplete (bash/zsh/fish) # # Usage: # ./install.sh -i|--install # Install or reinstall (includes autocomplete) @@ -102,6 +102,7 @@ install_with_uv_tool() { uv tool install git+https://github.com/Cyber-Syntax/my-unicorn --force check_local_bin_in_path setup_autocomplete_from_src "$src_dir" + setup_fish_completions copy_update_script echo "✅ Installation complete using uv tool." @@ -118,6 +119,7 @@ install_with_uv_editable() { uv tool install --editable . --force check_local_bin_in_path setup_autocomplete_from_src "$src_dir" + setup_fish_completions copy_update_script echo "✅ Editable installation complete using uv tool." @@ -125,6 +127,26 @@ install_with_uv_editable() { echo "Run 'my-unicorn --help' to get started." } +# Set up fish shell completions +setup_fish_completions() { + local fish_dir="$HOME/.config/fish/completions" + local fish_src="$INSTALL_DIR/completions/my-unicorn.fish" + + # Fallback to source directory if installed version not available + if [[ ! -f "$fish_src" ]]; then + fish_src="$(script_dir)/completions/my-unicorn.fish" + fi + + if [[ -f "$fish_src" ]]; then + if command -v fish &>/dev/null; then + echo "Setting up fish completions..." + mkdir -p "$fish_dir" + cp "$fish_src" "$fish_dir/" + echo "Fish completions installed to $fish_dir/my-unicorn.fish" + fi + fi +} + # Set up shell autocomplete by delegating to autocomplete.bash setup_autocomplete() { local helper="$INSTALL_DIR/scripts/autocomplete.bash" @@ -178,8 +200,8 @@ install_autocomplete() { src_dir="$(script_dir)" mkdir -p "$INSTALL_DIR" - # Copy autocomplete folder and scripts - for item in autocomplete scripts; do + # Copy autocomplete folder, completions folder, and scripts + for item in autocomplete completions scripts; do local src_path="$src_dir/$item" local dst_path="$INSTALL_DIR/$item" if [ -e "$src_path" ]; then @@ -193,7 +215,8 @@ install_autocomplete() { done if setup_autocomplete; then - echo "✅ Autocomplete installation complete!" + setup_fish_completions + echo "Autocomplete installation complete!" echo "" echo "Please restart your shell or source your shell's rc file to enable autocompletion." echo "Test completion by typing: my-unicorn "