mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-12 05:31:14 +02:00
Merge pull request #506 from goar5670/add-inode
This commit is contained in:
commit
092e25a83b
7 changed files with 32 additions and 12 deletions
|
@ -58,7 +58,7 @@ Metrics/ClassLength:
|
||||||
Max: 350
|
Max: 350
|
||||||
|
|
||||||
Metrics/ParameterLists:
|
Metrics/ParameterLists:
|
||||||
Max: 15
|
Max: 16
|
||||||
|
|
||||||
Naming/FileName:
|
Naming/FileName:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
|
@ -26,8 +26,8 @@ module ColorLS
|
||||||
|
|
||||||
class Core
|
class Core
|
||||||
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, show_git: 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_inode: false, show_group: true, show_user: true,
|
||||||
indicator_style: 'slash', time_style: '')
|
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
|
||||||
|
@ -38,12 +38,16 @@ module ColorLS
|
||||||
@group = group
|
@group = group
|
||||||
@show = show
|
@show = show
|
||||||
@one_per_line = mode == :one_per_line
|
@one_per_line = mode == :one_per_line
|
||||||
|
@show_inode = show_inode
|
||||||
init_long_format(mode,show_group,show_user)
|
init_long_format(mode,show_group,show_user)
|
||||||
@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)
|
@show_git = show_git
|
||||||
|
@git_status = init_git_status(show_git)
|
||||||
@time_style = time_style
|
@time_style = time_style
|
||||||
@indicator_style = indicator_style
|
@indicator_style = indicator_style
|
||||||
|
# how much characters an item occupies besides its name
|
||||||
|
@additional_chars_per_item = 12 + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0)
|
||||||
|
|
||||||
init_colors colors
|
init_colors colors
|
||||||
|
|
||||||
|
@ -149,11 +153,8 @@ module ColorLS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# how much characters an item occupies besides its name
|
|
||||||
CHARS_PER_ITEM = 12
|
|
||||||
|
|
||||||
def item_widths
|
def item_widths
|
||||||
@contents.map { |item| Unicode::DisplayWidth.of(item.show) + CHARS_PER_ITEM }
|
@contents.map { |item| Unicode::DisplayWidth.of(item.show) + @additional_chars_per_item }
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_hidden_contents
|
def filter_hidden_contents
|
||||||
|
@ -298,6 +299,12 @@ module ColorLS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inode(content)
|
||||||
|
return '' unless @show_inode
|
||||||
|
|
||||||
|
content.stats.ino.to_s.rjust(10).colorize(@colors[:inode])
|
||||||
|
end
|
||||||
|
|
||||||
def long_info(content)
|
def long_info(content)
|
||||||
return '' unless @long
|
return '' unless @long
|
||||||
|
|
||||||
|
@ -336,7 +343,7 @@ module ColorLS
|
||||||
entry = "#{out_encode(logo)} #{out_encode(name)}"
|
entry = "#{out_encode(logo)} #{out_encode(name)}"
|
||||||
entry = entry.bright if !content.directory? && content.executable?
|
entry = entry.bright if !content.directory? && content.executable?
|
||||||
|
|
||||||
"#{long_info(content)} #{git_info(content)} #{entry.colorize(color)}#{symlink_info(content)}"
|
"#{inode(content)} #{long_info(content)} #{git_info(content)} #{entry.colorize(color)}#{symlink_info(content)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def ls_line(chunk, widths)
|
def ls_line(chunk, widths)
|
||||||
|
@ -346,7 +353,7 @@ module ColorLS
|
||||||
entry = fetch_string(content, *options(content))
|
entry = fetch_string(content, *options(content))
|
||||||
line << (' ' * padding)
|
line << (' ' * padding)
|
||||||
line << ' ' << entry.encode(Encoding.default_external, undef: :replace)
|
line << ' ' << entry.encode(Encoding.default_external, undef: :replace)
|
||||||
padding = widths[i] - Unicode::DisplayWidth.of(content.show) - CHARS_PER_ITEM
|
padding = widths[i] - Unicode::DisplayWidth.of(content.show) - @additional_chars_per_item
|
||||||
end
|
end
|
||||||
print line << "\n"
|
print line << "\n"
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,9 +102,10 @@ module ColorLS
|
||||||
mode: STDOUT.tty? ? :vertical : :one_per_line, # rubocop:disable Style/GlobalStdStream
|
mode: STDOUT.tty? ? :vertical : :one_per_line, # rubocop:disable Style/GlobalStdStream
|
||||||
all: false,
|
all: false,
|
||||||
almost_all: false,
|
almost_all: false,
|
||||||
git_status: false,
|
show_git: false,
|
||||||
colors: [],
|
colors: [],
|
||||||
tree_depth: 3,
|
tree_depth: 3,
|
||||||
|
show_inode: false,
|
||||||
show_group: true,
|
show_group: true,
|
||||||
show_user: true,
|
show_user: true,
|
||||||
indicator_style: 'slash',
|
indicator_style: 'slash',
|
||||||
|
@ -141,8 +142,9 @@ module ColorLS
|
||||||
options.on('-A', '--almost-all', 'do not list . and ..') { @opts[:almost_all] = true }
|
options.on('-A', '--almost-all', 'do not list . and ..') { @opts[:almost_all] = true }
|
||||||
options.on('-d', '--dirs', 'show only directories') { @opts[:show] = :dirs }
|
options.on('-d', '--dirs', 'show only directories') { @opts[:show] = :dirs }
|
||||||
options.on('-f', '--files', 'show only files') { @opts[:show] = :files }
|
options.on('-f', '--files', 'show only files') { @opts[:show] = :files }
|
||||||
options.on('--gs', '--git-status', 'show git status for each file') { @opts[:git_status] = true }
|
options.on('--gs', '--git-status', 'show git status for each file') { @opts[:show_git] = true }
|
||||||
options.on('-p', 'append / indicator to directories') { @opts[:indicator_style] = 'slash' }
|
options.on('-p', 'append / indicator to directories') { @opts[:indicator_style] = 'slash' }
|
||||||
|
options.on('-i', '--inode', 'show inode number') { @opts[:show_inode] = true }
|
||||||
options.on('--report=[WORD]', %w[short long], 'show report: short, long (default if omitted)') do |word|
|
options.on('--report=[WORD]', %w[short long], 'show report: short, long (default if omitted)') do |word|
|
||||||
word ||= :long
|
word ||= :long
|
||||||
@report_mode = word.to_sym
|
@report_mode = word.to_sym
|
||||||
|
|
|
@ -36,6 +36,7 @@ tree: cyan
|
||||||
empty: yellow
|
empty: yellow
|
||||||
error: red
|
error: red
|
||||||
normal: darkkhaki
|
normal: darkkhaki
|
||||||
|
inode: moccasin
|
||||||
|
|
||||||
# Git
|
# Git
|
||||||
addition: chartreuse
|
addition: chartreuse
|
||||||
|
|
|
@ -36,6 +36,7 @@ tree: cyan
|
||||||
empty: yellow
|
empty: yellow
|
||||||
error: red
|
error: red
|
||||||
normal: black
|
normal: black
|
||||||
|
inode: black
|
||||||
|
|
||||||
# Git
|
# Git
|
||||||
addition: chartreuse
|
addition: chartreuse
|
||||||
|
|
|
@ -371,6 +371,14 @@ RSpec.describe ColorLS::Flags do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with --inode flag' do
|
||||||
|
let(:args) { ['--inode', '-i', 'show inode number', FIXTURES] }
|
||||||
|
|
||||||
|
it 'shows inode number' do
|
||||||
|
expect { subject }.to output(/\d{7,}/).to_stdout
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with non-existent path' do
|
context 'with non-existent path' do
|
||||||
let(:args) { ['not_exist_file'] }
|
let(:args) { ['not_exist_file'] }
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ OK colorls --tree=1
|
||||||
OK colorls --report
|
OK colorls --report
|
||||||
OK colorls --report=long
|
OK colorls --report=long
|
||||||
OK colorls --report=short
|
OK colorls --report=short
|
||||||
|
OK colorls --inode
|
||||||
|
|
||||||
LC_ALL=C OK colorls spec/fixtures/
|
LC_ALL=C OK colorls spec/fixtures/
|
||||||
LC_ALL=C OK colorls --git spec/fixtures/
|
LC_ALL=C OK colorls --git spec/fixtures/
|
||||||
|
|
Loading…
Reference in a new issue