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,
};
let target = FileName {
let target_name = FileName {
file: target,
colours: self.colours,
target: None,
@ -181,9 +181,15 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
options: target_options,
};
for bit in target.coloured_file_name() {
for bit in target_name.coloured_file_name() {
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 {
if let Some(class) = self.classify_char() {
if let Some(class) = self.classify_char(self.file) {
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 files type has one associated with it.
fn classify_char(&self) -> Option<&'static str> {
if self.file.is_executable_file() {
fn classify_char(&self, file: &File<'_>) -> Option<&'static str> {
if file.is_executable_file() {
Some("*")
}
else if self.file.is_directory() {
else if file.is_directory() {
Some("/")
}
else if self.file.is_pipe() {
else if file.is_pipe() {
Some("|")
}
else if self.file.is_link() {
else if file.is_link() {
Some("@")
}
else if self.file.is_socket() {
else if file.is_socket() {
Some("=")
}
else {

View File

@ -43,3 +43,11 @@ stdout = { file = "outputs/specials_long_classify.ansitxt" }
stderr = { empty = true }
status = 0
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/