forked from nushell/nu_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls-wide.nu
47 lines (44 loc) · 1.42 KB
/
ls-wide.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
}