Add nushell completion for __zoxide_z#1129
Add nushell completion for __zoxide_z#1129Juhan280 wants to merge 8 commits intoajeetdsouza:mainfrom
Conversation
f1080b3 to
5cc4f1a
Compare
ysthakur
left a comment
There was a problem hiding this comment.
Random Nushell user here. Thanks for this! I have some minor comments
| 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.
I don't think $ast will be nonempty only if you add a space after the first argument. ast -f "z foo" (no space after foo) is still a length 2 list.
| # If the user has typed a space after the first argument, use the custom | |
| # If the user has entered an argument, use the custom |
There was a problem hiding this comment.
If you look at the next few lines, I compare the output of ast 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 }5cc4f1a to
17cc8dd
Compare
This prevents the completion command "nu-complete __zoxide_z" from polluting the command namespace.
30291f1 to
bdedc2a
Compare
|
Minimum nushell version required to make zoxide work without completion: |
c6c4791 to
be220c9
Compare
|
edit: the above problem was just me being stupid, this code works perfectly fine @ajeetdsouza Could we get this PR merged? Despite the problem mentioned above, I think it's good enough for completing single arguments (we can make a new PR in the future once Nushell's completion story improves). If it makes any difference, I'm one of the Nushell maintainers and can confirm that the code in this PR works. |
|
@ysthakur, what nushell version have you tried? You need |
|
@Juhan280 I'm really sorry, I was just being really dumb above. I completely forgot that we already added the ability to specify spans in custom completers (I'm the one who implemented it). I have 0.110 installed locally, but because of the |
Nushell version
0.109.0(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)
Minimum nushell version required to make zoxide work without completion:
0.106.0To make completion script work properly:
0.109.0