aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authormidchildan <git@midchildan.org>2022-04-27 01:56:10 +0900
committermidchildan <git@midchildan.org>2022-04-27 01:56:10 +0900
commit68d51ae01278f314283523120713e745ef184011 (patch)
treeb9523d3b4194d1054f0d51d196c6aa15649b0b1c /misc
parent0f7c7ab97bef68339e480a018425de8b3f05ec43 (diff)
refactor: don't hardcode nix subcommands in run-help-nix
Diffstat (limited to 'misc')
-rw-r--r--misc/zsh/run-help-nix87
1 files changed, 16 insertions, 71 deletions
diff --git a/misc/zsh/run-help-nix b/misc/zsh/run-help-nix
index 45588470b..f91a304eb 100644
--- a/misc/zsh/run-help-nix
+++ b/misc/zsh/run-help-nix
@@ -18,80 +18,25 @@ emulate -L zsh
#
# bindkey '^[h' run-help
-if (( $# == 0 )); then
- man nix
- return
-fi
-
while [[ "$#" != 0 && "$1" == -* ]]; do
shift
done
-case "$1" in
- flake)
- case "$2" in
- archive|check|clone|info|init|lock|metadata|new|prefetch|show|update)
- man "nix3-$1-$2" ;;
- *)
- man "nix3-$1" ;;
- esac ;;
- hash)
- case "$2" in
- file|path|to-base16|to-base32|to-base64|to-sri)
- man "nix3-$1-$2" ;;
- *)
- man "nix3-$1" ;;
- esac ;;
- key)
- case "$2" in
- convert-secret-to-public|generate-secret)
- man "nix3-$1-$2" ;;
- *)
- man "nix3-$1" ;;
- esac ;;
- nar)
- case "$2" in
- cat|dump-path|ls)
- man "nix3-$1-$2" ;;
- *)
- man "nix3-$1" ;;
- esac ;;
- profile)
- case "$2" in
- diff-closures|history|install|list|remove|rollback|upgrade|wipe-history)
- man "nix3-$1-$2" ;;
- *)
- man "nix3-$1" ;;
- esac ;;
- realisation)
- case "$2" in
- info)
- man "nix3-$1-$2" ;;
- *)
- man "nix3-$1" ;;
- esac ;;
- registry)
- case "$2" in
- add|list|pin|remove)
- man "nix3-$1-$2" ;;
- *)
- man "nix3-$1" ;;
- esac ;;
- store)
- case "$2" in
- add-file|add-path|cat|copy-sigs|delete|diff-closures|dump-path|gc|ls)
- ;& # fallthrough
- make-content-addressed|optimise|ping|prefetch-file|repair|sign|verify)
- man "nix3-$1-$2" ;;
- *)
- man "nix3-$1" ;;
- esac ;;
- *)
- if man -w "nix3-$1" >/dev/null 2>&1; then
- man "nix3-$1"
- else
- man nix
- fi ;;
-esac
+local -a subcommands; subcommands=( nix3 )
+
+local arg
+for arg in "$@"; do
+ if man -w "${(j:-:)subcommands}-$arg" >/dev/null 2>&1; then
+ subcommands+="$arg"
+ else
+ break
+ fi
+done
+
+if (( $#subcommands > 1 )); then
+ man "${(j:-:)subcommands}"
+else
+ man nix
+fi
return $?