From e57026ec8ac64f67d038c6e04fda8be6d50bb066 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sat, 6 Feb 2021 14:15:30 -0600 Subject: [PATCH] add ls-wide script --- ls-wide.nu | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ls-wide.nu diff --git a/ls-wide.nu b/ls-wide.nu new file mode 100644 index 0000000..e9f1927 --- /dev/null +++ b/ls-wide.nu @@ -0,0 +1,22 @@ +# A ls command that approximates the ls -sh command in bash +def ls-wide [ + --columns(-c):int # The number of columns in your output + ] { + let is_empty = $(= $columns | empty?) + let max_fname_size = $(ls | get name | str from | str length | math max) + let max_fsize_size = $(ls | get size | str from | str length | math max) + + ls | each -n { + build-string $(echo $it.item.name | str rpad -c ' ' -l $max_fname_size) ' ' $(echo $(build-string $it.item.size) | str lpad -c ' ' -l $max_fsize_size) ' ' + if $is_empty { + if $it.index mod 3 == 0 && $it.index != 0 { + echo $(char newline) | autoview + } {} + + } { + if $it.index mod $columns == 0 && $it.index != 0 { + echo $(char newline) | autoview + } {} + } + } | str collect +}