From e5c71dbc4680ca4aa3ec441010313cbe20fee5ca Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 19 Feb 2021 09:56:19 -0600 Subject: [PATCH] updated ls-wide to take a path --- ls_mods/ls-wide.nu | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/ls_mods/ls-wide.nu b/ls_mods/ls-wide.nu index 10061da..1e59429 100644 --- a/ls_mods/ls-wide.nu +++ b/ls_mods/ls-wide.nu @@ -1,14 +1,37 @@ # A ls command that approximates the ls -sh command in bash def ls-wide [ + --path(-p):string # The path you want to list --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) + let is_columns_empty = $(= $columns | empty?) + let is_path_empty = $(= $path | empty?) + let columns_default = 3 - ls | each -n { + if $is_path_empty { + if $is_columns_empty { + run_ls "." $columns_default + } { + run_ls "." $columns + } + } { + if $is_columns_empty { + run_ls $path $columns_default + } { + run_ls $path $columns + } + } +} + +def run_ls [ + path:string + columns:int + ] { + let max_fname_size = $(ls $path | get name | str from | str length | math max) + let max_fsize_size = $(ls $path | get size | str from | str length | math max) + + ls $path | 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 $is_columns_empty { if $(= $it.index + 1) mod 3 == 0 { echo $(char newline) | autoview } {} @@ -19,3 +42,13 @@ def ls-wide [ } } | str collect } + +# This is a first attempt and some type of logging +def log [ + message:any # Some log message + ] { + let now = $(date now | date format '%Y%m%d_%H%M%S.%f') + let mess = $(build-string $now '|DBG|' $message $(char newline)) + echo $mess | autoview +} +