From e6d8d2704eeaf3148845dcbbab847f42782dc742 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Thu, 7 Apr 2022 08:45:04 -0500 Subject: [PATCH] update scripts to support `str replace` (#200) --- base16/base16.nu | 2 +- cool-oneliners/dict.nu | 2 +- custom-completions/git/git-completions.nu | 2 +- custom-completions/make/make-completions.nu | 16 +++++----- custom-completions/npm/npm-completions.nu | 2 +- .../winget/winget-completions.nu | 10 +++---- example-config/init.nu | 2 +- fun/website_builder.nu | 30 +++++++++---------- prompt/oh-my-minimal.nu | 10 +++---- prompt/oh-my.nu | 12 ++++---- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/base16/base16.nu b/base16/base16.nu index d092eed..c640635 100644 --- a/base16/base16.nu +++ b/base16/base16.nu @@ -145,6 +145,6 @@ def apply-base16-mustache [template: string] { reduce -f $template { let subs = $"\{\{($it.item.name)-hex\}\}" # regex let color = $it.item.color - $it.acc | str find-replace -a $subs $color + $it.acc | str replace -a $subs $color } } diff --git a/cool-oneliners/dict.nu b/cool-oneliners/dict.nu index d892b7d..b6e3bc9 100644 --- a/cool-oneliners/dict.nu +++ b/cool-oneliners/dict.nu @@ -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" ] { 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 | rename word) let w = ($output.word | first) diff --git a/custom-completions/git/git-completions.nu b/custom-completions/git/git-completions.nu index 0f0586b..cf5d2d1 100644 --- a/custom-completions/git/git-completions.nu +++ b/custom-completions/git/git-completions.nu @@ -1,5 +1,5 @@ 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" [] { diff --git a/custom-completions/make/make-completions.nu b/custom-completions/make/make-completions.nu index 0c2eecf..8bc376f 100644 --- a/custom-completions/make/make-completions.nu +++ b/custom-completions/make/make-completions.nu @@ -1,5 +1,5 @@ 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" [] { @@ -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. --check-symlink-times(-L) # Use the latest mtime between symlinks and target. --just-print(-n) # Don't actually run any recipe; just print them. - --dry-run - --recon + --dry-run + --recon --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. --print-data-base(-p) # Print make's internal database. --question(-q) # Run no recipe; exit status says if up to date. --no-builtin-rules(-r) # Disable the built-in implicit rules. --no-builtin-variables(-R) # Disable the built-in variable settings. --silent(-s) # Don't echo recipes. - --quiet + --quiet --no-silent # Echo recipes (disable --silent mode). --stop(-S) # Turns off -k. - --no-keep-going + --no-keep-going --touch(-t) # Touch targets instead of remaking them. --trace # Print tracing information. --version(-v) # Print the version number of make and exit. --print-directory(-w) # Print the current directory. --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. - --new-file: string@"nu-complete files" - --assume-new: string@"nu-complete files" + --new-file: string@"nu-complete files" + --assume-new: string@"nu-complete files" --warn-undefined-variables # Warn when an undefined variable is referenced. ] diff --git a/custom-completions/npm/npm-completions.nu b/custom-completions/npm/npm-completions.nu index c8c9d9a..5317fef 100644 --- a/custom-completions/npm/npm-completions.nu +++ b/custom-completions/npm/npm-completions.nu @@ -8,7 +8,7 @@ def "nu-complete npm" [] { |str trim |split column -c ' ' |get column4 - |str find-replace '"' '' + |str replace '"' '' } def "nu-complete npm run" [] { diff --git a/custom-completions/winget/winget-completions.nu b/custom-completions/winget/winget-completions.nu index e5450a0..61d20bd 100644 --- a/custom-completions/winget/winget-completions.nu +++ b/custom-completions/winget/winget-completions.nu @@ -391,19 +391,19 @@ def "nu-complete winget uninstall package id" [] { } 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" [] { let path = ($env.TMP | path join winget-packages.csv) 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 { # Chinese characters break parsing, filter broken entries with `where source == winget` let data = (winget search | where source == winget | select name id) $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 @@ -418,12 +418,12 @@ def "nu-complete winget install id" [] { let path = ($env.TMP | path join winget-packages.csv) 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 { # Chinese characters break parsing, filter broken entries with `where source == winget` let data = (winget search | where source == winget | select name id) $data | save $path | ignore - $data | get id | str find-replace "…" "" + $data | get id | str replace "…" "" } } diff --git a/example-config/init.nu b/example-config/init.nu index 6a0018c..e46cebd 100644 --- a/example-config/init.nu +++ b/example-config/init.nu @@ -42,7 +42,7 @@ export def build-prompt [] { }) 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 { pwd }) diff --git a/fun/website_builder.nu b/fun/website_builder.nu index 4615b7b..bc1c93c 100644 --- a/fun/website_builder.nu +++ b/fun/website_builder.nu @@ -9,14 +9,14 @@ for $markdown in $markdown_files { let $first_line = ($content_lines | first | str trim) if $first_line == "---" { - let $header = ($content_lines - | skip 1 + let $header = ($content_lines + | skip 1 | keep while {|x| ($x | str trim) != "---"} | str collect "\n" | from yaml) - let $post = ($content_lines - | skip 1 + let $post = ($content_lines + | skip 1 | skip while {|x| ($x | str trim) != "---"} | skip 1) @@ -25,22 +25,22 @@ for $markdown in $markdown_files { let $html_post = ($post | each {|line| if ($line | str starts-with "#") { - let $line = ($line | str find-replace "^# (.*)$" "
$1
')
+ let $line = ($line | str replace --all '`(.+?)`' '$1
')
$"($line)
" } }) @@ -85,12 +85,12 @@ for $markdown in $markdown_files { ($html_post) -