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.
|
||||
# #base0f-hex
|
||||
# ```
|
||||
export def build-nu-config [base-txt: path] {
|
||||
let b16 = (from-file $base-txt)
|
||||
export def build-nu-config [base_txt: path] {
|
||||
let b16 = (from-file $base_txt)
|
||||
|
||||
{
|
||||
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
|
||||
#
|
||||
# It injects the base16 colors into the Alacritty config template
|
||||
export def build-alacritty-config [base-txt: path] {
|
||||
let base16 = (from-file-table $base-txt)
|
||||
export def build-alacritty-config [base_txt: path] {
|
||||
let base16 = (from-file-table $base_txt)
|
||||
let template = (
|
||||
open "~/.config/nushell/alacritty_colors.mustache" |
|
||||
decode utf-8
|
||||
|
@ -73,13 +73,13 @@ export def build-alacritty-config [base-txt: path] {
|
|||
}
|
||||
|
||||
# Generate LS_COLORS value
|
||||
export def build-lscolors [base-txt: path] {
|
||||
export def build-lscolors [base_txt: path] {
|
||||
# TODO
|
||||
}
|
||||
|
||||
# Show the current base16 colors
|
||||
export def show [base-txt: path] {
|
||||
from-file $base-txt | each { |it|
|
||||
export def show [base_txt: path] {
|
||||
from-file $base_txt | each { |it|
|
||||
{ $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
|
||||
export def from-file [base-txt: path] {
|
||||
let base16-lines = (open $base-txt | lines | where ($it | str length) > 0)
|
||||
export def from-file [base_txt: path] {
|
||||
let base16_lines = (open $base_txt | lines | where ($it | str length) > 0)
|
||||
|
||||
{
|
||||
base00 : $base16-lines.0 # Default Background
|
||||
base01 : $base16-lines.1 # Lighter Background (Used for status bars, line number and folding marks)
|
||||
base02 : $base16-lines.2 # Selection Background
|
||||
base03 : $base16-lines.3 # Comments, Invisibles, Line Highlighting
|
||||
base04 : $base16-lines.4 # Dark Foreground (Used for status bars)
|
||||
base05 : $base16-lines.5 # Default Foreground, Caret, Delimiters, Operators
|
||||
base06 : $base16-lines.6 # Light Foreground (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
|
||||
base09 : $base16-lines.9 # Integers, Boolean, Constants, XML Attributes, Markup Link Url
|
||||
base0a : $base16-lines.10 # Classes, Markup Bold, Search Text Background
|
||||
base0b : $base16-lines.11 # Strings, Inherited Class, Markup Code, Diff Inserted
|
||||
base0c : $base16-lines.12 # Support, Regular Expressions, Escape Characters, Markup Quotes
|
||||
base0d : $base16-lines.13 # Functions, Methods, Attribute IDs, Headings
|
||||
base0e : $base16-lines.14 # Keywords, Storage, Selector, Markup Italic, Diff Changed
|
||||
base0f : $base16-lines.15 # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
|
||||
base00 : $base16_lines.0 # Default Background
|
||||
base01 : $base16_lines.1 # Lighter Background (Used for status bars, line number and folding marks)
|
||||
base02 : $base16_lines.2 # Selection Background
|
||||
base03 : $base16_lines.3 # Comments, Invisibles, Line Highlighting
|
||||
base04 : $base16_lines.4 # Dark Foreground (Used for status bars)
|
||||
base05 : $base16_lines.5 # Default Foreground, Caret, Delimiters, Operators
|
||||
base06 : $base16_lines.6 # Light Foreground (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
|
||||
base09 : $base16_lines.9 # Integers, Boolean, Constants, XML Attributes, Markup Link Url
|
||||
base0a : $base16_lines.10 # Classes, Markup Bold, Search Text Background
|
||||
base0b : $base16_lines.11 # Strings, Inherited Class, Markup Code, Diff Inserted
|
||||
base0c : $base16_lines.12 # Support, Regular Expressions, Escape Characters, Markup Quotes
|
||||
base0d : $base16_lines.13 # Functions, Methods, Attribute IDs, Headings
|
||||
base0e : $base16_lines.14 # Keywords, Storage, Selector, Markup Italic, Diff Changed
|
||||
base0f : $base16_lines.15 # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
|
||||
}
|
||||
}
|
||||
|
||||
# Get base16 as a table from an input file
|
||||
export def from-file-table [base-txt: path] {
|
||||
let base16-lines = (open $base-txt | lines | where ($it | str length) > 0)
|
||||
export def from-file-table [base_txt: path] {
|
||||
let base16_lines = (open $base_txt | lines | where ($it | str length) > 0)
|
||||
|
||||
[
|
||||
[ name color ];
|
||||
[ base00 $base16-lines.0 ] # Default Background
|
||||
[ base01 $base16-lines.1 ] # Lighter Background (Used for status bars, line number and folding marks)
|
||||
[ base02 $base16-lines.2 ] # Selection Background
|
||||
[ base03 $base16-lines.3 ] # Comments, Invisibles, Line Highlighting
|
||||
[ base04 $base16-lines.4 ] # Dark Foreground (Used for status bars)
|
||||
[ base05 $base16-lines.5 ] # Default Foreground, Caret, Delimiters, Operators
|
||||
[ base06 $base16-lines.6 ] # Light Foreground (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
|
||||
[ base09 $base16-lines.9 ] # Integers, Boolean, Constants, XML Attributes, Markup Link Url
|
||||
[ base0a $base16-lines.10 ] # Classes, Markup Bold, Search Text Background
|
||||
[ base0b $base16-lines.11 ] # Strings, Inherited Class, Markup Code, Diff Inserted
|
||||
[ base0c $base16-lines.12 ] # Support, Regular Expressions, Escape Characters, Markup Quotes
|
||||
[ base0d $base16-lines.13 ] # Functions, Methods, Attribute IDs, Headings
|
||||
[ base0e $base16-lines.14 ] # Keywords, Storage, Selector, Markup Italic, Diff Changed
|
||||
[ base0f $base16-lines.15 ] # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
|
||||
[ base00 $base16_lines.0 ] # Default Background
|
||||
[ base01 $base16_lines.1 ] # Lighter Background (Used for status bars, line number and folding marks)
|
||||
[ base02 $base16_lines.2 ] # Selection Background
|
||||
[ base03 $base16_lines.3 ] # Comments, Invisibles, Line Highlighting
|
||||
[ base04 $base16_lines.4 ] # Dark Foreground (Used for status bars)
|
||||
[ base05 $base16_lines.5 ] # Default Foreground, Caret, Delimiters, Operators
|
||||
[ base06 $base16_lines.6 ] # Light Foreground (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
|
||||
[ base09 $base16_lines.9 ] # Integers, Boolean, Constants, XML Attributes, Markup Link Url
|
||||
[ base0a $base16_lines.10 ] # Classes, Markup Bold, Search Text Background
|
||||
[ base0b $base16_lines.11 ] # Strings, Inherited Class, Markup Code, Diff Inserted
|
||||
[ base0c $base16_lines.12 ] # Support, Regular Expressions, Escape Characters, Markup Quotes
|
||||
[ base0d $base16_lines.13 ] # Functions, Methods, Attribute IDs, Headings
|
||||
[ base0e $base16_lines.14 ] # Keywords, Storage, Selector, Markup Italic, Diff Changed
|
||||
[ 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
|
||||
}
|
||||
|
||||
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 end = (($end - $start) / (($blocks-per-line) * $block-length))
|
||||
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 end = (($end - $start) / (($blocks_per_line) * $block_length))
|
||||
for i in 0..<$end {
|
||||
for row in 0..<$block-rows {
|
||||
for block in 0..<$blocks-per-line {
|
||||
print_run ($start + $block * $block-length + $row * $block-cols + $i * $block-length * $blocks-per-line) $block-cols
|
||||
for row in 0..<$block_rows {
|
||||
for block in 0..<$blocks_per_line {
|
||||
print_run ($start + $block * $block_length + $row * $block_cols + $i * $block_length * $blocks_per_line) $block_cols
|
||||
} | append (char nl) | 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
|
||||
def build-completion [fish-file: path, nu-file: path] {
|
||||
open $fish-file | parse-fish | make-commands-completion | str collect "\n\n" | save $nu-file
|
||||
def build-completion [fish_file: path, nu_file: path] {
|
||||
open $fish_file | parse-fish | make-commands-completion | str collect "\n\n" | save $nu_file
|
||||
}
|
||||
|
||||
# parse a .fish file based on autogenerated complete syntax
|
||||
|
|
|
@ -7,8 +7,8 @@ def parse-help [] {
|
|||
}
|
||||
|
||||
# takes a table of parsed help commands in format [short? long format? description]
|
||||
def make-completion [command-name: string] {
|
||||
build-string "extern \"" $command-name "\" [\n" ($in | each { |it|
|
||||
def make-completion [command_name: string] {
|
||||
build-string "extern \"" $command_name "\" [\n" ($in | each { |it|
|
||||
build-string "\t--" $it.long (if ($it.short | empty?) == false {
|
||||
build-string "(-" $it.short ")"
|
||||
}) (if ($it.description | empty?) == false {
|
||||
|
|
|
@ -30,7 +30,7 @@ export env SHOW_USR { "true" }
|
|||
# prompt
|
||||
export env PROMPT_COMMAND { "build-prompt" }
|
||||
export def build-prompt [] {
|
||||
let usr-str = (if $env.SHOW_USR == "true" {
|
||||
let usr_str = (if $env.SHOW_USR == "true" {
|
||||
[
|
||||
$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
|
||||
} else {
|
||||
pwd
|
||||
})
|
||||
|
||||
[ $usr-str $pwd-str ' ' ] | str collect
|
||||
[ $usr_str $pwd_str ' ' ] | str collect
|
||||
}
|
||||
|
|
24
fehbg.nu
24
fehbg.nu
|
@ -25,16 +25,16 @@
|
|||
# * imagemagick
|
||||
|
||||
# Path definitions
|
||||
let img-dir = $env.WALLPAPER_DIR
|
||||
let tmp-image = ([ $env.TMP_DIR "wallpaper.jpg" ] | path join)
|
||||
let img_dir = $env.WALLPAPER_DIR
|
||||
let tmp_image = ([ $env.TMP_DIR "wallpaper.jpg" ] | path join)
|
||||
|
||||
# Monitor resolution
|
||||
let resolution-y = 1440
|
||||
let res-str = ($"x($resolution-y)")
|
||||
let resolution_y = 1440
|
||||
let res_str = ($"x($resolution-y)")
|
||||
|
||||
# Position of the caption
|
||||
let pos-x = 5
|
||||
let pos-y = (0.995 * $resolution-y | into int)
|
||||
let pos_x = 5
|
||||
let pos_y = (0.995 * $resolution_y | into int)
|
||||
|
||||
# Select random item from input
|
||||
def select-random [] {
|
||||
|
@ -50,20 +50,20 @@ def list-images [dir: path] {
|
|||
}
|
||||
|
||||
# Set the caption text (just filename for now)
|
||||
def caption [img-f: string] {
|
||||
echo $img-f
|
||||
def caption [img_f: string] {
|
||||
echo $img_f
|
||||
}
|
||||
|
||||
# Build the argument for the '-draw' command of the 'convert' utility
|
||||
def draw-str [img-f: string] {
|
||||
$"text ($pos-x), ($pos-y) (char dq)(caption $img-f)(char dq) "
|
||||
def draw-str [img_f: string] {
|
||||
$"text ($pos_x), ($pos_y) (char dq)(caption $img_f)(char dq) "
|
||||
}
|
||||
|
||||
# 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
|
||||
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
|
||||
feh --no-fehbg --bg-max $tmp-image
|
||||
|
|
|
@ -17,8 +17,8 @@ def main [
|
|||
--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
|
||||
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|
|
||||
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|
|
||||
call-gitlab --query $"page=($page)&per_page=($page_size)"|select name id
|
||||
}
|
||||
|flatten
|
||||
|
|
|
@ -65,8 +65,8 @@ export def "ssh script" [
|
|||
if $script in ($nu.scope.commands|where is_custom|get command) {
|
||||
|
||||
let host = (hosts|where name == $hostname|get 0)
|
||||
let full-command = (build-string (view-source $script) '; ' $script ' ' ($args|str collect ' ') '|to json -r')
|
||||
^ssh (get-url $host) ($full-command)|from json
|
||||
let full_command = (build-string (view-source $script) '; ' $script ' ' ($args|str collect ' ') '|to json -r')
|
||||
^ssh (get-url $host) ($full_command)|from json
|
||||
|
||||
} else {
|
||||
error make {
|
||||
|
|
|
@ -471,6 +471,6 @@ module panache-plumbing {
|
|||
# An opinionated Git prompt for Nushell, styled after posh-git
|
||||
def panache-git [] {
|
||||
use panache-plumbing *
|
||||
let prompt = ($'(panache-git dir) (panache-git styled)' | str trim)
|
||||
let prompt = ($'(panache_git dir) (panache-git styled)' | str trim)
|
||||
$'($prompt)> '
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue