From 620aae77dfbbf2e88f8e691c1378f922ba53e11e Mon Sep 17 00:00:00 2001 From: gasinvein Date: Tue, 31 Mar 2020 18:16:52 +0300 Subject: [PATCH] Add fish shell completion --- Makefile.am | 4 ++++ completion/flatpak.fish | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 completion/flatpak.fish diff --git a/Makefile.am b/Makefile.am index 7adc3103..48dfacef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -144,6 +144,10 @@ zshcompletiondir = $(datadir)/zsh/site-functions zshcompletion_DATA = completion/_flatpak EXTRA_DIST += $(zshcompletion_DATA) +fishcompletiondir = $(datadir)/fish/vendor_completions.d +fishcompletion_DATA = completion/flatpak.fish +EXTRA_DIST += $(fishcompletion_DATA) + profiledir = $(PROFILE_DIR) profile_DATA = profile/flatpak.sh EXTRA_DIST += $(profile_DATA) diff --git a/completion/flatpak.fish b/completion/flatpak.fish new file mode 100644 index 00000000..dada5c64 --- /dev/null +++ b/completion/flatpak.fish @@ -0,0 +1,47 @@ +function __fish_complete_flatpak + set current_cmd (commandline -p) + set current_position (commandline -C) + set current_token (commandline -ct) + echo "CMD \"$current_cmd\" POS \"$current_position\" TOK \"$current_token\"" >> /tmp/fish-flatpak-debug.txt + command flatpak complete "$current_cmd" "$current_position" "$current_token" | while read fp_sugg + echo "SUG \"$fp_sugg\"" >> /tmp/fish-flatpak-debug.txt + set sugg (string trim -- "$fp_sugg") + switch "$sugg" + case __FLATPAK_FILE + __fish_complete_path "$current_token" + case __FLATPAK_BUNDLE_FILE + __fish_complete_suffix "$current_token" '.flatpak' + case __FLATPAK_BUNDLE_OR_REF_FILE + __fish_complete_suffix "$current_token" '.flatpak' + __fish_complete_suffix "$current_token" '.flatpakref' + case __FLATPAK_DIR + __fish_complete_directories "$current_token" + case '*' + # completing a value for option + if string match -- "--*=" "$current_token" + echo "$current_token$sugg" + else + echo "$sugg" + end + end + end + return +end + +function __fish_flatpak_complete_files + if __fish_seen_subcommand_from run build + set pos_args 0 + for t in (commandline -co) + if string match --invert -- "-*" "$t" + set pos_args (math "$pos_args+1") + end + end + if test $pos_args -gt 2 + return 0 + end + end + return 1 +end + +complete -c flatpak -f -n "not __fish_flatpak_complete_files" -a '(__fish_complete_flatpak)' +complete -c flatpak -n "__fish_flatpak_complete_files" -a '(__fish_complete_flatpak)'