mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Merge pull request #21 from fdncred/ls-wide-path
updated ls-wide to take a path
This commit is contained in:
commit
348d6a5342
1 changed files with 38 additions and 5 deletions
|
@ -1,14 +1,37 @@
|
||||||
# A ls command that approximates the ls -sh command in bash
|
# A ls command that approximates the ls -sh command in bash
|
||||||
def ls-wide [
|
def ls-wide [
|
||||||
|
--path(-p):string # The path you want to list
|
||||||
--columns(-c):int # The number of columns in your output
|
--columns(-c):int # The number of columns in your output
|
||||||
] {
|
] {
|
||||||
let is_empty = $(= $columns | empty?)
|
let is_columns_empty = $(= $columns | empty?)
|
||||||
let max_fname_size = $(ls | get name | str from | str length | math max)
|
let is_path_empty = $(= $path | empty?)
|
||||||
let max_fsize_size = $(ls | get size | str from | str length | math max)
|
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) ' '
|
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 {
|
if $(= $it.index + 1) mod 3 == 0 {
|
||||||
echo $(char newline) | autoview
|
echo $(char newline) | autoview
|
||||||
} {}
|
} {}
|
||||||
|
@ -19,3 +42,13 @@ def ls-wide [
|
||||||
}
|
}
|
||||||
} | str collect
|
} | 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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue