1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-31 14:17:45 +00:00

Merge pull request #14 from fdncred/main

add a ls-wide custom command
This commit is contained in:
Darren Schroeder 2021-02-06 14:17:12 -06:00 committed by GitHub
commit 44fb3eda48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

22
ls-wide.nu Normal file
View file

@ -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
}