-
Notifications
You must be signed in to change notification settings - Fork 2
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completion support coverage #23
Labels
Comments
amtoine
added
enhancement
New feature or request
help wanted
Extra attention is needed
labels
May 8, 2023
i've started with the def extract-subcommand-options [] {
let command = $in
let output = (
do -i { nu -c $"git ($command) -h" }
| complete
| reject exit_code # merge stdout and stderr, e.g. `am` to stderr and `checkout` to stdout
| transpose key value
| get value
| str join
| lines --skip-empty
| str trim
| str replace '^-' "%%-" # merge the multiline options
| str join " "
| split row "%%"
)
{
usage: ($output | find --invert --regex '^-' | str replace '^usage: ' '' | split row "or:" | str trim)
options: (
$output
| find --regex '^-' # pick the options only
| str replace " " " %% " # separate the flag and its description
| split column "%%" option description
| str trim
)
}
}
export def git-commands [] {
git help -a
| lines
| split list ""
| skip 1
| each {|section| {
section: ($section | get 0)
commands: ($section | skip 1)
}}
| where section not-in ["Command aliases" "External commands"]
| update commands { str trim | parse "{command} {description}" | str trim }
| flatten --all
| upsert data {|it|
print -n $"(ansi erase_line)extracting `git ($it.command)` from (char dq)($it.section)(char dq)\r"
$it.command | extract-subcommand-options
}
| flatten --all
} def to-nu [--indent: int = 4] {
str replace '-(.), --([\w-]*)' '--${2} (-${1})' option # fix the short/long flag format
| to md --pretty # convert to md table to have a nice alignment
| lines
| skip 2
| str replace '^\| ' $'(" " * $indent)' # remove the md table formatting
| str replace '\s+\|$' ''
| str replace ' \| ' ' # '
| to text
}
export def dump [file?: path] {
let output = (each {|it|
if ($it.usage | str join | str contains "is not a git command") {
print $"skipping ($it.command): not a git command"
} else {
let options = ($it.options | to-nu --indent 4 | str trim)
if ($options | is-empty) {
print $"skipping ($it.command): no option"
} else {[
$"# ($it.section)"
$"#"
$"# ($it.usage | str join $"\n(char hash)(char space)")"
$"export extern (char dq)git ($it.command)(char dq) ["
$" ($options)"
$"]"
] | str join "\n"}
}
} | str join "\n\n")
if $file != null {
$output | save --force $file
} else {
$output
}
} which can be used with let commands = (git-commands)
$commands | dump commands.nu and has to be completed with
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in the long run, i'd like to have more external and custom completions inside both
gm
andsugar
👍in
gm
in
sugar
external completions
gh
CLI command of GitHub insugar completions gh
: based ongh version 2.28.0 (2023-04-25)
?git
commandcore
,cherry
,remote
,worktree
, ..., to allow importing only usefull commands more easilycustom completions
sugar git
sugar gist
(removed)sugar gh
sugar dotfiles
(removed)The text was updated successfully, but these errors were encountered: