nu-modules/s3.nu

48 lines
1.3 KiB
Plaintext

def mc-hosts [] {
open ~/.mc/config.json | get aliases | columns
}
export def buckets [host:string@mc-hosts] {
^mc ls --json $host | from json --objects | get key
}
export def "del bucket" [host:string@mc-hosts, bucket:string] {
^mc rb --force $"($host)/($bucket)"
}
export def "download bucket" [host:string@mc-hosts, bucket:string] {
^mc cp --recursive ([$host, $bucket ] | path join) .
}
# delete all files within a bucket (but not the bucket itself)
export def "empty bucket" [host:string@mc-hosts, bucket:string:string] {
^mc rm --recursive --force ([$host, $bucket] | path join)
}
export def "mk bucket" [host:string@mc-hosts, bucket:string] {
^mc mb $"($host)/($bucket)"
}
export def files [host:string@mc-hosts,prefix:string=""] {
^mc ls -r --json ([$host, $prefix] | path join) | from json --objects
| insert host $host
| insert prefix $prefix
}
export def folders [host:string@mc-hosts] {
^mc ls --json $host | from json --objects
}
export def "delete files" [] {
let files = ($in | each { |x| [$x.host, $x.prefix, $x.key] | path join })
run-external --redirect-stdout mc rm $files
}
export def "cat files" [] {
let files = ($in | each { |x| [$x.host, $x.prefix, $x.key] | path join })
run-external --redirect-stdout mc cat $files
}
export def get-csv [] {
^mc cat $in | from csv
}