From ca9a2151f6443fbb5eb4122846ca031e62504b75 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Thu, 27 Jan 2022 12:37:35 -0800 Subject: [PATCH] Add fish function for generating and saving completions --- .../fish/functions/update_completions.fish | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 assets/default/fish/functions/update_completions.fish diff --git a/assets/default/fish/functions/update_completions.fish b/assets/default/fish/functions/update_completions.fish new file mode 100644 index 0000000..f8fcec0 --- /dev/null +++ b/assets/default/fish/functions/update_completions.fish @@ -0,0 +1,20 @@ +function update_completions --description "Update completions for a command" --argument-names "target_command" + # Usage: update_completions kubectl completion fish + # + # This generates new completions, sources them, and then saves it to your + # user completions directory for future loading. + + if not set -q target_command ; or [ -z "$target_command" ] + echo "Must pass some command to generate completions. eg: update_completions kubectl completion fish" 1>&2 + return 1 + end + + set --local completion_dir "$HOME/.config/fish/completions" + if set -q XDG_CONFIG_HOME + set --local completion_dir "$XDG_CONFIG_HOME" + end + + set --local completion_path "$completion_dir/$target_command.fish" + eval $argv[1..] | tee "$completion_path" | source + echo "Completions for $target_command generated, sourced, and stored in $completion_path for future shells" 1>&2 +end