Put completions in their own module (#4880)

This commit is contained in:
JT 2022-03-20 12:03:58 +13:00 committed by GitHub
parent bd5778fa24
commit d5f23ab592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,20 +54,21 @@ let-env NU_PLUGIN_DIRS = [
($nu.config-path | path dirname | path join 'plugins') ($nu.config-path | path dirname | path join 'plugins')
] ]
# Custom completions for external commands (those outside of Nushell) module completions {
# Each completions has two parts: the form of the external command, including its flags and parameters # Custom completions for external commands (those outside of Nushell)
# and a helper command that knows how to complete values for those flags and parameters # Each completions has two parts: the form of the external command, including its flags and parameters
# # and a helper command that knows how to complete values for those flags and parameters
# This is a simplified version of completions for git branches and git remotes #
def "nu-complete git branches" [] { # This is a simplified version of completions for git branches and git remotes
def "nu-complete git branches" [] {
^git branch | lines | each { |line| $line | str find-replace '\* ' '' | str trim } ^git branch | lines | each { |line| $line | str find-replace '\* ' '' | str trim }
} }
def "nu-complete git remotes" [] { def "nu-complete git remotes" [] {
^git remote | lines | each { |line| $line | str trim } ^git remote | lines | each { |line| $line | str trim }
} }
extern "git checkout" [ export extern "git checkout" [
branch?: string@"nu-complete git branches" # name of the branch to checkout branch?: string@"nu-complete git branches" # name of the branch to checkout
-b: string # create and checkout a new branch -b: string # create and checkout a new branch
-B: string # create/reset and checkout a branch -B: string # create/reset and checkout a branch
@ -90,9 +91,9 @@ extern "git checkout" [
--patch(-p) # select hunks interactively --patch(-p) # select hunks interactively
--ignore-skip-worktree-bits # do not limit pathspecs to sparse entries only --ignore-skip-worktree-bits # do not limit pathspecs to sparse entries only
--pathspec-from-file: string # read pathspec from file --pathspec-from-file: string # read pathspec from file
] ]
extern "git push" [ export extern "git push" [
remote?: string@"nu-complete git remotes", # the name of the remote remote?: string@"nu-complete git remotes", # the name of the remote
refspec?: string@"nu-complete git branches"# the branch / refspec refspec?: string@"nu-complete git branches"# the branch / refspec
--verbose(-v) # be more verbose --verbose(-v) # be more verbose
@ -120,7 +121,11 @@ extern "git push" [
--push-option(-o): string # option to transmit --push-option(-o): string # option to transmit
--ipv4(-4) # use IPv4 addresses only --ipv4(-4) # use IPv4 addresses only
--ipv6(-6) # use IPv6 addresses only --ipv6(-6) # use IPv6 addresses only
] ]
}
# Get just the extern definitions without the custom completion commands
use completions *
# for more information on themes see # for more information on themes see
# https://github.com/nushell/nushell/blob/main/docs/How_To_Coloring_and_Theming.md # https://github.com/nushell/nushell/blob/main/docs/How_To_Coloring_and_Theming.md