mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-12 05:31:14 +02:00
add --time-style option in long style format
This commit is contained in:
parent
a503848e67
commit
d7e7ddd01e
3 changed files with 16 additions and 3 deletions
|
@ -28,7 +28,7 @@ module ColorLS
|
||||||
def initialize(all: false, sort: false, show: false,
|
def initialize(all: false, sort: false, show: false,
|
||||||
mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
|
mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
|
||||||
reverse: false, hyperlink: false, tree_depth: nil, show_group: true, show_user: true,
|
reverse: false, hyperlink: false, tree_depth: nil, show_group: true, show_user: true,
|
||||||
indicator_style: 'slash')
|
indicator_style: 'slash', time_style: '')
|
||||||
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
||||||
@all = all
|
@all = all
|
||||||
@almost_all = almost_all
|
@almost_all = almost_all
|
||||||
|
@ -42,6 +42,7 @@ module ColorLS
|
||||||
@tree = {mode: mode == :tree, depth: tree_depth}
|
@tree = {mode: mode == :tree, depth: tree_depth}
|
||||||
@horizontal = mode == :horizontal
|
@horizontal = mode == :horizontal
|
||||||
@git_status = init_git_status(git_status)
|
@git_status = init_git_status(git_status)
|
||||||
|
@time_style = time_style
|
||||||
@indicator_style = indicator_style
|
@indicator_style = indicator_style
|
||||||
|
|
||||||
init_colors colors
|
init_colors colors
|
||||||
|
@ -249,7 +250,7 @@ module ColorLS
|
||||||
end
|
end
|
||||||
|
|
||||||
def mtime_info(file_mtime)
|
def mtime_info(file_mtime)
|
||||||
mtime = file_mtime.asctime
|
mtime = @time_style.empty? ? file_mtime.asctime : file_mtime.strftime(@time_style)
|
||||||
now = Time.now
|
now = Time.now
|
||||||
return mtime.colorize(@colors[:hour_old]) if now - file_mtime < 60 * 60
|
return mtime.colorize(@colors[:hour_old]) if now - file_mtime < 60 * 60
|
||||||
return mtime.colorize(@colors[:day_old]) if now - file_mtime < 24 * 60 * 60
|
return mtime.colorize(@colors[:day_old]) if now - file_mtime < 24 * 60 * 60
|
||||||
|
|
|
@ -107,7 +107,8 @@ module ColorLS
|
||||||
tree_depth: 3,
|
tree_depth: 3,
|
||||||
show_group: true,
|
show_group: true,
|
||||||
show_user: true,
|
show_user: true,
|
||||||
indicator_style: 'slash'
|
indicator_style: 'slash',
|
||||||
|
time_style: ''
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -183,6 +184,9 @@ module ColorLS
|
||||||
@opts[:show_user] = false
|
@opts[:show_user] = false
|
||||||
end
|
end
|
||||||
options.on('-G', '--no-group', 'show no group information in a long listing') { @opts[:show_group] = false }
|
options.on('-G', '--no-group', 'show no group information in a long listing') { @opts[:show_group] = false }
|
||||||
|
options.on('--time-style=FORMAT', String, 'use time display format') do |time_style|
|
||||||
|
@opts[:time_style] = time_style
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_general_options(options)
|
def add_general_options(options)
|
||||||
|
|
|
@ -550,4 +550,12 @@ RSpec.describe ColorLS::Flags do
|
||||||
|
|
||||||
it { expect { subject }.to output(/.+second-level \n.+symlinks \n/).to_stdout }
|
it { expect { subject }.to output(/.+second-level \n.+symlinks \n/).to_stdout }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with --time-style option' do
|
||||||
|
let(:args) { ['-l', '--time-style=%y-%m-%d %k:%M', "#{FIXTURES}/a.txt"] }
|
||||||
|
|
||||||
|
mtime = File.mtime("#{FIXTURES}/a.txt")
|
||||||
|
|
||||||
|
it { expect { subject }.to output(/#{mtime.strftime("%y-%m-%d %k:%M")}/).to_stdout }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue