-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ported script to help with vscode extension (#172)
- Loading branch information
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |