You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@zetanumbers the current implementation sends to the custom completion two args [current_line: string, pos: int]. Based on that you could parse the current line and be aware of that was already specified previously. It's not the best way to do but at least some starting point.
Here's one example:
def "extract-flag" [line: string] {
line | parse -r "(?P<n>-n [a-zA-Z-0-9]+)"
}
def "nu-complete mycmd test" [line: string, pos: int] {
let my_flag = extract-flag $line
// flag can be ""
// or "-n Something123"
if ($my_flag | str length) == 0 {
// no flag specified, do something
[ no flags input ]
} else {
// flag specified, do anything with it $my_flag
[ the flag is $my_flag ]
}
}
export extern "mycmd test" [
target?: string@"nu-complete mycmd test"
]
This came with some refactor in the completions part (#5102)
Handling current_line is probably not a good idea because you have to account for quotes, spaces, etc. Perhaps there could be some sort of parse_args function? Or maybe we could just pass string array and not worry, tho it would be opinionated to handle args in some way or another? I think there will be downside of copying the logic in completions, until we pass fully preprocessed args.
Completers now get the already parsed arguments of the command.
Declare the completer with a place: record parameter and $place.command holds them (#16765, #18791).
Activity
mxfp0 commentedon Apr 7, 2022
@zetanumbers the current implementation sends to the custom completion two args
[current_line: string, pos: int]. Based on that you could parse the current line and be aware of that was already specified previously. It's not the best way to do but at least some starting point.Here's one example:
This came with some refactor in the completions part (#5102)
zetanumbers commentedon Apr 7, 2022
Handling current_line is probably not a good idea because you have to account for quotes, spaces, etc. Perhaps there could be some sort of parse_args function? Or maybe we could just pass string array and not worry, tho it would be opinionated to handle args in some way or another? I think there will be downside of copying the logic in completions, until we pass fully preprocessed args.
Command-wide completions (#16765)
kronberger-droid commentedon Nov 13, 2026
Completers now get the already parsed arguments of the command.
Declare the completer with a
place: recordparameter and$place.commandholds them (#16765, #18791).