mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-05 05:21:16 +02:00
Merge pull request #595 from ayushpoddar/color-hidden-files
Colorise hidden files and directories
This commit is contained in:
commit
597a8c6807
6 changed files with 43 additions and 17 deletions
|
@ -407,6 +407,7 @@ module ColorLS
|
|||
when file.blockdev? then :blockdev
|
||||
when file.socket? then :socket
|
||||
when file.executable? then :executable_file
|
||||
when file.hidden? then :hidden
|
||||
when @files.key?(key) then :recognized_file
|
||||
else :unrecognized_file
|
||||
end
|
||||
|
@ -415,20 +416,32 @@ module ColorLS
|
|||
|
||||
def options(content)
|
||||
if content.directory?
|
||||
key = content.name.downcase.to_sym
|
||||
key = @folder_aliases[key] unless @folders.key? key
|
||||
key = :folder if key.nil?
|
||||
color = @colors[:dir]
|
||||
group = :folders
|
||||
options_directory(content).values_at(:key, :color, :group)
|
||||
else
|
||||
key = File.extname(content.name).delete_prefix('.').downcase.to_sym
|
||||
key = @file_aliases[key] unless @files.key? key
|
||||
color = file_color(content, key)
|
||||
group = @files.key?(key) ? :recognized_files : :unrecognized_files
|
||||
key = :file if key.nil?
|
||||
options_file(content).values_at(:key, :color, :group)
|
||||
end
|
||||
end
|
||||
|
||||
[key, color, group]
|
||||
def options_directory(content)
|
||||
key = content.name.downcase.to_sym
|
||||
key = @folder_aliases[key] unless @folders.key?(key)
|
||||
key = :folder if key.nil?
|
||||
|
||||
color = content.hidden? ? @colors[:hidden_dir] : @colors[:dir]
|
||||
|
||||
{key: key, color: color, group: :folders}
|
||||
end
|
||||
|
||||
def options_file(content)
|
||||
key = File.extname(content.name).delete_prefix('.').downcase.to_sym
|
||||
key = @file_aliases[key] unless @files.key?(key)
|
||||
|
||||
color = file_color(content, key)
|
||||
group = @files.key?(key) ? :recognized_files : :unrecognized_files
|
||||
|
||||
key = :file if key.nil?
|
||||
|
||||
{key: key, color: color, group: group}
|
||||
end
|
||||
|
||||
def tree_contents(path)
|
||||
|
|
|
@ -40,6 +40,10 @@ module ColorLS
|
|||
@dead
|
||||
end
|
||||
|
||||
def hidden?
|
||||
@name.start_with?('.')
|
||||
end
|
||||
|
||||
def owner
|
||||
return @@users[@stats.uid] if @@users.key? @stats.uid
|
||||
|
||||
|
|
|
@ -9,9 +9,11 @@ dead_link: red
|
|||
link: cyan
|
||||
|
||||
# special files
|
||||
socket: green
|
||||
blockdev: green
|
||||
chardev: green
|
||||
socket: green
|
||||
blockdev: green
|
||||
chardev: green
|
||||
hidden: burlywood
|
||||
hidden_dir: slategray
|
||||
|
||||
# Access Modes
|
||||
write: darkkhaki
|
||||
|
|
|
@ -9,9 +9,11 @@ dead_link: red
|
|||
link: cyan
|
||||
|
||||
# special files
|
||||
socket: darkgray
|
||||
blockdev: darkgray
|
||||
chardev: darkgray
|
||||
socket: darkgray
|
||||
blockdev: darkgray
|
||||
chardev: darkgray
|
||||
hidden: seagreen
|
||||
hidden_dir: royalblue
|
||||
|
||||
# Access Modes
|
||||
write: red
|
||||
|
|
|
@ -25,6 +25,7 @@ RSpec.describe ColorLS::Core do
|
|||
chardev?: false,
|
||||
socket?: false,
|
||||
symlink?: false,
|
||||
hidden?: false,
|
||||
stats: instance_double(File::Stat,
|
||||
mode: 0o444, # read for user, owner, other
|
||||
setuid?: false,
|
||||
|
@ -47,6 +48,7 @@ RSpec.describe ColorLS::Core do
|
|||
chardev?: false,
|
||||
socket?: false,
|
||||
symlink?: false,
|
||||
hidden?: false,
|
||||
stats: instance_double(File::Stat,
|
||||
mode: 0o444, # read for user, owner, other
|
||||
setuid?: false,
|
||||
|
@ -77,6 +79,7 @@ RSpec.describe ColorLS::Core do
|
|||
chardev?: false,
|
||||
socket?: false,
|
||||
symlink?: false,
|
||||
hidden?: true,
|
||||
executable?: false
|
||||
)
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ RSpec.describe ColorLS::Flags do
|
|||
chardev?: false,
|
||||
socket?: false,
|
||||
symlink?: false,
|
||||
hidden?: false,
|
||||
stats: instance_double(File::Stat,
|
||||
mode: 0o444, # read for user, owner, other
|
||||
setuid?: true,
|
||||
|
@ -467,6 +468,7 @@ RSpec.describe ColorLS::Flags do
|
|||
chardev?: false,
|
||||
socket?: false,
|
||||
symlink?: true,
|
||||
hidden?: false,
|
||||
link_target: "#{FIXTURES}/z.txt",
|
||||
dead?: false,
|
||||
executable?: false
|
||||
|
|
Loading…
Reference in a new issue