Add classify char to symlink targets

Fixes GH-589.
This commit is contained in:
Benjamin Sago 2021-04-12 22:02:30 +01:00
parent b1c49341c0
commit dbd11d3804
3 changed files with 33 additions and 9 deletions

View File

@ -173,7 +173,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
show_icons: ShowIcons::Off, show_icons: ShowIcons::Off,
}; };
let target = FileName { let target_name = FileName {
file: target, file: target,
colours: self.colours, colours: self.colours,
target: None, target: None,
@ -181,9 +181,15 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
options: target_options, options: target_options,
}; };
for bit in target.coloured_file_name() { for bit in target_name.coloured_file_name() {
bits.push(bit); bits.push(bit);
} }
if let Classify::AddFileIndicators = self.options.classify {
if let Some(class) = self.classify_char(target) {
bits.push(Style::default().paint(class));
}
}
} }
} }
@ -206,7 +212,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
} }
} }
else if let Classify::AddFileIndicators = self.options.classify { else if let Classify::AddFileIndicators = self.options.classify {
if let Some(class) = self.classify_char() { if let Some(class) = self.classify_char(self.file) {
bits.push(Style::default().paint(class)); bits.push(Style::default().paint(class));
} }
} }
@ -235,20 +241,20 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
/// The character to be displayed after a file when classifying is on, if /// The character to be displayed after a file when classifying is on, if
/// the files type has one associated with it. /// the files type has one associated with it.
fn classify_char(&self) -> Option<&'static str> { fn classify_char(&self, file: &File<'_>) -> Option<&'static str> {
if self.file.is_executable_file() { if file.is_executable_file() {
Some("*") Some("*")
} }
else if self.file.is_directory() { else if file.is_directory() {
Some("/") Some("/")
} }
else if self.file.is_pipe() { else if file.is_pipe() {
Some("|") Some("|")
} }
else if self.file.is_link() { else if file.is_link() {
Some("@") Some("@")
} }
else if self.file.is_socket() { else if file.is_socket() {
Some("=") Some("=")
} }
else { else {

View File

@ -43,3 +43,11 @@ stdout = { file = "outputs/specials_long_classify.ansitxt" }
stderr = { empty = true } stderr = { empty = true }
status = 0 status = 0
tags = [ 'long', 'classify' ] tags = [ 'long', 'classify' ]
[[cmd]]
name = "exa -lF handles and classifies symlink kinds"
shell = "exa -lF --no-time /testcases/links"
stdout = { file = "outputs/links_long_classify.ansitxt" }
stderr = { empty = true }
status = 0
tags = [ 'long', 'classify' ]

View File

@ -0,0 +1,10 @@
lrwxrwxrwx 7 vagrant broken -> nowhere
lrwxrwxrwx 1 vagrant current_dir -> ./
lrwxrwxrwx 12 vagrant forbidden -> /proc/1/root
lrwxrwxrwx 6 vagrant itself -> itself
lrwxrwxrwx 2 vagrant parent_dir -> ../
lrwxrwxrwx 1 vagrant root -> //
.rw-rw-r-- 0 vagrant some_file
lrwxrwxrwx 26 vagrant some_file_absolute -> /testcases/links/some_file
lrwxrwxrwx 9 vagrant some_file_relative -> some_file
lrwxrwxrwx 4 vagrant usr -> /usr/