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

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

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

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 '\\' '/'
}
}