Skip to content

Commit 7aaf475

Browse files
committed
feat: Add nuwget command for file downloads
- Add `nuwget` command to download files from a URL - Support specifying output directory and custom file names - Include options to force overwrite existing files or run silently - Display download statistics including time and speed after completion
1 parent 247968a commit 7aaf475

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

files.nu

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,3 +816,31 @@ export def subtitle-renamer [] {
816816
}
817817
}
818818
}
819+
820+
# Download file with nu
821+
export def nuwget [
822+
url: string
823+
--directory (-d): path # Base dir
824+
--output (-o): path # File name
825+
--force (-f) # Overwrite file
826+
--silent (-s) # Don't print anything
827+
] {
828+
if ($directory | is-not-empty) { cd $directory }
829+
let $file_name = $output | default { $url | url parse | get path | split row '/' | url decode | last }
830+
831+
if not $force and ($file_name | path exists) { error make -u {msg: "File already exists"} }
832+
833+
let $time = timeit { http get $url | save --progress --force=$force $file_name }
834+
835+
if not $silent {
836+
print "Download results:"
837+
{
838+
url: $url
839+
file: ($file_name | path basename)
840+
cwd: ($file_name | path expand | path dirname)
841+
time: $time
842+
speed: $"((ls $file_name | get 0.size) / ($time | into int | $in / 10 ** 9))/s"
843+
}
844+
| print
845+
}
846+
}

0 commit comments

Comments
 (0)