mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-19 05:31:23 +02:00
Merges branch
This commit is contained in:
commit
4313a25771
5 changed files with 32 additions and 4 deletions
|
@ -18,10 +18,12 @@ script:
|
||||||
- colorls -d
|
- colorls -d
|
||||||
- colorls -f
|
- colorls -f
|
||||||
- colorls -l
|
- colorls -l
|
||||||
|
- colorls -l spec/fixtures/symlinks
|
||||||
- colorls -r
|
- colorls -r
|
||||||
- colorls -sd
|
- colorls -sd
|
||||||
- colorls -sf
|
- colorls -sf
|
||||||
- colorls -t
|
- colorls -t
|
||||||
|
- colorls spec/fixtures/symlinks
|
||||||
- colorls README.md
|
- colorls README.md
|
||||||
- colorls *
|
- colorls *
|
||||||
- colorls | grep /
|
- colorls | grep /
|
||||||
|
|
|
@ -64,6 +64,7 @@ module ColorLS
|
||||||
|
|
||||||
def init_user_lengths
|
def init_user_lengths
|
||||||
@userlength = @contents.map do |c|
|
@userlength = @contents.map do |c|
|
||||||
|
next 0 unless File.exist?("#{@input}/#{c}")
|
||||||
begin
|
begin
|
||||||
user = Etc.getpwuid(File.stat("#{@input}/#{c}").uid).name
|
user = Etc.getpwuid(File.stat("#{@input}/#{c}").uid).name
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
|
@ -75,6 +76,7 @@ module ColorLS
|
||||||
|
|
||||||
def init_group_lengths
|
def init_group_lengths
|
||||||
@grouplength = @contents.map do |c|
|
@grouplength = @contents.map do |c|
|
||||||
|
next 0 unless File.exist?("#{@input}/#{c}")
|
||||||
begin
|
begin
|
||||||
group = Etc.getgrgid(File.stat("#{@input}/#{c}").gid).name
|
group = Etc.getgrgid(File.stat("#{@input}/#{c}").gid).name
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
|
@ -146,7 +148,7 @@ module ColorLS
|
||||||
end
|
end
|
||||||
|
|
||||||
def in_line(chunk_size)
|
def in_line(chunk_size)
|
||||||
return false if @max_widths.sum + 8 * chunk_size > @screen_width
|
return false if @max_widths.sum + 7 * chunk_size > @screen_width
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -210,8 +212,25 @@ module ColorLS
|
||||||
end
|
end
|
||||||
|
|
||||||
def long_info(content)
|
def long_info(content)
|
||||||
|
return '' unless @long
|
||||||
|
unless File.exist?("#{@input}/#{content}")
|
||||||
|
return '[No Info]'.colorize(:red) + ' ' * (39 + @userlength + @grouplength)
|
||||||
|
end
|
||||||
stat = File.stat("#{@input}/#{content}")
|
stat = File.stat("#{@input}/#{content}")
|
||||||
"#{mode_info(stat)} #{user_info(stat)} #{group_info(stat)} #{size_info(stat)} #{mtime_info(stat)} "
|
[mode_info(stat), user_info(stat), group_info(stat), size_info(stat), mtime_info(stat)].join(' ')
|
||||||
|
end
|
||||||
|
|
||||||
|
def symlink_info(content)
|
||||||
|
return '' unless @long && File.lstat("#{@input}/#{content}").symlink?
|
||||||
|
if File.exist?("#{@input}/#{content}")
|
||||||
|
" ⇒ #{File.readlink("#{@input}/#{content}")}/".colorize(:cyan)
|
||||||
|
else
|
||||||
|
' ⇒ [Dead link]'.colorize(:red)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def slash?(content)
|
||||||
|
Dir.exist?("#{@input}/#{content}") ? '/'.colorize(:blue) : ' '
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_string(content, key, color, increment)
|
def fetch_string(content, key, color, increment)
|
||||||
|
@ -219,7 +238,11 @@ module ColorLS
|
||||||
value = increment == :folders ? @folders[key] : @files[key]
|
value = increment == :folders ? @folders[key] : @files[key]
|
||||||
logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..-1].to_i(16)].pack('U') }
|
logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..-1].to_i(16)].pack('U') }
|
||||||
|
|
||||||
"#{@long ? long_info(content) : ''} #{logo.colorize(color)} #{content.colorize(color)}"
|
[
|
||||||
|
long_info(content),
|
||||||
|
logo.colorize(color),
|
||||||
|
"#{content.colorize(color)}#{slash?(content)}#{symlink_info(content)}"
|
||||||
|
].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_from_yaml(filename, aliase=false)
|
def load_from_yaml(filename, aliase=false)
|
||||||
|
@ -239,7 +262,7 @@ module ColorLS
|
||||||
|
|
||||||
print " #{fetch_string(content, *options(@input, content))}"
|
print " #{fetch_string(content, *options(@input, content))}"
|
||||||
print Dir.exist?("#{@input}/#{content}") ? '/'.colorize(:blue) : ' '
|
print Dir.exist?("#{@input}/#{content}") ? '/'.colorize(:blue) : ' '
|
||||||
print ' ' * (@max_widths[i] - content.length)
|
print ' ' * (@max_widths[i] - content.length) unless @one_per_line || @long
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
1
spec/fixtures/symlinks/ReadmeLink.md
vendored
Symbolic link
1
spec/fixtures/symlinks/ReadmeLink.md
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../../README.md
|
1
spec/fixtures/symlinks/Supportlink
vendored
Symbolic link
1
spec/fixtures/symlinks/Supportlink
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../support
|
1
spec/fixtures/symlinks/doesnotexisttest.txt
vendored
Symbolic link
1
spec/fixtures/symlinks/doesnotexisttest.txt
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
thisfiledoesnotexist
|
Loading…
Reference in a new issue