-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sourceInputCompletionHook: init #104225
sourceInputCompletionHook: init #104225
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ makeSetupHook, findutils, substituteAll }: | ||
|
||
# See the header comment in ./source-input-completion-hook.sh for example usage. | ||
makeSetupHook { name = "source-input-completion-hook"; } ( | ||
substituteAll { | ||
src = ./source-input-completion-hook.sh; | ||
inherit findutils; | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
# This function is meant to inspect the inputs to a derivation and source the shell completion. | ||
# This is intended to be only used with nix-shell to provide a better user experience, and is not | ||
# intended to be used within nixpkgs as shell completion is only useful in an interactive shell. | ||
sourceInputCompletion() { | ||
local completionPath= | ||
|
||
case $(basename $SHELL) in | ||
bash) | ||
completionPath=share/bash-completion/completions/ | ||
;; | ||
fish) | ||
completionPath=share/fish/vendor_completions.d/ | ||
;; | ||
zsh) | ||
completionPath=share/zsh/site-functions/ | ||
;; | ||
*) | ||
echo "$(basename $SHELL) is not supported for shell completion. Skipping." | ||
exit 0 | ||
esac | ||
|
||
declare -A inputsSourced | ||
for input in $nativeBuildInputs $buildInputs $propagatedNativeBuildInputs $propagatedBuildInputs; do | ||
local completionDir=$input/$completionPath | ||
if [ -d $completionDir ]; then | ||
for script in $(@findutils@/bin/find $completionDir -type f); do | ||
. $script | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bash completions should be loaded lazily. This can be achieved with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I'm thinking of closing this in favor of #103501 . Made this PR before I was aware of it's existence |
||
# grab derivation pname. E.g. /nix/store/...-kubectl-1.19.4 -> kubectl | ||
inputsSourced[$(echo $input | sed -e 's/[^-]*-//' | sed -e 's/-.*$//')]=1 | ||
done | ||
fi | ||
done | ||
|
||
echo "Completions added for: ${!inputsSourced[@]}" | ||
} | ||
|
||
if [ -z "$dontUseSourceInputCompletion" ]; then | ||
sourceInputCompletion | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,6 +161,8 @@ in | |
deps = [ innoextract file-rename ]; } | ||
../build-support/setup-hooks/gog-unpack.sh; | ||
|
||
sourceInputCompletionHook = callPackage ../shells/hooks/sourceInputCompletionHook { }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explicitly state |
||
|
||
buildEnv = callPackage ../build-support/buildenv { }; # not actually a package | ||
|
||
# TODO: eventually migrate everything to buildFHSUserEnvBubblewrap | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.