- Notifications
You must be signed in to change notification settings - Fork707
Add nushell completion for __zoxide_z#1129
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
f1080b3 to5cc4f1aCompare
ysthakur left a comment
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.
Random Nushell user here. Thanks for this! I have some minor comments
Uh oh!
There was an error while loading.Please reload this page.
| def "nu-complete __zoxide_z" [context: string] { | ||
| let ast = ast --flatten $context | skip 1 | ||
| # If the user has typed a space after the first argument, use the custom |
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.
I don't think$ast will be nonempty only if you add a space after the first argument.ast -f "z foo" (no space afterfoo) is still a length 2 list.
| # If the user hastyped a space after the first argument, use the custom | |
| # If the user hasentered an argument, use the custom |
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.
If you look at the next few lines, I compare the output ofast with the length of the$context, thats how I tell if there is an extra space after the first arg or not.
if$ast.0.span.end>= ($context| str length) {return null }
Uh oh!
There was an error while loading.Please reload this page.
| # | ||
| {{ section }} | ||
| # Completion for __zoxide_z | ||
| # |
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.
What's this for? The extra# and the blank line below, I mean.
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.
To match the formating of other section headers in the file
{{ section }}# Hook configuration for zoxide.# {{ section }}# When using zoxide with --no-cmd, alias these internal functions as desired.#5cc4f1a to17cc8ddCompare
nushell/nushell#15888 added support for completions to replace multiple arguments. This allows us to define a completion which replaces all the keywords with the correct file path upon accepting the path.
Also wrapped the whole script into a nushell module to prevent the completion command from polluting the command namespace. (That's why (the indentation) the diff is so messy, sorry)