Add basic --inode flag

This commit is contained in:
goar5670 2022-03-20 00:17:08 +03:00 committed by goar5670
parent 0b61d733de
commit 793cd20cc8
2 changed files with 10 additions and 3 deletions

View file

@ -26,8 +26,7 @@ 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, reverse: false, hyperlink: false, tree_depth: nil, show_inode: false, show_group: true, show_user: true,
reverse: false, hyperlink: false, tree_depth: nil, 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,6 +37,7 @@ 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
@ -298,6 +298,11 @@ module ColorLS
end end
end end
def get_inode(content)
return '' unless @show_inode
content.stats.ino.to_s
end
def long_info(content) def long_info(content)
return '' unless @long return '' unless @long
@ -336,7 +341,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)}" "#{get_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)

View file

@ -105,6 +105,7 @@ module ColorLS
git_status: false, git_status: 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',
@ -143,6 +144,7 @@ module ColorLS
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[:git_status] = 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