aboutsummaryrefslogtreecommitdiff
path: root/misc/zsh
diff options
context:
space:
mode:
Diffstat (limited to 'misc/zsh')
-rw-r--r--misc/zsh/completion.zsh11
-rw-r--r--misc/zsh/local.mk1
-rw-r--r--misc/zsh/run-help-nix42
3 files changed, 49 insertions, 5 deletions
diff --git a/misc/zsh/completion.zsh b/misc/zsh/completion.zsh
index e702c721e..f9b3dca74 100644
--- a/misc/zsh/completion.zsh
+++ b/misc/zsh/completion.zsh
@@ -10,14 +10,15 @@ function _nix() {
local -a suggestions
declare -a suggestions
for suggestion in ${res:1}; do
- # FIXME: This doesn't work properly if the suggestion word contains a `:`
- # itself
- suggestions+="${suggestion/ /:}"
+ suggestions+=("${suggestion%% *}")
done
+ local -a args
if [[ "$tpe" == filenames ]]; then
- compadd -f
+ args+=('-f')
+ elif [[ "$tpe" == attrs ]]; then
+ args+=('-S' '')
fi
- _describe 'nix' suggestions
+ compadd -J nix "${args[@]}" -a suggestions
}
_nix "$@"
diff --git a/misc/zsh/local.mk b/misc/zsh/local.mk
index 418fb1377..0b4e294fb 100644
--- a/misc/zsh/local.mk
+++ b/misc/zsh/local.mk
@@ -1 +1,2 @@
$(eval $(call install-file-as, $(d)/completion.zsh, $(datarootdir)/zsh/site-functions/_nix, 0644))
+$(eval $(call install-file-as, $(d)/run-help-nix, $(datarootdir)/zsh/site-functions/run-help-nix, 0644))
diff --git a/misc/zsh/run-help-nix b/misc/zsh/run-help-nix
new file mode 100644
index 000000000..f91a304eb
--- /dev/null
+++ b/misc/zsh/run-help-nix
@@ -0,0 +1,42 @@
+emulate -L zsh
+
+# run-help is a zsh widget that can be bound to a key. It mainly looks up the
+# man page for the currently typed in command.
+#
+# Although run-help works for any command without requiring special support,
+# it can only deduce the right man page based solely on the name of the
+# command. Programs like Nix provide better integration with run-help by
+# helping zsh identify Nix subcommands and their corresponding man pages. This
+# is what this function does.
+#
+# To actually use run-help on zsh, place the following lines in your .zshrc:
+#
+# (( $+aliases[run-help] )) && unalias run-help
+# autoload -Uz run-help run-help-nix
+#
+# Then also assign run-help to any key of choice:
+#
+# bindkey '^[h' run-help
+
+while [[ "$#" != 0 && "$1" == -* ]]; do
+ shift
+done
+
+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 $?