Skip to content

Conversation

@Juhan280
Copy link

@Juhan280 Juhan280 commented Nov 4, 2025

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)

Copy link

@ysthakur ysthakur left a 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

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

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 after foo) is still a length 2 list.

Suggested change
# If the user has typed a space after the first argument, use the custom
# If the user has entered an argument, use the custom

Copy link
Author

@Juhan280 Juhan280 Nov 13, 2025

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 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 }

#
{{ section }}
# Completion for __zoxide_z
#
Copy link

@ysthakur ysthakur Nov 13, 2025

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.

Copy link
Author

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. 
   #

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants