diff --git a/CHANGELOG.md b/CHANGELOG.md index 49b57ec..6658a94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,13 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added +- compact date with week day (e.g. Thu 18 Jul'24 09:03) + ### Updated - tweaked the help layout - removed the last vestiages of line buffering +- remove leading 0 in compact date format ## [2024.4] - 2024-07-07 ### Added diff --git a/lsv/entry.v b/lsv/entry.v index 5d224e3..02b1eb0 100644 --- a/lsv/entry.v +++ b/lsv/entry.v @@ -58,7 +58,7 @@ fn make_entry(file string, dir_name string, options Options) Entry { } filetype := stat.get_filetype() - is_link := filetype == os.FileType.symbolic_link + is_link := filetype == .symbolic_link link_origin := if is_link { read_link(path) } else { '' } mut size := stat.size mut link_stat := os.Stat{} @@ -76,8 +76,7 @@ fn make_entry(file string, dir_name string, options Options) Entry { is_character_device := filetype == .character_device is_unknown := filetype == .unknown is_exe := !is_dir && is_executable(stat) - is_file := !is_dir && !is_fifo && !is_block && !is_socket && !is_character_device && !is_unknown - && !is_exe && !invalid + is_file := filetype == .regular indicator := if is_dir && options.dir_indicator { '/' } else { '' } return Entry{ @@ -105,10 +104,6 @@ fn make_entry(file string, dir_name string, options Options) Entry { } } -fn is_executable(stat os.Stat) bool { - return stat.get_mode().bitmask() & 0b001001001 > 0 -} - fn readable_size(size u64, si bool) string { kb := if si { f64(1024) } else { f64(1000) } mut sz := f64(size) @@ -152,6 +147,12 @@ fn checksum(name string, dir_name string, options Options) string { } } +@[inline] +fn is_executable(stat os.Stat) bool { + return stat.get_mode().bitmask() & 0b001001001 > 0 +} + +@[inline] fn is_dot_file(file string) bool { - return file.len > 0 && file[0] == `.` + return file.starts_with('.') } diff --git a/lsv/format_long.v b/lsv/format_long.v index d89a1e5..19d6bed 100644 --- a/lsv/format_long.v +++ b/lsv/format_long.v @@ -21,6 +21,7 @@ const space = ' ' const date_format = 'MMM DD YYYY HH:mm:ss' const date_iso_format = 'YYYY-MM-DD HH:mm:ss' const date_compact_format = "DD MMM'YY HH:mm" +const date_compact_format_with_day = "ddd DD MMM'YY HH:mm" struct Longest { inode int @@ -286,9 +287,10 @@ fn format_header(options Options, longest Longest) (string, []int) { fn time_format(options Options) string { return match true { // vfmt off - options.time_iso { date_iso_format } - options.time_compact { date_compact_format } - else { date_format } + options.time_iso { date_iso_format } + options.time_compact { date_compact_format } + options.time_compact_with_day { date_compact_format_with_day } + else { date_format } // vfmt on } } @@ -388,10 +390,14 @@ fn format_time(entry Entry, stat_time StatTime, options Options) string { .modified { entry.stat.mtime } } - date := time.unix(entry_time) + mut date := time.unix(entry_time) .local() .custom_format(time_format(options)) + if date.starts_with('0') { + date = ' ' + date[1..] + } + dim := if options.no_dim { no_style } else { dim_style } content := if entry.invalid { '?' + space.repeat(date.len - 1) } else { date } return format_cell(content, date.len, .left, dim, options) diff --git a/lsv/options.v b/lsv/options.v index 2db1b32..361256d 100644 --- a/lsv/options.v +++ b/lsv/options.v @@ -39,23 +39,24 @@ struct Options { sort_width bool // // long view options - accessed_date bool - changed_date bool - header bool - inode bool - no_count bool - no_date bool - no_group_name bool - no_hard_links bool - no_owner_name bool - no_permissions bool - no_size bool - octal_permissions bool - size_kb bool - size_ki bool - time_iso bool - time_compact bool - checksum string + accessed_date bool + changed_date bool + header bool + inode bool + no_count bool + no_date bool + no_group_name bool + no_hard_links bool + no_owner_name bool + no_permissions bool + no_size bool + octal_permissions bool + size_kb bool + size_ki bool + time_iso bool + time_compact bool + time_compact_with_day bool + checksum string // // from ls colors style_di Style @@ -115,6 +116,7 @@ fn parse_args(args []string) Options { header := fp.bool('', `H`, false, 'show column headers') time_iso := fp.bool('', `I`, false, 'show time in iso format') time_compact := fp.bool('', `J`, false, 'show time in compact format') + time_compact_with_day := fp.bool('', `L`, false, 'show time in compact format with week day') inode := fp.bool('', `N`, false, 'show inodes') no_wrap := fp.bool('', `Z`, false, 'do not wrap long lines\n') @@ -128,8 +130,7 @@ fn parse_args(args []string) Options { no_permissions := fp.bool('no-permissions', 0, false, 'hide permissions') no_size := fp.bool('no-size', 0, false, 'hide file size\n') - fp.footer(' - + fp.footer('\n The -c option emits color codes when standard output is connected to a terminal. Colors are defined in the LS_COLORS environment variable.'.trim_indent()) @@ -189,6 +190,7 @@ fn parse_args(args []string) Options { style_so: style_map['so'] table_format: table_format && long_format time_compact: time_compact + time_compact_with_day: time_compact_with_day time_iso: time_iso width_in_cols: width_in_cols with_commas: with_commas