mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 22:57:46 +00:00
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`
This commit is contained in:
parent
7a5424d7d0
commit
e8df70a406
16 changed files with 177 additions and 230 deletions
47
modules/ls_mods/ls-wide.nu
Normal file
47
modules/ls_mods/ls-wide.nu
Normal file
|
@ -0,0 +1,47 @@
|
|||
# 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue