From e1b9e632b0ed18f4af2c5016b9dfce8e6d1a6f5d Mon Sep 17 00:00:00 2001 From: Aldwin Vlasblom Date: Sun, 29 Mar 2020 18:56:46 +0200 Subject: [PATCH] Update deployments completion to respect --state The possible deployments are taken from a database. The database file is also passed on the command line. If the user passes a database file, we'd like to list the deployments from that file, and not the default one. --- _nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/_nix b/_nix index e5244d6..ad5c838 100644 --- a/_nix +++ b/_nix @@ -978,11 +978,19 @@ function _nix_completion () { ${main_options[*]} \ ${nix_boilerplate_opts[*]} && return 0 + local statecmd + if [[ "${opts[--state]}" || "${opts[-s]}" ]]; then + local statefile="${opt_args[--state]:-${opt_args[-s]}}" + if [[ "$statefile" == *.nixops && -f "$statefile" ]]; then + statecmd="--state $statefile" + fi + fi + case "$state" in nixops_deployments) local -a deployments=() while read -r _ id _ name _; do deployments+=("$id" "$name") - done < <(nixops list | tail -n +4 | head -n -1) + done < <(nixops list $statecmd | tail -n +4 | head -n -1) COMPREPLY=($(compgen -W "${deployments[*]}" -- "$cur")) return ;;