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

update scripts to support str replace (#200)

This commit is contained in:
Darren Schroeder 2022-04-07 08:45:04 -05:00 committed by GitHub
parent 577ad93638
commit e6d8d2704e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 44 additions and 44 deletions

View file

@ -145,6 +145,6 @@ def apply-base16-mustache [template: string] {
reduce -f $template { reduce -f $template {
let subs = $"\{\{($it.item.name)-hex\}\}" # regex let subs = $"\{\{($it.item.name)-hex\}\}" # regex
let color = $it.item.color let color = $it.item.color
$it.acc | str find-replace -a $subs $color $it.acc | str replace -a $subs $color
} }
} }

View file

@ -2,7 +2,7 @@
def dict [...word #word(s) to query the dictionary API but they have to make sense together like "martial law", not "cats dogs" def dict [...word #word(s) to query the dictionary API but they have to make sense together like "martial law", not "cats dogs"
] { ] {
let query = ($word | str collect %20) let query = ($word | str collect %20)
let link = (build-string 'https://api.dictionaryapi.dev/api/v2/entries/en/' ($query|str find-replace ' ' '%20')) let link = (build-string 'https://api.dictionaryapi.dev/api/v2/entries/en/' ($query|str replace ' ' '%20'))
let output = (fetch $link | let output = (fetch $link |
rename word) rename word)
let w = ($output.word | first) let w = ($output.word | first)

View file

@ -1,5 +1,5 @@
def "nu-complete git branches" [] { def "nu-complete git branches" [] {
^git branch | lines | each { |line| $line | str find-replace '\* ' "" | str trim } ^git branch | lines | each { |line| $line | str replace '\* ' "" | str trim }
} }
def "nu-complete git remotes" [] { def "nu-complete git remotes" [] {

View file

@ -1,5 +1,5 @@
def "nu-complete make" [] { def "nu-complete make" [] {
open ./Makefile|lines|find ':'|where ($it|str starts-with '.') == false|split column ' '|get column1|find ':'|str find-replace ':' '' open ./Makefile|lines|find ':'|where ($it|str starts-with '.') == false|split column ' '|get column1|find ':'|str replace ':' ''
} }
def "nu-complete make jobs" [] { def "nu-complete make jobs" [] {
@ -30,27 +30,27 @@ def "nu-complete make" [] {
--load-average(-l): int@"nu-complete make jobs" # Don't start multiple jobs unless load is below N. --load-average(-l): int@"nu-complete make jobs" # Don't start multiple jobs unless load is below N.
--check-symlink-times(-L) # Use the latest mtime between symlinks and target. --check-symlink-times(-L) # Use the latest mtime between symlinks and target.
--just-print(-n) # Don't actually run any recipe; just print them. --just-print(-n) # Don't actually run any recipe; just print them.
--dry-run --dry-run
--recon --recon
--assume-old: string@"nu-complete make files" # Consider FILE to be very old and don't remake it. --assume-old: string@"nu-complete make files" # Consider FILE to be very old and don't remake it.
--old-file(-o): string@"nu-complete make files" --old-file(-o): string@"nu-complete make files"
--output-sync(-O) # Synchronize output of parallel jobs by TYPE. --output-sync(-O) # Synchronize output of parallel jobs by TYPE.
--print-data-base(-p) # Print make's internal database. --print-data-base(-p) # Print make's internal database.
--question(-q) # Run no recipe; exit status says if up to date. --question(-q) # Run no recipe; exit status says if up to date.
--no-builtin-rules(-r) # Disable the built-in implicit rules. --no-builtin-rules(-r) # Disable the built-in implicit rules.
--no-builtin-variables(-R) # Disable the built-in variable settings. --no-builtin-variables(-R) # Disable the built-in variable settings.
--silent(-s) # Don't echo recipes. --silent(-s) # Don't echo recipes.
--quiet --quiet
--no-silent # Echo recipes (disable --silent mode). --no-silent # Echo recipes (disable --silent mode).
--stop(-S) # Turns off -k. --stop(-S) # Turns off -k.
--no-keep-going --no-keep-going
--touch(-t) # Touch targets instead of remaking them. --touch(-t) # Touch targets instead of remaking them.
--trace # Print tracing information. --trace # Print tracing information.
--version(-v) # Print the version number of make and exit. --version(-v) # Print the version number of make and exit.
--print-directory(-w) # Print the current directory. --print-directory(-w) # Print the current directory.
--no-print-directory # Turn off -w, even if it was turned on implicitly. --no-print-directory # Turn off -w, even if it was turned on implicitly.
--what-if(-W): string@"nu-complete files" # Consider FILE to be infinitely new. --what-if(-W): string@"nu-complete files" # Consider FILE to be infinitely new.
--new-file: string@"nu-complete files" --new-file: string@"nu-complete files"
--assume-new: string@"nu-complete files" --assume-new: string@"nu-complete files"
--warn-undefined-variables # Warn when an undefined variable is referenced. --warn-undefined-variables # Warn when an undefined variable is referenced.
] ]

View file

@ -8,7 +8,7 @@ def "nu-complete npm" [] {
|str trim |str trim
|split column -c ' ' |split column -c ' '
|get column4 |get column4
|str find-replace '"' '' |str replace '"' ''
} }
def "nu-complete npm run" [] { def "nu-complete npm run" [] {

View file

@ -391,19 +391,19 @@ def "nu-complete winget uninstall package id" [] {
} }
def "nu-complete winget uninstall package name" [] { def "nu-complete winget uninstall package name" [] {
winget list | get name | str trim | str find-replace "…" "..." winget list | get name | str trim | str replace "…" "..."
} }
def "nu-complete winget install name" [] { def "nu-complete winget install name" [] {
let path = ($env.TMP | path join winget-packages.csv) let path = ($env.TMP | path join winget-packages.csv)
let completions = if ($path | path exists) && (ls $path | first | get modified | ((date now) - $in) < 1day) { let completions = if ($path | path exists) && (ls $path | first | get modified | ((date now) - $in) < 1day) {
open $path | get name | each { |it| $"(char dq)($it)(char dq)" } | str find-replace "…" "" open $path | get name | each { |it| $"(char dq)($it)(char dq)" } | str replace "…" ""
} else { } else {
# Chinese characters break parsing, filter broken entries with `where source == winget` # Chinese characters break parsing, filter broken entries with `where source == winget`
let data = (winget search | where source == winget | select name id) let data = (winget search | where source == winget | select name id)
$data | save $path | ignore $data | save $path | ignore
$data | get name | each { |it| $"(char dq)($it)(char dq)" } | str find-replace "…" "" $data | get name | each { |it| $"(char dq)($it)(char dq)" } | str replace "…" ""
} }
{ {
completions: $completions completions: $completions
@ -418,12 +418,12 @@ def "nu-complete winget install id" [] {
let path = ($env.TMP | path join winget-packages.csv) let path = ($env.TMP | path join winget-packages.csv)
if ($path | path exists) && (ls $path | first | get modified | ((date now) - $in) < 1day) { if ($path | path exists) && (ls $path | first | get modified | ((date now) - $in) < 1day) {
open $path | get id | str find-replace "…" "" open $path | get id | str replace "…" ""
} else { } else {
# Chinese characters break parsing, filter broken entries with `where source == winget` # Chinese characters break parsing, filter broken entries with `where source == winget`
let data = (winget search | where source == winget | select name id) let data = (winget search | where source == winget | select name id)
$data | save $path | ignore $data | save $path | ignore
$data | get id | str find-replace "…" "" $data | get id | str replace "…" ""
} }
} }

View file

@ -42,7 +42,7 @@ 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 find-replace $env.HOME '~' | str trim).0 (pwd | str replace $env.HOME '~' | str trim).0
} else { } else {
pwd pwd
}) })

View file

@ -9,14 +9,14 @@ for $markdown in $markdown_files {
let $first_line = ($content_lines | first | str trim) let $first_line = ($content_lines | first | str trim)
if $first_line == "---" { if $first_line == "---" {
let $header = ($content_lines let $header = ($content_lines
| skip 1 | skip 1
| keep while {|x| ($x | str trim) != "---"} | keep while {|x| ($x | str trim) != "---"}
| str collect "\n" | str collect "\n"
| from yaml) | from yaml)
let $post = ($content_lines let $post = ($content_lines
| skip 1 | skip 1
| skip while {|x| ($x | str trim) != "---"} | skip while {|x| ($x | str trim) != "---"}
| skip 1) | skip 1)
@ -25,22 +25,22 @@ for $markdown in $markdown_files {
let $html_post = ($post let $html_post = ($post
| each {|line| | each {|line|
if ($line | str starts-with "#") { if ($line | str starts-with "#") {
let $line = ($line | str find-replace "^# (.*)$" "<h1>$1</h1>") let $line = ($line | str replace "^# (.*)$" "<h1>$1</h1>")
let $line = ($line | str find-replace "^## (.*)$" "<h2>$1</h2>") let $line = ($line | str replace "^## (.*)$" "<h2>$1</h2>")
let $line = ($line | str find-replace "^### (.*)$" "<h3>$1</h3>") let $line = ($line | str replace "^### (.*)$" "<h3>$1</h3>")
$line $line
} else if $line != "" { } else if $line != "" {
# Otherwise, it's a paragraph # Otherwise, it's a paragraph
# Convert images # Convert images
let $line = ($line | str find-replace --all '!\[(.+)\]\((.+)\)' '<img src="$2" alt="$1"/>') let $line = ($line | str replace --all '!\[(.+)\]\((.+)\)' '<img src="$2" alt="$1"/>')
let $line = ($line | str find-replace --all 'src="../assets' 'src="assets') let $line = ($line | str replace --all 'src="../assets' 'src="assets')
# Convert links # Convert links
let $line = ($line | str find-replace --all '\[(.+?)\]\((.+?)\)' '<a href="$2">$1</a>') let $line = ($line | str replace --all '\[(.+?)\]\((.+?)\)' '<a href="$2">$1</a>')
# Convert code # Convert code
let $line = ($line | str find-replace --all '`(.+?)`' '<code>$1</code>') let $line = ($line | str replace --all '`(.+?)`' '<code>$1</code>')
$"<p>($line)</p>" $"<p>($line)</p>"
} }
}) })
@ -85,12 +85,12 @@ for $markdown in $markdown_files {
<body> <body>
($html_post) ($html_post)
</body> </body>
</html>" </html>"
# print $html_post # print $html_post
let $name = ($markdown.name | path parse | update extension "html" | path join) let $name = ($markdown.name | path parse | update extension "html" | path join)
$html_post | save --raw $name $html_post | save --raw $name
} }
} }

View file

@ -20,14 +20,14 @@ def home_abbrev [os] {
let is_home_in_path = ($env.PWD | str starts-with $nu.home-path) let is_home_in_path = ($env.PWD | str starts-with $nu.home-path)
if ($is_home_in_path == true) { if ($is_home_in_path == true) {
if ($os == "Windows") { if ($os == "Windows") {
let home = ($nu.home-path | str find-replace -a '\\' '/') let home = ($nu.home-path | str replace -a '\\' '/')
let pwd = ($env.PWD | str find-replace -a '\\' '/') let pwd = ($env.PWD | str replace -a '\\' '/')
$pwd | str find-replace $home '~' $pwd | str replace $home '~'
} else { } else {
$env.PWD | str find-replace $nu.home-path '~' $env.PWD | str replace $nu.home-path '~'
} }
} else { } else {
$env.PWD | str find-replace -a '\\' '/' $env.PWD | str replace -a '\\' '/'
} }
} }

View file

@ -20,14 +20,14 @@ def home_abbrev [os_name] {
let is_home_in_path = ($env.PWD | str starts-with $nu.home-path) let is_home_in_path = ($env.PWD | str starts-with $nu.home-path)
if $is_home_in_path { if $is_home_in_path {
if ($os_name == "Windows") { if ($os_name == "Windows") {
let home = ($nu.home-path | str find-replace -a '\\' '/') let home = ($nu.home-path | str replace -a '\\' '/')
let pwd = ($env.PWD | str find-replace -a '\\' '/') let pwd = ($env.PWD | str replace -a '\\' '/')
$pwd | str find-replace $home '~' $pwd | str replace $home '~'
} else { } else {
$env.PWD | str find-replace $nu.home-path '~' $env.PWD | str replace $nu.home-path '~'
} }
} else { } else {
$env.PWD | str find-replace -a '\\' '/' $env.PWD | str replace -a '\\' '/'
} }
} }
@ -523,7 +523,7 @@ export def git_prompt [] {
# so you might want to play around with these settings a bit # so you might want to play around with these settings a bit
let abbrev = ((path_abbrev_if_needed (home_abbrev $os.name) 30) | ansi strip) let abbrev = ((path_abbrev_if_needed (home_abbrev $os.name) 30) | ansi strip)
# $"\u001b]0;($abbrev)" # $"\u001b]0;($abbrev)"
# note that this isn't ending properly with a bel or a st, that's # note that this isn't ending properly with a bel or a st, that's
# because it makes the string echo to the screen as an empty line # because it makes the string echo to the screen as an empty line
$"(ansi osc)2;($abbrev)" $"(ansi osc)2;($abbrev)"