1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-31 14:17:45 +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 {
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
}
}

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"
] {
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)

View file

@ -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" [] {

View file

@ -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.
]

View file

@ -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" [] {

View file

@ -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 "…" ""
}
}

View file

@ -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
})

View file

@ -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 "^# (.*)$" "<h1>$1</h1>")
let $line = ($line | str find-replace "^## (.*)$" "<h2>$1</h2>")
let $line = ($line | str find-replace "^### (.*)$" "<h3>$1</h3>")
let $line = ($line | str replace "^# (.*)$" "<h1>$1</h1>")
let $line = ($line | str replace "^## (.*)$" "<h2>$1</h2>")
let $line = ($line | str replace "^### (.*)$" "<h3>$1</h3>")
$line
} else if $line != "" {
# Otherwise, it's a paragraph
# Convert images
let $line = ($line | str find-replace --all '!\[(.+)\]\((.+)\)' '<img src="$2" alt="$1"/>')
let $line = ($line | str find-replace --all 'src="../assets' 'src="assets')
let $line = ($line | str replace --all '!\[(.+)\]\((.+)\)' '<img src="$2" alt="$1"/>')
let $line = ($line | str replace --all 'src="../assets' 'src="assets')
# Convert links
let $line = ($line | str find-replace --all '\[(.+?)\]\((.+?)\)' '<a href="$2">$1</a>')
# Convert links
let $line = ($line | str replace --all '\[(.+?)\]\((.+?)\)' '<a href="$2">$1</a>')
# Convert code
let $line = ($line | str find-replace --all '`(.+?)`' '<code>$1</code>')
let $line = ($line | str replace --all '`(.+?)`' '<code>$1</code>')
$"<p>($line)</p>"
}
})
@ -85,12 +85,12 @@ for $markdown in $markdown_files {
<body>
($html_post)
</body>
</html>"
</html>"
# print $html_post
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)
if ($is_home_in_path == true) {
if ($os == "Windows") {
let home = ($nu.home-path | str find-replace -a '\\' '/')
let pwd = ($env.PWD | str find-replace -a '\\' '/')
$pwd | str find-replace $home '~'
let home = ($nu.home-path | str replace -a '\\' '/')
let pwd = ($env.PWD | str replace -a '\\' '/')
$pwd | str replace $home '~'
} else {
$env.PWD | str find-replace $nu.home-path '~'
$env.PWD | str replace $nu.home-path '~'
}
} 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)
if $is_home_in_path {
if ($os_name == "Windows") {
let home = ($nu.home-path | str find-replace -a '\\' '/')
let pwd = ($env.PWD | str find-replace -a '\\' '/')
$pwd | str find-replace $home '~'
let home = ($nu.home-path | str replace -a '\\' '/')
let pwd = ($env.PWD | str replace -a '\\' '/')
$pwd | str replace $home '~'
} else {
$env.PWD | str find-replace $nu.home-path '~'
$env.PWD | str replace $nu.home-path '~'
}
} 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
let abbrev = ((path_abbrev_if_needed (home_abbrev $os.name) 30) | ansi strip)
# $"\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
$"(ansi osc)2;($abbrev)"