Skip to content

Commit

Permalink
Add classify char to symlink targets
Browse files Browse the repository at this point in the history
Fixes GH-589.
  • Loading branch information
ogham committed Apr 12, 2021
1 parent b1c4934 commit dbd11d3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/output/file_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,23 @@ 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,
link_style: LinkStyle::FullLinkPaths,
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));
}
}
}
}

Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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 file’s 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 {
Expand Down
8 changes: 8 additions & 0 deletions xtests/details-view.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
10 changes: 10 additions & 0 deletions xtests/outputs/links_long_classify.ansitxt
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit dbd11d3

Please sign in to comment.