Skip to content

Commit

Permalink
Show number of hard links in long listing
Browse files Browse the repository at this point in the history
Fixes #293
  • Loading branch information
avdv committed Jun 30, 2019
1 parent d6a04d2 commit 56a0ec6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/colorls/core.rb
Expand Up @@ -269,7 +269,7 @@ def git_dir_info(path)
def long_info(content)
return '' unless @long

[mode_info(content.stats), user_info(content), group_info(content.group),
[mode_info(content.stats), content.nlink, user_info(content), group_info(content.group),
size_info(content.size), mtime_info(content.mtime)].join(' ')
end

Expand Down
2 changes: 1 addition & 1 deletion lib/colorls/fileinfo.rb
Expand Up @@ -57,6 +57,6 @@ def to_s
name
end

def_delegators :@stats, :directory?, :socket?, :chardev?, :symlink?, :blockdev?, :mtime, :size, :owned?
def_delegators :@stats, :directory?, :socket?, :chardev?, :symlink?, :blockdev?, :mtime, :nlink, :size, :owned?
end
end
32 changes: 30 additions & 2 deletions spec/color_ls/flags_spec.rb
Expand Up @@ -57,7 +57,7 @@
it('lists file info') { expect { subject }.to output(/((r|-).*(w|-).*(x|-).*){3}/).to_stdout }
end

context 'with --long flag and special bits' do
context 'with --long flag for `a.txt`' do
let(:args) { ['--long', "#{FIXTURES}/a.txt"] }

it 'shows special permission bits' do
Expand All @@ -68,6 +68,7 @@
:directory? => false,
:owner => "user",
:name => "a.txt",
:nlink => 1,
:size => 128,
:blockdev? => false,
:chardev? => false,
Expand All @@ -83,7 +84,34 @@

allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", true) { fileInfo }

expect { subject }.to output(/r-Sr-Sr-T \s+ user \s+ sys .* a.txt/mx).to_stdout
expect { subject }.to output(/r-Sr-Sr-T .* a.txt/mx).to_stdout
end

it 'shows number of hardlinks' do
fileInfo = instance_double(
'FileInfo',
:group => "sys",
:mtime => Time.now,
:directory? => false,
:owner => "user",
:name => "a.txt",
:nlink => 5, # number of hardlinks
:size => 128,
:blockdev? => false,
:chardev? => false,
:socket? => false,
:symlink? => false,
:stats => OpenStruct.new(
mode: 0o444, # read for user, owner, other
setuid?: true,
setgid?: true,
sticky?: true
)
)

allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", true) { fileInfo }

expect { subject }.to output(/\S+\s+ 5 .* a.txt/mx).to_stdout
end
end

Expand Down

0 comments on commit 56a0ec6

Please sign in to comment.