nuscripts/tools/varia.nu

65 lines
1.7 KiB
Plaintext
Raw Normal View History

2024-01-13 10:50:06 +00:00
# use runonce.nu
export def "cargo search" [ query: string, --limit=10] {
^cargo search $query --limit $limit
| lines
| each {
|line| if ($line | str contains "#") {
$line | parse --regex '(?P<name>.+) = "(?P<version>.+)" +# (?P<description>.+)'
} else {
$line | parse --regex '(?P<name>.+) = "(?P<version>.+)"'
}
}
| flatten
}
export def "download" [ dest: string url: string , --minsize=1] {
let $destdir = $dest | path dirname
mkdir $destdir
print $"download url:($url) to dest:($dest)"
# Download the file
http get $url | save -f $dest
let minsize = $minsize * 1000000
if ($minsize > 0) {
let p = ls $dest
if (($p.size | into int).0 < $minsize) {
print $"The download was too small for ($dest)"
exit 1
} else {
print $"Download ok for ($dest)"
}
}
# echo $"File size: $file_size bytes"
}
export def "download_expand" [ dest: string url: string , --minsize=1] {
mkdir $dest
print $"download expand url:($url) to dest:($dest)"
let $file_name = $url | split row '/' | last
let $ext = $file_name | split row '.' | skip 1 | | str join "." | str downcase
let $dest2 = $"($dest)/downloadedfile.($ext)"
print $dest2
download $dest2 $url --minsize=$minsize
let $e = extract $dest2
}
# export def init_plugins [] {
# runonce run init_plugins {
# register bin/nu_plugin_dns
# register bin/nu_plugin_desktop_notifications
# register bin/nu_plugin_net
# register bin/nu_plugin_port_list
# register bin/nu_plugin_port_scan
# register bin/nu_plugin_query
# } --reset true
# }