mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Migrate some scripts to fit new variable and arguments naming style (#268)
* add tmp script * fix more scripts * remove tmp file * migrate to new variable definition * rename builtin variable back
This commit is contained in:
parent
ea7de87315
commit
a34f173181
10 changed files with 99 additions and 99 deletions
|
@ -9,8 +9,8 @@
|
||||||
# ...etc.
|
# ...etc.
|
||||||
# #base0f-hex
|
# #base0f-hex
|
||||||
# ```
|
# ```
|
||||||
export def build-nu-config [base-txt: path] {
|
export def build-nu-config [base_txt: path] {
|
||||||
let b16 = (from-file $base-txt)
|
let b16 = (from-file $base_txt)
|
||||||
|
|
||||||
{
|
{
|
||||||
separator: $b16.base03
|
separator: $b16.base03
|
||||||
|
@ -56,8 +56,8 @@ export def build-nu-config [base-txt: path] {
|
||||||
# Generate Alacritty color config to be included in the main Alacritty config
|
# Generate Alacritty color config to be included in the main Alacritty config
|
||||||
#
|
#
|
||||||
# It injects the base16 colors into the Alacritty config template
|
# It injects the base16 colors into the Alacritty config template
|
||||||
export def build-alacritty-config [base-txt: path] {
|
export def build-alacritty-config [base_txt: path] {
|
||||||
let base16 = (from-file-table $base-txt)
|
let base16 = (from-file-table $base_txt)
|
||||||
let template = (
|
let template = (
|
||||||
open "~/.config/nushell/alacritty_colors.mustache" |
|
open "~/.config/nushell/alacritty_colors.mustache" |
|
||||||
decode utf-8
|
decode utf-8
|
||||||
|
@ -73,13 +73,13 @@ export def build-alacritty-config [base-txt: path] {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate LS_COLORS value
|
# Generate LS_COLORS value
|
||||||
export def build-lscolors [base-txt: path] {
|
export def build-lscolors [base_txt: path] {
|
||||||
# TODO
|
# TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
# Show the current base16 colors
|
# Show the current base16 colors
|
||||||
export def show [base-txt: path] {
|
export def show [base_txt: path] {
|
||||||
from-file $base-txt | each { |it|
|
from-file $base_txt | each { |it|
|
||||||
{ $it.column: $"(ansi -e { fg: ($it.value) bg: ($it.value) })($it.value)(ansi reset)" }
|
{ $it.column: $"(ansi -e { fg: ($it.value) bg: ($it.value) })($it.value)(ansi reset)" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,51 +92,51 @@ export def new-wallpaper [] {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get base16 as a record from an input file
|
# Get base16 as a record from an input file
|
||||||
export def from-file [base-txt: path] {
|
export def from-file [base_txt: path] {
|
||||||
let base16-lines = (open $base-txt | lines | where ($it | str length) > 0)
|
let base16_lines = (open $base_txt | lines | where ($it | str length) > 0)
|
||||||
|
|
||||||
{
|
{
|
||||||
base00 : $base16-lines.0 # Default Background
|
base00 : $base16_lines.0 # Default Background
|
||||||
base01 : $base16-lines.1 # Lighter Background (Used for status bars, line number and folding marks)
|
base01 : $base16_lines.1 # Lighter Background (Used for status bars, line number and folding marks)
|
||||||
base02 : $base16-lines.2 # Selection Background
|
base02 : $base16_lines.2 # Selection Background
|
||||||
base03 : $base16-lines.3 # Comments, Invisibles, Line Highlighting
|
base03 : $base16_lines.3 # Comments, Invisibles, Line Highlighting
|
||||||
base04 : $base16-lines.4 # Dark Foreground (Used for status bars)
|
base04 : $base16_lines.4 # Dark Foreground (Used for status bars)
|
||||||
base05 : $base16-lines.5 # Default Foreground, Caret, Delimiters, Operators
|
base05 : $base16_lines.5 # Default Foreground, Caret, Delimiters, Operators
|
||||||
base06 : $base16-lines.6 # Light Foreground (Not often used)
|
base06 : $base16_lines.6 # Light Foreground (Not often used)
|
||||||
base07 : $base16-lines.7 # Light Background (Not often used)
|
base07 : $base16_lines.7 # Light Background (Not often used)
|
||||||
base08 : $base16-lines.8 # Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted
|
base08 : $base16_lines.8 # Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted
|
||||||
base09 : $base16-lines.9 # Integers, Boolean, Constants, XML Attributes, Markup Link Url
|
base09 : $base16_lines.9 # Integers, Boolean, Constants, XML Attributes, Markup Link Url
|
||||||
base0a : $base16-lines.10 # Classes, Markup Bold, Search Text Background
|
base0a : $base16_lines.10 # Classes, Markup Bold, Search Text Background
|
||||||
base0b : $base16-lines.11 # Strings, Inherited Class, Markup Code, Diff Inserted
|
base0b : $base16_lines.11 # Strings, Inherited Class, Markup Code, Diff Inserted
|
||||||
base0c : $base16-lines.12 # Support, Regular Expressions, Escape Characters, Markup Quotes
|
base0c : $base16_lines.12 # Support, Regular Expressions, Escape Characters, Markup Quotes
|
||||||
base0d : $base16-lines.13 # Functions, Methods, Attribute IDs, Headings
|
base0d : $base16_lines.13 # Functions, Methods, Attribute IDs, Headings
|
||||||
base0e : $base16-lines.14 # Keywords, Storage, Selector, Markup Italic, Diff Changed
|
base0e : $base16_lines.14 # Keywords, Storage, Selector, Markup Italic, Diff Changed
|
||||||
base0f : $base16-lines.15 # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
|
base0f : $base16_lines.15 # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get base16 as a table from an input file
|
# Get base16 as a table from an input file
|
||||||
export def from-file-table [base-txt: path] {
|
export def from-file-table [base_txt: path] {
|
||||||
let base16-lines = (open $base-txt | lines | where ($it | str length) > 0)
|
let base16_lines = (open $base_txt | lines | where ($it | str length) > 0)
|
||||||
|
|
||||||
[
|
[
|
||||||
[ name color ];
|
[ name color ];
|
||||||
[ base00 $base16-lines.0 ] # Default Background
|
[ base00 $base16_lines.0 ] # Default Background
|
||||||
[ base01 $base16-lines.1 ] # Lighter Background (Used for status bars, line number and folding marks)
|
[ base01 $base16_lines.1 ] # Lighter Background (Used for status bars, line number and folding marks)
|
||||||
[ base02 $base16-lines.2 ] # Selection Background
|
[ base02 $base16_lines.2 ] # Selection Background
|
||||||
[ base03 $base16-lines.3 ] # Comments, Invisibles, Line Highlighting
|
[ base03 $base16_lines.3 ] # Comments, Invisibles, Line Highlighting
|
||||||
[ base04 $base16-lines.4 ] # Dark Foreground (Used for status bars)
|
[ base04 $base16_lines.4 ] # Dark Foreground (Used for status bars)
|
||||||
[ base05 $base16-lines.5 ] # Default Foreground, Caret, Delimiters, Operators
|
[ base05 $base16_lines.5 ] # Default Foreground, Caret, Delimiters, Operators
|
||||||
[ base06 $base16-lines.6 ] # Light Foreground (Not often used)
|
[ base06 $base16_lines.6 ] # Light Foreground (Not often used)
|
||||||
[ base07 $base16-lines.7 ] # Light Background (Not often used)
|
[ base07 $base16_lines.7 ] # Light Background (Not often used)
|
||||||
[ base08 $base16-lines.8 ] # Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted
|
[ base08 $base16_lines.8 ] # Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted
|
||||||
[ base09 $base16-lines.9 ] # Integers, Boolean, Constants, XML Attributes, Markup Link Url
|
[ base09 $base16_lines.9 ] # Integers, Boolean, Constants, XML Attributes, Markup Link Url
|
||||||
[ base0a $base16-lines.10 ] # Classes, Markup Bold, Search Text Background
|
[ base0a $base16_lines.10 ] # Classes, Markup Bold, Search Text Background
|
||||||
[ base0b $base16-lines.11 ] # Strings, Inherited Class, Markup Code, Diff Inserted
|
[ base0b $base16_lines.11 ] # Strings, Inherited Class, Markup Code, Diff Inserted
|
||||||
[ base0c $base16-lines.12 ] # Support, Regular Expressions, Escape Characters, Markup Quotes
|
[ base0c $base16_lines.12 ] # Support, Regular Expressions, Escape Characters, Markup Quotes
|
||||||
[ base0d $base16-lines.13 ] # Functions, Methods, Attribute IDs, Headings
|
[ base0d $base16_lines.13 ] # Functions, Methods, Attribute IDs, Headings
|
||||||
[ base0e $base16-lines.14 ] # Keywords, Storage, Selector, Markup Italic, Diff Changed
|
[ base0e $base16_lines.14 ] # Keywords, Storage, Selector, Markup Italic, Diff Changed
|
||||||
[ base0f $base16-lines.15 ] # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
|
[ base0f $base16_lines.15 ] # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,13 +50,13 @@ def print_run [start:int, amount:int] {
|
||||||
} | append " " | str collect
|
} | append " " | str collect
|
||||||
}
|
}
|
||||||
|
|
||||||
def print_blocks [start:int, end:int, block-cols:int, block-rows:int, blocks-per-line:int] {
|
def print_blocks [start:int, end:int, block_cols:int, block_rows:int, blocks_per_line:int] {
|
||||||
let block-length = ($block-cols * $block-rows)
|
let block_length = ($block_cols * $block_rows)
|
||||||
let end = (($end - $start) / (($blocks-per-line) * $block-length))
|
let end = (($end - $start) / (($blocks_per_line) * $block_length))
|
||||||
for i in 0..<$end {
|
for i in 0..<$end {
|
||||||
for row in 0..<$block-rows {
|
for row in 0..<$block_rows {
|
||||||
for block in 0..<$blocks-per-line {
|
for block in 0..<$blocks_per_line {
|
||||||
print_run ($start + $block * $block-length + $row * $block-cols + $i * $block-length * $blocks-per-line) $block-cols
|
print_run ($start + $block * $block_length + $row * $block_cols + $i * $block_length * $blocks_per_line) $block_cols
|
||||||
} | append (char nl) | str collect
|
} | append (char nl) | str collect
|
||||||
} | str collect
|
} | str collect
|
||||||
} | str collect
|
} | str collect
|
||||||
|
|
|
@ -12,8 +12,8 @@ def build-completions-from-pwd [] {
|
||||||
}
|
}
|
||||||
|
|
||||||
# build a completion form a .fish file and generate a .nu file
|
# build a completion form a .fish file and generate a .nu file
|
||||||
def build-completion [fish-file: path, nu-file: path] {
|
def build-completion [fish_file: path, nu_file: path] {
|
||||||
open $fish-file | parse-fish | make-commands-completion | str collect "\n\n" | save $nu-file
|
open $fish_file | parse-fish | make-commands-completion | str collect "\n\n" | save $nu_file
|
||||||
}
|
}
|
||||||
|
|
||||||
# parse a .fish file based on autogenerated complete syntax
|
# parse a .fish file based on autogenerated complete syntax
|
||||||
|
@ -38,15 +38,15 @@ def parse-fish [] {
|
||||||
# tokenize each line of the fish file into a list of tokens
|
# tokenize each line of the fish file into a list of tokens
|
||||||
# make use of detect columns -n which with one like properly tokenizers arguments including across quotes
|
# make use of detect columns -n which with one like properly tokenizers arguments including across quotes
|
||||||
def tokenize-complete-lines [] {
|
def tokenize-complete-lines [] {
|
||||||
lines
|
lines
|
||||||
| each { |line|
|
| each { |line|
|
||||||
$line
|
$line
|
||||||
| where $line starts-with complete
|
| where $line starts-with complete
|
||||||
| str replace -a "\\\\'" "" # remove escaped quotes ' which break detect columns
|
| str replace -a "\\\\'" "" # remove escaped quotes ' which break detect columns
|
||||||
| str replace -a "-f " "" # remove -f which is a boolean flag we don't support yet
|
| str replace -a "-f " "" # remove -f which is a boolean flag we don't support yet
|
||||||
| detect columns -n
|
| detect columns -n
|
||||||
| transpose -i tokens # turn columns into items, each is a token
|
| transpose -i tokens # turn columns into items, each is a token
|
||||||
}
|
}
|
||||||
| where ($it | length) > 0 # remove any empty lines
|
| where ($it | length) > 0 # remove any empty lines
|
||||||
| get tokens # get the list of tokens
|
| get tokens # get the list of tokens
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,10 @@ def tokenize-complete-lines [] {
|
||||||
def pair-args [] {
|
def pair-args [] {
|
||||||
where $it != complete # drop complete command as we don't need it
|
where $it != complete # drop complete command as we don't need it
|
||||||
| window 2 -s 2 # group by ordered pairs, using window 2 -s 2 instead of group 2 to automatically drop any left overs
|
| window 2 -s 2 # group by ordered pairs, using window 2 -s 2 instead of group 2 to automatically drop any left overs
|
||||||
| each { |pair|
|
| each { |pair|
|
||||||
[
|
[
|
||||||
{$"($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
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ def make-subcommands-completion [parents: list] {
|
||||||
| transpose name args # turn it into a table of name to arguments
|
| transpose name args # turn it into a table of name to arguments
|
||||||
| each {|subcommand|
|
| each {|subcommand|
|
||||||
build-string (
|
build-string (
|
||||||
if ('d' in ($subcommand.args | columns)) && ($subcommand.args.d != "") {
|
if ('d' in ($subcommand.args | columns)) && ($subcommand.args.d != "") {
|
||||||
build-string "# " ($subcommand.args.d.0) "\n" # (sub)command description
|
build-string "# " ($subcommand.args.d.0) "\n" # (sub)command description
|
||||||
}) "extern " $quote ($parents | str collect " ") (
|
}) "extern " $quote ($parents | str collect " ") (
|
||||||
if $subcommand.name != "" {
|
if $subcommand.name != "" {
|
||||||
|
@ -108,7 +108,7 @@ def make-subcommands-completion [parents: list] {
|
||||||
} else {
|
} else {
|
||||||
where ($it.n == "__fish_use_subcommand") && ($it.a == "") # for root command -> any where n == __fish_use_subcommand and a is empty. otherwise a means a subcommand
|
where ($it.n == "__fish_use_subcommand") && ($it.a == "") # for root command -> any where n == __fish_use_subcommand and a is empty. otherwise a means a subcommand
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$fishes # catch all
|
$fishes # catch all
|
||||||
}
|
}
|
||||||
| build-flags
|
| build-flags
|
||||||
|
@ -119,11 +119,11 @@ def make-subcommands-completion [parents: list] {
|
||||||
|
|
||||||
# build the list of flag string in nu syntax
|
# build the list of flag string in nu syntax
|
||||||
def build-flags [] {
|
def build-flags [] {
|
||||||
each { |subargs|
|
each { |subargs|
|
||||||
if ('l' in ($subargs | columns)) && ($subargs.l != "") {
|
if ('l' in ($subargs | columns)) && ($subargs.l != "") {
|
||||||
build-string "\t--" $subargs.l (build-string
|
build-string "\t--" $subargs.l (build-string
|
||||||
(if ('s' in ($subargs | columns)) && ($subargs.s != "") {
|
(if ('s' in ($subargs | columns)) && ($subargs.s != "") {
|
||||||
build-string "(-" $subargs.s ")"
|
build-string "(-" $subargs.s ")"
|
||||||
}) (if ('d' in ($subargs | columns)) && ($subargs.d != "") {
|
}) (if ('d' in ($subargs | columns)) && ($subargs.d != "") {
|
||||||
build-string "\t\t\t\t\t# " $subargs.d
|
build-string "\t\t\t\t\t# " $subargs.d
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,10 +7,10 @@ def parse-help [] {
|
||||||
}
|
}
|
||||||
|
|
||||||
# takes a table of parsed help commands in format [short? long format? description]
|
# takes a table of parsed help commands in format [short? long format? description]
|
||||||
def make-completion [command-name: string] {
|
def make-completion [command_name: string] {
|
||||||
build-string "extern \"" $command-name "\" [\n" ($in | each { |it|
|
build-string "extern \"" $command_name "\" [\n" ($in | each { |it|
|
||||||
build-string "\t--" $it.long (if ($it.short | empty?) == false {
|
build-string "\t--" $it.long (if ($it.short | empty?) == false {
|
||||||
build-string "(-" $it.short ")"
|
build-string "(-" $it.short ")"
|
||||||
}) (if ($it.description | empty?) == false {
|
}) (if ($it.description | empty?) == false {
|
||||||
build-string "\t\t# " $it.description
|
build-string "\t\t# " $it.description
|
||||||
})
|
})
|
||||||
|
@ -33,16 +33,16 @@ module tests {
|
||||||
['' config 'KEY=VALUE' 'Override a configuration value (unstable)']
|
['' config 'KEY=VALUE' 'Override a configuration value (unstable)']
|
||||||
[h help '' 'Print help information']
|
[h help '' 'Print help information']
|
||||||
]
|
]
|
||||||
|
|
||||||
let result = (cargo --help | parse-help)
|
let result = (cargo --help | parse-help)
|
||||||
|
|
||||||
if $result == $expect {
|
if $result == $expect {
|
||||||
"passed"
|
"passed"
|
||||||
} else {
|
} else {
|
||||||
$result
|
$result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def test-nu [] {
|
def test-nu [] {
|
||||||
let expect = [
|
let expect = [
|
||||||
[short long format description];
|
[short long format description];
|
||||||
|
@ -59,16 +59,16 @@ module tests {
|
||||||
['' log-level 'String' 'log level for performance logs']
|
['' log-level 'String' 'log level for performance logs']
|
||||||
['t' threads 'Int' 'threads to use for parallel commands']
|
['t' threads 'Int' 'threads to use for parallel commands']
|
||||||
]
|
]
|
||||||
|
|
||||||
let result = (nu --help | parse-help)
|
let result = (nu --help | parse-help)
|
||||||
|
|
||||||
if $result == $expect {
|
if $result == $expect {
|
||||||
"passed"
|
"passed"
|
||||||
} else {
|
} else {
|
||||||
$result
|
$result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export def run-tests [] {
|
export def run-tests [] {
|
||||||
[
|
[
|
||||||
[test result];
|
[test result];
|
||||||
|
|
|
@ -266,7 +266,7 @@ export extern "yarn npm logout" [
|
||||||
export extern "yarn npm publish" [
|
export extern "yarn npm publish" [
|
||||||
--access: string # The access level of the published package (public or restricted)
|
--access: string # The access level of the published package (public or restricted)
|
||||||
--tag: string # The tag on the registry that the package should be attached to
|
--tag: string # The tag on the registry that the package should be attached to
|
||||||
--tolerate-republish # Warn and exit when republishing an already existing version of a package
|
--tolerate-republish # Warn and exit when republishing an already existing version of a package
|
||||||
--opt: string # The OTP token to use with the command
|
--opt: string # The OTP token to use with the command
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ export extern "yarn plugin" []
|
||||||
export extern "yarn plugin import from sources" [
|
export extern "yarn plugin import from sources" [
|
||||||
--path: string # The path where the repository should be cloned to
|
--path: string # The path where the repository should be cloned to
|
||||||
--repository: string # The repository that should be cloned
|
--repository: string # The repository that should be cloned
|
||||||
--branch: string # The branch of the repository that should be cloned
|
--branch: string # The branch of the repository that should be cloned
|
||||||
--no-minify # Build a plugin for development (debugging) - non-minified and non-mangled
|
--no-minify # Build a plugin for development (debugging) - non-minified and non-mangled
|
||||||
--force(-f) # Always clone the repository instead of trying to fetch the latest commits
|
--force(-f) # Always clone the repository instead of trying to fetch the latest commits
|
||||||
plugin: string
|
plugin: string
|
||||||
|
@ -419,7 +419,7 @@ export extern "yarn set resolution" [
|
||||||
export extern "yarn set version from sources" [
|
export extern "yarn set version from sources" [
|
||||||
--path: string # The path where the repository should be cloned to
|
--path: string # The path where the repository should be cloned to
|
||||||
--repository: string # The repository that should be cloned
|
--repository: string # The repository that should be cloned
|
||||||
--branch: string # The branch of the repository that should be cloned
|
--branch: string # The branch of the repository that should be cloned
|
||||||
--no-minify # Build a plugin for development (debugging) - non-minified and non-mangled
|
--no-minify # Build a plugin for development (debugging) - non-minified and non-mangled
|
||||||
--force(-f) # Always clone the repository instead of trying to fetch the latest commits
|
--force(-f) # Always clone the repository instead of trying to fetch the latest commits
|
||||||
--skip-plugins # Skip updating the contrib plugins
|
--skip-plugins # Skip updating the contrib plugins
|
||||||
|
@ -506,7 +506,7 @@ def "nu-complete yarn why" [] {
|
||||||
|
|
||||||
# Display the reason why a package is needed.
|
# Display the reason why a package is needed.
|
||||||
export extern "yarn why" [
|
export extern "yarn why" [
|
||||||
--recursive(-R) # List, for each workspace, what are all the paths that lead to the dependency
|
--recursive(-R) # List, for each workspace, what are all the paths that lead to the dependency
|
||||||
--json # Format the output as an NDJSON stream
|
--json # Format the output as an NDJSON stream
|
||||||
--peers # Also print the peer dependencies that match the specified name
|
--peers # Also print the peer dependencies that match the specified name
|
||||||
package: string@"nu-complete yarn why"
|
package: string@"nu-complete yarn why"
|
||||||
|
|
|
@ -30,7 +30,7 @@ export env SHOW_USR { "true" }
|
||||||
# prompt
|
# prompt
|
||||||
export env PROMPT_COMMAND { "build-prompt" }
|
export env PROMPT_COMMAND { "build-prompt" }
|
||||||
export def build-prompt [] {
|
export def build-prompt [] {
|
||||||
let usr-str = (if $env.SHOW_USR == "true" {
|
let usr_str = (if $env.SHOW_USR == "true" {
|
||||||
[
|
[
|
||||||
$env.USER
|
$env.USER
|
||||||
'@'
|
'@'
|
||||||
|
@ -41,11 +41,11 @@ export def build-prompt [] {
|
||||||
''
|
''
|
||||||
})
|
})
|
||||||
|
|
||||||
let pwd-str = (if (pwd | str starts-with $env.HOME).0 {
|
let pwd_str = (if (pwd | str starts-with $env.HOME).0 {
|
||||||
(pwd | str replace $env.HOME '~' | str trim).0
|
(pwd | str replace $env.HOME '~' | str trim).0
|
||||||
} else {
|
} else {
|
||||||
pwd
|
pwd
|
||||||
})
|
})
|
||||||
|
|
||||||
[ $usr-str $pwd-str ' ' ] | str collect
|
[ $usr_str $pwd_str ' ' ] | str collect
|
||||||
}
|
}
|
||||||
|
|
24
fehbg.nu
24
fehbg.nu
|
@ -25,16 +25,16 @@
|
||||||
# * imagemagick
|
# * imagemagick
|
||||||
|
|
||||||
# Path definitions
|
# Path definitions
|
||||||
let img-dir = $env.WALLPAPER_DIR
|
let img_dir = $env.WALLPAPER_DIR
|
||||||
let tmp-image = ([ $env.TMP_DIR "wallpaper.jpg" ] | path join)
|
let tmp_image = ([ $env.TMP_DIR "wallpaper.jpg" ] | path join)
|
||||||
|
|
||||||
# Monitor resolution
|
# Monitor resolution
|
||||||
let resolution-y = 1440
|
let resolution_y = 1440
|
||||||
let res-str = ($"x($resolution-y)")
|
let res_str = ($"x($resolution-y)")
|
||||||
|
|
||||||
# Position of the caption
|
# Position of the caption
|
||||||
let pos-x = 5
|
let pos_x = 5
|
||||||
let pos-y = (0.995 * $resolution-y | into int)
|
let pos_y = (0.995 * $resolution_y | into int)
|
||||||
|
|
||||||
# Select random item from input
|
# Select random item from input
|
||||||
def select-random [] {
|
def select-random [] {
|
||||||
|
@ -50,20 +50,20 @@ def list-images [dir: path] {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set the caption text (just filename for now)
|
# Set the caption text (just filename for now)
|
||||||
def caption [img-f: string] {
|
def caption [img_f: string] {
|
||||||
echo $img-f
|
echo $img_f
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build the argument for the '-draw' command of the 'convert' utility
|
# Build the argument for the '-draw' command of the 'convert' utility
|
||||||
def draw-str [img-f: string] {
|
def draw-str [img_f: string] {
|
||||||
$"text ($pos-x), ($pos-y) (char dq)(caption $img-f)(char dq) "
|
$"text ($pos_x), ($pos_y) (char dq)(caption $img_f)(char dq) "
|
||||||
}
|
}
|
||||||
|
|
||||||
# Select random image
|
# Select random image
|
||||||
let img-name = (list-images $img-dir | select-random | get name) # TODO: change the env var to $img-dir
|
let img_name = (list-images $img_dir | select-random | get name) # TODO: change the env var to $img-dir
|
||||||
|
|
||||||
# Resize the image to the monitor height, draw the caption and save it
|
# Resize the image to the monitor height, draw the caption and save it
|
||||||
convert -resize $res-str -pointsize 15 -fill 'rgb(255,200,150)' -draw (draw-str $img-name) $img-name $tmp-image
|
convert -resize $res_str -pointsize 15 -fill 'rgb(255,200,150)' -draw (draw-str $img_name) $img_name $tmp_image
|
||||||
|
|
||||||
# Set the created image as a background
|
# Set the created image as a background
|
||||||
feh --no-fehbg --bg-max $tmp-image
|
feh --no-fehbg --bg-max $tmp-image
|
||||||
|
|
|
@ -17,8 +17,8 @@ def main [
|
||||||
--branch: string # branch to scan
|
--branch: string # branch to scan
|
||||||
] {
|
] {
|
||||||
# /projects endpoint can return up to $page_size items which is why we need multiple calls to retrieve full list
|
# /projects endpoint can return up to $page_size items which is why we need multiple calls to retrieve full list
|
||||||
let num-of-pages = ((call-gitlab --query 'page=1&per_page=1&order_by=id&simple=true'|get id.0|into int) / $page_size|math round)
|
let num_of_pages = ((call-gitlab --query 'page=1&per_page=1&order_by=id&simple=true'|get id.0|into int) / $page_size|math round)
|
||||||
seq 1 $num-of-pages|par-each {|page|
|
seq 1 $num_of_pages|par-each {|page|
|
||||||
call-gitlab --query $"page=($page)&per_page=($page_size)"|select name id
|
call-gitlab --query $"page=($page)&per_page=($page_size)"|select name id
|
||||||
}
|
}
|
||||||
|flatten
|
|flatten
|
||||||
|
|
|
@ -34,7 +34,7 @@ def get-url [
|
||||||
if 'ip' in ($host|columns) {
|
if 'ip' in ($host|columns) {
|
||||||
echo $"ssh://($host.username)@($host.ip):($host.port)"
|
echo $"ssh://($host.username)@($host.ip):($host.port)"
|
||||||
} else {
|
} else {
|
||||||
echo $"ssh://($host.username)@($host.name).($host.domain):($host.port)"
|
echo $"ssh://($host.username)@($host.name).($host.domain):($host.port)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,15 +58,15 @@ export def ssh [
|
||||||
# Connect over ssh to one of predefined hosts, execute nushell script with arguments passed from the host
|
# Connect over ssh to one of predefined hosts, execute nushell script with arguments passed from the host
|
||||||
export def "ssh script" [
|
export def "ssh script" [
|
||||||
hostname: string@"nu-complete nu" # name of the host you want to connect to
|
hostname: string@"nu-complete nu" # name of the host you want to connect to
|
||||||
script: string@"nu-complete scripts" # name of the script
|
script: string@"nu-complete scripts" # name of the script
|
||||||
...args # arguments you wish to pass to the script in key=value format
|
...args # arguments you wish to pass to the script in key=value format
|
||||||
] {
|
] {
|
||||||
let span = (metadata $script).span
|
let span = (metadata $script).span
|
||||||
if $script in ($nu.scope.commands|where is_custom|get command) {
|
if $script in ($nu.scope.commands|where is_custom|get command) {
|
||||||
|
|
||||||
let host = (hosts|where name == $hostname|get 0)
|
let host = (hosts|where name == $hostname|get 0)
|
||||||
let full-command = (build-string (view-source $script) '; ' $script ' ' ($args|str collect ' ') '|to json -r')
|
let full_command = (build-string (view-source $script) '; ' $script ' ' ($args|str collect ' ') '|to json -r')
|
||||||
^ssh (get-url $host) ($full-command)|from json
|
^ssh (get-url $host) ($full_command)|from json
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error make {
|
error make {
|
||||||
|
|
|
@ -471,6 +471,6 @@ module panache-plumbing {
|
||||||
# An opinionated Git prompt for Nushell, styled after posh-git
|
# An opinionated Git prompt for Nushell, styled after posh-git
|
||||||
def panache-git [] {
|
def panache-git [] {
|
||||||
use panache-plumbing *
|
use panache-plumbing *
|
||||||
let prompt = ($'(panache-git dir) (panache-git styled)' | str trim)
|
let prompt = ($'(panache_git dir) (panache-git styled)' | str trim)
|
||||||
$'($prompt)> '
|
$'($prompt)> '
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue