mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
🐛 fix some parser issues with type signatures (#1001)
When I updated nu to 101, the completions of poetry failed because of a missing `:` this ```nu def "nu-complete poetry python-versions" [] nothing -> list<string> { ``` for this ```nu def "nu-complete poetry python-versions" []: nothing -> list<string> { ``` Fixed a couple of places and some other parser issues
This commit is contained in:
parent
43d122448c
commit
4fa48b3e60
5 changed files with 45 additions and 41 deletions
|
@ -60,7 +60,7 @@ def pair-args [] {
|
||||||
{$"($pair.0 | str trim -c '-')": ($pair.1 | unquote)} # turn into a [{<flag> :<arg>}] removing quotes
|
{$"($pair.0 | str trim -c '-')": ($pair.1 | unquote)} # turn into a [{<flag> :<arg>}] removing quotes
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
| reduce { |it, acc| $acc | merge { $it }} # merge the list of records into one big record
|
| reduce { |it, acc| $acc | merge $it } # merge the list of records into one big record
|
||||||
}
|
}
|
||||||
|
|
||||||
def unquote [] {
|
def unquote [] {
|
||||||
|
@ -84,11 +84,10 @@ def make-commands-completion [] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let quote = '"' # "
|
|
||||||
|
|
||||||
# make the action nu completion string from subcommand and args
|
# make the action nu completion string from subcommand and args
|
||||||
# subcommand can be empty which will be the root command
|
# subcommand can be empty which will be the root command
|
||||||
def make-subcommands-completion [parents: list] {
|
def make-subcommands-completion [parents: list] {
|
||||||
|
let quote = '"' # "
|
||||||
let fishes = $in
|
let fishes = $in
|
||||||
$fishes
|
$fishes
|
||||||
| group-by a # group by sub command (a flag)
|
| group-by a # group by sub command (a flag)
|
||||||
|
|
|
@ -109,7 +109,7 @@ export extern "op account forget" [
|
||||||
--help(-h) # help for forget
|
--help(-h) # help for forget
|
||||||
--all # Forget all authenticated accounts.
|
--all # Forget all authenticated accounts.
|
||||||
|
|
||||||
account?: string: string@"nu completion account" # The account to forget.
|
account?: string@"nu completion account" # The account to forget.
|
||||||
]
|
]
|
||||||
|
|
||||||
# Manage Connect server instances and tokens in your 1Password account
|
# Manage Connect server instances and tokens in your 1Password account
|
||||||
|
@ -2124,7 +2124,7 @@ def "nu completion item" [] {
|
||||||
|
|
||||||
def parse_args_rg [] { "(?<opening_quote>['\"`]?)(?<content>.*?)(?<closing_quote>\\k<opening_quote>)(?<separator>\\s+)" }
|
def parse_args_rg [] { "(?<opening_quote>['\"`]?)(?<content>.*?)(?<closing_quote>\\k<opening_quote>)(?<separator>\\s+)" }
|
||||||
|
|
||||||
def "nu completion parse-context" [] string -> {cmd: string, args: list<string>} {
|
def "nu completion parse-context" []: string -> record {
|
||||||
# context strings starts at cursor position
|
# context strings starts at cursor position
|
||||||
let ctx = $in + ' ' # add space to end to ensure last part is parsed🙄
|
let ctx = $in + ' ' # add space to end to ensure last part is parsed🙄
|
||||||
mut parse = $ctx | parse --regex (parse_args_rg)
|
mut parse = $ctx | parse --regex (parse_args_rg)
|
||||||
|
@ -2177,7 +2177,7 @@ def "nu completion parse-context" [] string -> {cmd: string, args: list<string>}
|
||||||
def "nu completion output" [
|
def "nu completion output" [
|
||||||
ctx: string, # entered command [sub command, args, + options]
|
ctx: string, # entered command [sub command, args, + options]
|
||||||
--complete (-c) # if the copletion should have a closing quote and terminating space
|
--complete (-c) # if the copletion should have a closing quote and terminating space
|
||||||
] list<string> -> list<string>, string -> list<string> {
|
]: list<string> -> list<string>, string -> list<string> {
|
||||||
|
|
||||||
let output = $in
|
let output = $in
|
||||||
let parse = $ctx + ` `
|
let parse = $ctx + ` `
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
# Python versions
|
# Python versions
|
||||||
#
|
#
|
||||||
# Used by the add command to specify for which Python version the dependency must be installed
|
# Used by the add command to specify for which Python version the dependency must be installed
|
||||||
def "nu-complete poetry python-versions" [] nothing -> list<string> {
|
def "nu-complete poetry python-versions" []: nothing -> list<string> {
|
||||||
["3.8" "3.9" "3.10" "3.11" "3.12" "3.13"]
|
["3.8" "3.9" "3.10" "3.11" "3.12" "3.13"]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Default package source names
|
# Default package source names
|
||||||
#
|
#
|
||||||
# The default package source names available to install packages from
|
# The default package source names available to install packages from
|
||||||
def "nu-complete poetry default-package-source-names" [] nothing -> list<string> {
|
def "nu-complete poetry default-package-source-names" []: nothing -> list<string> {
|
||||||
[pypi test test.pypi.org internal-pypi]
|
[pypi test test.pypi.org internal-pypi]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Default package source urls
|
# Default package source urls
|
||||||
#
|
#
|
||||||
# The default package source urls available to install packages from
|
# The default package source urls available to install packages from
|
||||||
def "nu-complete poetry default-package-source-urls" [] nothing -> list<string> {
|
def "nu-complete poetry default-package-source-urls" []: nothing -> list<string> {
|
||||||
["https://" "https://test.pypi.org/legacy/" "https://pypi.org/legacy"]
|
["https://" "https://test.pypi.org/legacy/" "https://pypi.org/legacy"]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Default package sources
|
# Default package sources
|
||||||
#
|
#
|
||||||
# The default sources to use to install the package, beyond the ones defined within pyproject.toml available for the add command
|
# The default sources to use to install the package, beyond the ones defined within pyproject.toml available for the add command
|
||||||
def "nu-complete poetry default-package-sources" [] nothing -> list<string> {
|
def "nu-complete poetry default-package-sources" []: nothing -> list<string> {
|
||||||
(nu-complete poetry default-package-source-names) | append (
|
(nu-complete poetry default-package-source-names) | append (
|
||||||
nu-complete poetry default-package-source-urls
|
nu-complete poetry default-package-source-urls
|
||||||
)
|
)
|
||||||
|
@ -31,21 +31,21 @@ def "nu-complete poetry default-package-sources" [] nothing -> list<string> {
|
||||||
# Build formats
|
# Build formats
|
||||||
#
|
#
|
||||||
# Used by the build command to limit the built package to either sdist or wheel
|
# Used by the build command to limit the built package to either sdist or wheel
|
||||||
def "nu-complete poetry build-formats" [] nothing -> list<string> {
|
def "nu-complete poetry build-formats" []: nothing -> list<string> {
|
||||||
[sdist wheel]
|
[sdist wheel]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Default usernames
|
# Default usernames
|
||||||
#
|
#
|
||||||
# The current username which is the default suggestion for logging in to services with a username
|
# The current username which is the default suggestion for logging in to services with a username
|
||||||
def "nu-complete poetry default-usernames" [] nothing -> list<string> {
|
def "nu-complete poetry default-usernames" []: nothing -> list<string> {
|
||||||
[(whoami)]
|
[(whoami)]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Setting keys
|
# Setting keys
|
||||||
#
|
#
|
||||||
# The available setting keys that can be retrieved/changed by the config command
|
# The available setting keys that can be retrieved/changed by the config command
|
||||||
def "nu-complete poetry setting-keys" [] nothing -> list<string> {
|
def "nu-complete poetry setting-keys" []: nothing -> list<string> {
|
||||||
[
|
[
|
||||||
cache-dir
|
cache-dir
|
||||||
experimental.system-git-client
|
experimental.system-git-client
|
||||||
|
@ -87,7 +87,7 @@ def "nu-complete poetry setting-keys" [] nothing -> list<string> {
|
||||||
# Setting keys
|
# Setting keys
|
||||||
#
|
#
|
||||||
# The possible values for the given setting key, that the config command can chenge the respective setting key to
|
# The possible values for the given setting key, that the config command can chenge the respective setting key to
|
||||||
def "nu-complete poetry setting-values" [context: string] nothing -> list<any> {
|
def "nu-complete poetry setting-values" [context: string]: nothing -> list<any> {
|
||||||
let $final_context: string = ($context | str trim | split row " " | last)
|
let $final_context: string = ($context | str trim | split row " " | last)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -173,21 +173,21 @@ def "nu-complete poetry setting-values" [context: string] nothing -> list<any> {
|
||||||
# Export formats
|
# Export formats
|
||||||
#
|
#
|
||||||
# The list of possible formats supported by the export command
|
# The list of possible formats supported by the export command
|
||||||
def "nu-complete poetry export-formats" [] nothing -> list<string> {
|
def "nu-complete poetry export-formats" []: nothing -> list<string> {
|
||||||
["requirements.txt" "constraints.txt"]
|
["requirements.txt" "constraints.txt"]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Default dependency groups
|
# Default dependency groups
|
||||||
#
|
#
|
||||||
# A default selection of dependency groups
|
# A default selection of dependency groups
|
||||||
def "nu-complete poetry default-dependency-groups" [] nothing -> list<string> {
|
def "nu-complete poetry default-dependency-groups" []: nothing -> list<string> {
|
||||||
[main dev deploy test testing tests development developing deployment deploying]
|
[main dev deploy test testing tests development developing deployment deploying]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Commands
|
# Commands
|
||||||
#
|
#
|
||||||
# The list of command names available to have a help message displayed using the help command
|
# The list of command names available to have a help message displayed using the help command
|
||||||
def "nu-complete poetry commands" [] nothing -> list<string> {
|
def "nu-complete poetry commands" []: nothing -> list<string> {
|
||||||
[
|
[
|
||||||
about
|
about
|
||||||
add
|
add
|
||||||
|
@ -233,35 +233,35 @@ def "nu-complete poetry commands" [] nothing -> list<string> {
|
||||||
# Licenses
|
# Licenses
|
||||||
#
|
#
|
||||||
# The available license IDs for project.toml
|
# The available license IDs for project.toml
|
||||||
def "nu-complete poetry licenses" [] nothing -> list<string> {
|
def "nu-complete poetry licenses" []: nothing -> list<string> {
|
||||||
http get https://spdx.org/licenses/licenses.json | get licenses | get licenseId
|
http get https://spdx.org/licenses/licenses.json | get licenses | get licenseId
|
||||||
}
|
}
|
||||||
|
|
||||||
# ReadMe file formats
|
# ReadMe file formats
|
||||||
#
|
#
|
||||||
# A default selection of file extensions used for ReadMe files
|
# A default selection of file extensions used for ReadMe files
|
||||||
def "nu-complete poetry readme-file-formats" [] nothing -> list<string> {
|
def "nu-complete poetry readme-file-formats" []: nothing -> list<string> {
|
||||||
[md txt adoc rst rft pdf html dbk odf tex latex texi asciidoc markdown xhtml xht htm xml]
|
[md txt adoc rst rft pdf html dbk odf tex latex texi asciidoc markdown xhtml xht htm xml]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
#
|
#
|
||||||
# The list of namespaces available to list poetry commands about
|
# The list of namespaces available to list poetry commands about
|
||||||
def "nu-complete poetry namespaces" [] nothing -> list<string> {
|
def "nu-complete poetry namespaces" []: nothing -> list<string> {
|
||||||
[cache debug env self source]
|
[cache debug env self source]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Default repositories
|
# Default repositories
|
||||||
#
|
#
|
||||||
# The default set of repositories available to publish this projects package to
|
# The default set of repositories available to publish this projects package to
|
||||||
def "nu-complete poetry default-repositories" [] nothing -> list<string> {
|
def "nu-complete poetry default-repositories" []: nothing -> list<string> {
|
||||||
nu-complete poetry default-package-sources
|
nu-complete poetry default-package-sources
|
||||||
}
|
}
|
||||||
|
|
||||||
# Default dist directories
|
# Default dist directories
|
||||||
#
|
#
|
||||||
# The default set of directories where build artifacts may be stored
|
# The default set of directories where build artifacts may be stored
|
||||||
def "nu-complete poetry default-dist-directories" [] nothing -> list<string> {
|
def "nu-complete poetry default-dist-directories" []: nothing -> list<string> {
|
||||||
(
|
(
|
||||||
ls | get name | where (($it | path type) == "dir") | each {|it| $it | path expand}
|
ls | get name | where (($it | path type) == "dir") | each {|it| $it | path expand}
|
||||||
) | prepend ($env.PWD | path join "dist")
|
) | prepend ($env.PWD | path join "dist")
|
||||||
|
@ -270,21 +270,21 @@ def "nu-complete poetry default-dist-directories" [] nothing -> list<string> {
|
||||||
# Caches
|
# Caches
|
||||||
#
|
#
|
||||||
# The list of available poetry caches, used to remove one that is listed
|
# The list of available poetry caches, used to remove one that is listed
|
||||||
def "nu-complete poetry caches" [] nothing -> list<string> {
|
def "nu-complete poetry caches" []: nothing -> list<string> {
|
||||||
poetry cache list | lines
|
poetry cache list | lines
|
||||||
}
|
}
|
||||||
|
|
||||||
# Virtual environments
|
# Virtual environments
|
||||||
#
|
#
|
||||||
# The list of available virtual environements, used to remove one that is listed
|
# The list of available virtual environements, used to remove one that is listed
|
||||||
def "nu-complete poetry virtual-environments" [] nothing -> list<string> {
|
def "nu-complete poetry virtual-environments" []: nothing -> list<string> {
|
||||||
poetry env list --full-path | lines | each {|| (split row " ").0}
|
poetry env list --full-path | lines | each {|| (split row " ").0}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Source priorities
|
# Source priorities
|
||||||
#
|
#
|
||||||
# Used by the source commands to set/display the priority of the source
|
# Used by the source commands to set/display the priority of the source
|
||||||
def "nu-complete poetry source-priorities" [] nothing -> list<string> {
|
def "nu-complete poetry source-priorities" []: nothing -> list<string> {
|
||||||
[default primary secondary supplemental explicit]
|
[default primary secondary supplemental explicit]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ def gen_keywords [] {
|
||||||
| where is_extern == false
|
| where is_extern == false
|
||||||
and is_custom == false
|
and is_custom == false
|
||||||
and category !~ deprecated
|
and category !~ deprecated
|
||||||
and ($it.name | str contains -n ' ')
|
and not ($it.name | str contains ' ')
|
||||||
| get name
|
| get name
|
||||||
| str join '|')
|
| str join '|')
|
||||||
|
|
||||||
|
@ -12,10 +12,6 @@ def gen_keywords [] {
|
||||||
let postamble = ')\\b'
|
let postamble = ')\\b'
|
||||||
$'"match": "($var_with_dash_or_under_regex)|($preamble)($cmds)($postamble)",'
|
$'"match": "($var_with_dash_or_under_regex)|($preamble)($cmds)($postamble)",'
|
||||||
}
|
}
|
||||||
print $"Generating keywords(char nl)"
|
|
||||||
print (gen_keywords)
|
|
||||||
print (char nl)
|
|
||||||
print (char nl)
|
|
||||||
|
|
||||||
def gen_sub_keywords [] {
|
def gen_sub_keywords [] {
|
||||||
let sub_cmds = (scope commands
|
let sub_cmds = (scope commands
|
||||||
|
@ -33,9 +29,6 @@ def gen_sub_keywords [] {
|
||||||
} | str join '|')
|
} | str join '|')
|
||||||
$'"match": "($preamble)($cmds)($postamble)",'
|
$'"match": "($preamble)($cmds)($postamble)",'
|
||||||
}
|
}
|
||||||
print $"Generating sub keywords(char nl)"
|
|
||||||
print (gen_sub_keywords)
|
|
||||||
print (char nl)
|
|
||||||
|
|
||||||
def gen_keywords_alphabetically [] {
|
def gen_keywords_alphabetically [] {
|
||||||
let alphabet = [a b c d e f g h i j k l m n o p q r s t u v w x y z]
|
let alphabet = [a b c d e f g h i j k l m n o p q r s t u v w x y z]
|
||||||
|
@ -43,7 +36,7 @@ def gen_keywords_alphabetically [] {
|
||||||
| where is_extern == false
|
| where is_extern == false
|
||||||
and is_custom == false
|
and is_custom == false
|
||||||
and category !~ deprecated
|
and category !~ deprecated
|
||||||
and ($it.name | str contains -n ' ')
|
and not ($it.name | str contains ' ')
|
||||||
| get name)
|
| get name)
|
||||||
|
|
||||||
let preamble = '\\b('
|
let preamble = '\\b('
|
||||||
|
@ -64,9 +57,6 @@ def gen_keywords_alphabetically [] {
|
||||||
} | str join "\n"
|
} | str join "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Generating keywords alphabetically\n"
|
|
||||||
print (gen_keywords_alphabetically)
|
|
||||||
print (char nl)
|
|
||||||
|
|
||||||
def gen_sub_keywords_alphabetically [] {
|
def gen_sub_keywords_alphabetically [] {
|
||||||
let alphabet = [a b c d e f g h i j k l m n o p q r s t u v w x y z]
|
let alphabet = [a b c d e f g h i j k l m n o p q r s t u v w x y z]
|
||||||
|
@ -96,6 +86,21 @@ def gen_sub_keywords_alphabetically [] {
|
||||||
} | str join "\n"
|
} | str join "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Generating sub keywords alphabetically\n"
|
export def main [] {
|
||||||
print (gen_sub_keywords_alphabetically)
|
print $"Generating keywords(char nl)"
|
||||||
print (char nl)
|
print (gen_keywords)
|
||||||
|
print (char nl)
|
||||||
|
print (char nl)
|
||||||
|
|
||||||
|
print $"Generating sub keywords(char nl)"
|
||||||
|
print (gen_sub_keywords)
|
||||||
|
print (char nl)
|
||||||
|
|
||||||
|
print "Generating keywords alphabetically\n"
|
||||||
|
print (gen_keywords_alphabetically)
|
||||||
|
print (char nl)
|
||||||
|
|
||||||
|
print "Generating sub keywords alphabetically\n"
|
||||||
|
print (gen_sub_keywords_alphabetically)
|
||||||
|
print (char nl)
|
||||||
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ def __cwdhist_switching [] {
|
||||||
export def empty-sqlite [] {
|
export def empty-sqlite [] {
|
||||||
# sqlite3 empty.db "VACUUM;"; cat empty.db | gzip | encode base64
|
# sqlite3 empty.db "VACUUM;"; cat empty.db | gzip | encode base64
|
||||||
'H4sIAAAAAAAAAwsO9MksSVVIyy/KTSxRMGYQYGBkZHBQUGBgYGCEYhhAZhMLGBn0ihbwglgCZOgeBaNgFIyCUTAKRsEoGAWjYBSMglEwCkYBVQAANHgbMAAQAAA='
|
'H4sIAAAAAAAAAwsO9MksSVVIyy/KTSxRMGYQYGBkZHBQUGBgYGCEYhhAZhMLGBn0ihbwglgCZOgeBaNgFIyCUTAKRsEoGAWjYBSMglEwCkYBVQAANHgbMAAQAAA='
|
||||||
| decode base64 --binary | gzip -d
|
| decode base64 | gzip -d
|
||||||
}
|
}
|
||||||
|
|
||||||
export def 'cwd history delete' [cwd] {
|
export def 'cwd history delete' [cwd] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue