1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 22:57:46 +00:00

ported script to help with vscode extension (#172)

This commit is contained in:
Darren Schroeder 2022-03-08 16:27:43 -06:00 committed by GitHub
parent 09abce0d18
commit 6645c7fd08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

101
make_release/gen-js-ext.nu Normal file
View file

@ -0,0 +1,101 @@
def gen_keywords [] {
let cmds = ($nu.scope.commands
| where is_extern == false
&& is_custom == false
&& category !~ deprecated
&& ($it.command | str contains -n ' ')
| get command
| str collect '|')
let var_with_dash_or_under_regex = '(([a-zA-Z]+[\\-_]){1,}[a-zA-Z]+\\s)'
let preamble = '\\b('
let postamble = ')\\b'
$'"match": "($var_with_dash_or_under_regex)|($preamble)($cmds)($postamble)",'
}
$"Generating keywords(char nl)"
gen_keywords
char nl
char nl
def gen_sub_keywords [] {
let sub_cmds = ($nu.scope.commands
| where is_extern == false
&& is_custom == false
&& category !~ deprecated
&& ($it.command | str contains ' ')
| get command)
let preamble = '\\b('
let postamble = ')\\b'
let cmds = (for x in $sub_cmds {
let parts = ($x | split row ' ')
$'($parts.0)\\s($parts.1)'
} | str collect '|')
$'"match": "($preamble)($cmds)($postamble)",'
}
$"Generating sub keywords(char nl)"
gen_sub_keywords
char nl
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 cmds = ($nu.scope.commands
| where is_extern == false
&& is_custom == false
&& category !~ deprecated
&& ($it.command | str contains -n ' ')
| get command)
let preamble = '\\b('
let postamble = ')\\b'
for alpha in $alphabet {
let letter_cmds = (for cmd in $cmds {
if ($cmd | str starts-with $alpha) {
$cmd
} else {
$nothing
}
} | str collect '|')
if ($letter_cmds | str trim | str length) > 0 {
$'"match": "($preamble)($letter_cmds)($postamble)",'
}
} | str collect "\n"
}
"Generating keywords alphabetically\n"
gen_keywords_alphabetically
char nl
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 sub_cmds = ($nu.scope.commands
| where is_extern == false
&& is_custom == false
&& category !~ deprecated
&& ($it.command | str contains ' ')
| get command)
let preamble = '\\b('
let postamble = ')\\b'
for alpha in $alphabet {
let letter_cmds = (for cmd in $sub_cmds {
if ($cmd | str starts-with $alpha) {
let parts = ($cmd | split row ' ')
$'($parts.0)\\s($parts.1)'
} else {
$nothing
}
} | str collect '|')
if ($letter_cmds | str trim | str length) > 0 {
$'"match": "($preamble)($letter_cmds)($postamble)",'
}
} | str collect "\n"
}
"Generating sub keywords alphabetically\n"
gen_sub_keywords_alphabetically
char nl