Skip to content

Commit

Permalink
v2024.6
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-ward committed Dec 31, 2024
1 parent 491c99f commit 70684fb
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## [2024.6]
### Added
- , (comma) flag to print file sizes grouped and separated by thousands.

### Update
- icons

## [2024.5]
### Added
- compact date with week day (e.g. Thu 18 Jul'24 09:03)
Expand Down
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ Border format with header option

### Homebrew

I tried several times to submit to Homebrew but could never get past the CI. Please send a pull request to Homebrew if you know how. Thanks.
Not enough stars to publish to Homebrew :(

## Help
```
lsv 2024.4
lsv 2024.6
-----------------------------------------------
Usage: lsv [options] [FILES]
Expand All @@ -54,13 +54,15 @@ Options:
-c color the listing
-D append / to directories
-i show file icon (requires nerd fonts)
-l long listing format
-m list of files separated by commas
-q enclose files in quotes
-R list subdirectories recursively
--depth <int> limit depth of recursion
-X list files by lines instead of by columns
-1 list one file per line
--width <int> set output width to <int>
--depth <int> limit depth of recursion
--width <int> set output width to <int>
Filtering and Sorting Options:
-d list only directories
Expand All @@ -75,31 +77,32 @@ Filtering and Sorting Options:
-u no sorting
Long Listing Options:
-, show file sizes grouped and separated by thousands
-b blank line every 5 rows
-B add borders to long listing format
-k sizes in kibibytes (1024) (e.g. 1k 234m 2g)
-K sizes in Kilobytes (1000) (e.g. 1kb 234mb 2gb)
-l long listing format
-o show octal permissions
-p show relative path
-A show last accessed date
-C show last status changed date
-H show column headers
-I show time in iso format
-J show time in compact format
-L show time in compact format with week day
-N show inodes
-Z do not wrap long lines
--cs <string> show file checksum
--cs <string> show file checksum
(md5, sha1, sha224, sha256, sha512, blake2b)
--no-counts hide file/dir counts
--no-date hide date (modified)
--no-dim hide shading; useful for light backgrounds
--no-group hide group name
--no-hard-links hide hard links count
--no-owner hide owner name
--no-permissions hide permissions
--no-size hide file size
--no-counts hide file/dir counts
--no-date hide date (modified)
--no-dim hide shading; useful for light backgrounds
--no-group hide group name
--no-hard-links hide hard links count
--no-owner hide owner name
--no-permissions hide permissions
--no-size hide file size
-h, --help display this help and exit
--version output version information and exit
Expand Down
9 changes: 9 additions & 0 deletions lsv/entry.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct Entry {
unknown bool
link_origin string
size u64
size_comma string
size_ki string
size_kb string
checksum string
Expand Down Expand Up @@ -96,6 +97,7 @@ fn make_entry(file string, dir_name string, options Options) Entry {
unknown: is_unknown
link_origin: link_origin
size: size
size_comma: if options.comma { num_with_commas(size)} else { '' }
size_ki: if options.size_ki { readable_size(size, true) } else { '' }
size_kb: if options.size_kb { readable_size(size, false) } else { '' }
checksum: if is_file { checksum(file, dir_name, options) } else { '' }
Expand All @@ -104,6 +106,13 @@ fn make_entry(file string, dir_name string, options Options) Entry {
}
}

fn num_with_commas(num u64) string {
if num < 1000 {
return num.str()
}
return num_with_commas(num / 1000) + ',${(num % 1000):03u}'
}

fn readable_size(size u64, si bool) string {
kb := if si { f64(1024) } else { f64(1000) }
mut sz := f64(size)
Expand Down
3 changes: 3 additions & 0 deletions lsv/format_long.v
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fn format_long_listing(entries []Entry, options Options) {
entry.dir || entry.socket || entry.fifo { '-' }
options.size_ki && options.size_ki && !options.size_kb { entry.size_ki }
options.size_kb && options.size_kb { entry.size_kb }
options.comma { entry.size_comma }
else { entry.size.str() }
// vfmt on
}
Expand Down Expand Up @@ -330,6 +331,7 @@ fn statistics(entries []Entry, len int, options Options) {
size := match true {
options.size_ki { readable_size(total, true) }
options.size_kb { readable_size(total, false) }
options.comma { num_with_commas(total) }
else { total.str() }
}

Expand Down Expand Up @@ -426,6 +428,7 @@ fn longest_size_len(entries []Entry, title string, options Options) int {
it.dir { 1 }
options.size_ki && !options.size_kb { it.size_ki.len }
options.size_kb { it.size_kb.len }
options.comma { it.size_comma.len }
else { it.size.str().len }
})
max := arrays.max(lengths) or { 0 }
Expand Down
20 changes: 15 additions & 5 deletions lsv/icons.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ fn get_icon_for_entry(entry Entry, options Options) string {
name := os.file_name(entry.name)
return match entry.dir {
true { get_icon_for_folder(name) }
else { get_icon_for_file(name, ext) }
else { get_icon_for_file(name, ext, entry) }
}
}

fn get_icon_for_file(name string, ext string) string {
fn get_icon_for_file(name string, ext string, entry Entry) string {
// default icon for all files. try to find a better one though...
mut icon := icons_map['file']
// resolve aliased extensions
Expand All @@ -39,6 +39,15 @@ fn get_icon_for_file(name string, ext string) string {
if best_icon != '' {
icon = best_icon
}
// look at file type
if icon == icons_map['file'] {
icon = match true {
entry.socket { other_icons_map['socket'] }
entry.link { other_icons_map['link'] }
entry.exe { other_icons_map['exe'] }
else { icons_map['file'] }
}
}
return icon + space
}

Expand Down Expand Up @@ -88,7 +97,7 @@ const icons_map = {
'erl': '\ue7b1'
'ex': '\ue62d'
'f': '󱈚'
'file': '\uf15b'
'file': '\uea7b'
'font': '\uf031'
'fs': '\ue7a7'
'gb': '\ue272'
Expand Down Expand Up @@ -421,11 +430,11 @@ const folders_map = {
'.npm': '\ue5fa'
'.nvm': '\ue718'
'.rvm': '\ue21e'
'.Trash': '\uf1f8'
'.Trash': '\uf014'
'.vscode': '\ue70c'
'.vim': '\ue62b'
'config': '\ue5fc'
'folder': '\uf07c'
'folder': '\uea83'
'hidden': '\uf023'
'node_modules': '\ue5fa'
}
Expand All @@ -437,4 +446,5 @@ const other_icons_map = {
'device': '\uf0a0'
'socket': '\uf1e6'
'pipe': '\ufce3'
'exe': '\uef0c'
}
9 changes: 6 additions & 3 deletions lsv/options.v
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct Options {
// long view options
accessed_date bool
changed_date bool
comma bool
header bool
inode bool
no_count bool
Expand Down Expand Up @@ -76,7 +77,7 @@ fn parse_args(args []string) Options {
mut fp := flag.new_flag_parser(args)

fp.application(app_name)
fp.version('2024.5')
fp.version('2024.6')
fp.skip_executable()
fp.description('List information about FILES')
fp.arguments_description('[FILES]')
Expand All @@ -91,8 +92,8 @@ fn parse_args(args []string) Options {
recursive := fp.bool('', `R`, false, 'list subdirectories recursively')
list_by_lines := fp.bool('', `X`, false, 'list files by lines instead of by columns')
one_per_line := fp.bool('', `1`, false, 'list one file per line\n')

recursion_depth := fp.int('depth', 0, max_int, 'limit depth of recursion')

width_in_cols := fp.int('width', 0, 0, 'set output width to <int>\n\nFiltering and Sorting Options:')
only_dirs := fp.bool('', `d`, false, 'list only directories')
only_files := fp.bool('', `f`, false, 'list only files')
Expand All @@ -103,8 +104,9 @@ fn parse_args(args []string) Options {
sort_natural := fp.bool('', `v`, false, 'sort digits within text as numbers')
sort_width := fp.bool('', `w`, false, 'sort by width, shortest first')
sort_ext := fp.bool('', `x`, false, 'sort by file extension')

sort_none := fp.bool('', `u`, false, 'no sorting\n\nLong Listing Options:')

comma := fp.bool('', `,`, false, 'show file sizes grouped and separated by thousands')
blocked_output := fp.bool('', `b`, false, 'blank line every 5 rows')
table_format := fp.bool('', `B`, false, 'add borders to long listing format')
size_ki := fp.bool('', `k`, false, 'sizes in kibibytes (1024) (e.g. 1k 234m 2g)')
Expand Down Expand Up @@ -146,6 +148,7 @@ fn parse_args(args []string) Options {
changed_date: changed_date
checksum: checksum
colorize: colorize && can_show_color_on_stdout
comma: comma
dir_indicator: dir_indicator
dirs_first: dirs_first
files: if files == [] { current_dir } else { files }
Expand Down
12 changes: 6 additions & 6 deletions lsv/style.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const dim_style = Style{

const di_style = Style{
bold: true
fg: fgf('36') // cyan
fg: fgf('36') // cyan
}

const fi_style = Style{
Expand All @@ -30,12 +30,12 @@ const fi_style = Style{

const ln_style = Style{
bold: true
fg: fgf('34') // magenta
fg: fgf('34') // magenta
}

const ex_style = Style{
bold: true
fg: fgf('31') // red
fg: fgf('31') // red
}

const so_style = Style{
Expand Down Expand Up @@ -152,10 +152,10 @@ fn make_style(ansi string) Style {
}

return Style{
fg: fg
bg: bg
fg: fg
bg: bg
bold: bold
ul: ul
ul: ul
}
}

Expand Down

0 comments on commit 70684fb

Please sign in to comment.