1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-31 14:17:45 +00:00
nu_scripts/modules/ls_mods/ls-wide.nu
Igor e8df70a406
Port before_v0.60/fuzzy, before_v0.60/ls-mods and before_v0.60/nu_101 (#845)
This PR is part of porting all old scripts #221 and includes a set of
modules:

- fuzzy -> `modules/fuzzy/fuzzy_command_search.nu`
- ls-mods -> `modules/ls-mods`: `ls-less.nu`, `ls-wide.nu` and
`ls-wide-with-color.nu`
- nu_101 -> `modules/nu_101`: `nothing.nu` and `inner_outer_loop.nu`

Edit: `fuzzy` and `nu_101` have been moved to `sourced`
2024-05-26 12:35:59 -05:00

47 lines
1.4 KiB
Text

# A ls command that approximates the ls -sh command in bash
export def ls-wide [
--path(-p):string # The path you want to list
--columns(-c):int # The number of columns in your output
] {
let is_columns_empty = ($columns | is-empty)
let is_path_empty = ($path | is-empty)
let columns_default = 3
if $is_path_empty {
if $is_columns_empty {
run_ls "." $columns_default
} else {
run_ls "." $columns
}
} else {
if $is_columns_empty {
run_ls $path $columns_default
} else {
run_ls $path $columns
}
}
}
def run_ls [
path:string
columns:int
] {
let max_fname_size = (ls $path | get name | into string | str length | math max)
let max_fsize_size = (ls $path | get size | into string | str length | math max)
let is_columns_empty = ($columns | is-empty)
ls $path | enumerate | each { |file|
let the_file = ($file.item.name | into string | fill -a l -c ' ' -w $max_fname_size)
let the_size = ($file.item.size | into string | fill -a r -c ' ' -w $max_fsize_size)
let new_line = (if $is_columns_empty {
if ($file.index + 1) mod 3 == 0 {
char newline
}
} else {
if ($file.index + 1) mod $columns == 0 {
char newline
}
})
$"($the_file) ($the_size) ($new_line)"
} | str join
}