Repository: eza-community/eza (language: rust)

Issue:
bug: -X/--dereference was broken and no longer working for filenames
Hi!

I found some really inconsystem behaviour when listing symlinks. 
```
$ [[ -L .steampath ]] && echo true
true

$ eza .steampath
.steampath

$ echo "$(eza .steampath)"
.steampath -> /home/vosje/.steam/sdk32/steam

$ echo "$(eza --dereference .steampath)"
.steampath -> /home/vosje/.steam/sdk32/steam

$ echo "$(eza -l --dereference .steampath)"
---------- - - - .steampath -> /home/vosje/.steam/sdk32/steam

$ echo "$(eza -1 --dereference .steampath)"
.steampath -> /home/vosje/.steam/sdk32/steam

$ echo "$(eza -G --dereference .steampath)"
.steampath -> /home/vosje/.steam/sdk32/steam
```

It seems like eza does not care at all about the `-X`/`--dereference` option when output is redirected, does not matter what the mode is. It also does not care about `-X` when in one of the listing modes, or in tree mode. In grid mode it does not list symlink targets at all, but I do understand it doing not it there. But when forced in grid mode with `-GX` it does give a link target, which grid mode did not do before.

In case this is intended behaviour, why is the `-X` option there? Because then it would serve no purpose as far as I know.
*later addition: it seems like -X does more than remove the target, or rather, it does something different than removing the target listing. So how would I then remove the `-> target` part? On `ls` that is `--dereference`.*

I am using `eza` version `v0.18.9 [+git]` (from the AUR). I am running arch linux.

So what I would like to see fixed, is the `-X` option accually getting respected. It seems to do nothing: it is not respected in list, long or tree modes, in grid mode there is no target listed in the first place, and when output is redirected it does not do anything at all.



Discussion / hints:
This needs to be tested thoroughly, but I think you got a point here. 
> This needs to be tested thoroughly

If I can help with anything, just let me know. Just note I have never writen any rust, but I can do testing.
> If I can help with anything, just let me know. Just note I have never writen any rust, but I can do testing.

test exemples like a directory or at least files tests so that i could narrow down your problems 
[![asciicast](https://asciinema.org/a/NxvupCEgBjRgV5IkUhY0SCpaS.svg)](https://asciinema.org/a/NxvupCEgBjRgV5IkUhY0SCpaS)

<details>
<summary>Commands (expand)</Summary>

```bash
# make files
touch file1
mkdir directory

eza

# make symlinks
ln -s file1 symlink_to_file1
ln -s file2 symlink_to_file2 # file2 does not exists; orphaned symlink
ln -s directory symlink_to_directory

eza

# correct behaviour
eza -G symlink_* # should not give link targets
eza -l symlink_* # should give link targets

# incorrect behaviour
eza -l -X symlink_* # should not give link targets
eza -1 -X symlink_* # should not give link targets

# correct behaviour (output redirected)
echo "$(eza -l symlink_*)" # list; should give link targets
echo "$(eza -1 symlink_*)" # list; should give link targets

# incorrect behaviour (output redirected)
echo "$(eza -G symlink_*)" # grouped display, should not give link targets
echo "$(eza -l -X symlink_*)" # -X given, should not give link targets
echo "$(eza -1 -X symlink_*)" # -X given, should not give link targets
```

</details>

<details>
<summary>Terminal session from cast (expand)</summary>

```
> # make files
touch file1
mkdir directory
> eza
directory  file1
> # make symlinks
ln -s file1 symlink_to_file1
ln -s file2 symlink_to_file2 # file2 does not exists; orphaned symlink
ln -s directory symlink_to_directory
> eza
directory  file1  symlink_to_directory  symlink_to_file1  symlink_to_file2
> # correct behaviour
> eza -G symlink_* # should not give link targets
symlink_to_file1  symlink_to_file2

symlink_to_directory:
> eza -l symlink_* # should give link targets
lrwxrwxrwx - vosje 17 Apr 20:17 symlink_to_file1 -> file1
lrwxrwxrwx - vosje 17 Apr 20:17 symlink_to_file2 -> file2

symlink_to_directory:
> # incorrect behaviour
> eza -l -X symlink_* # should not give link targets
lrw-r--r-- 0 vosje 17 Apr 20:17 symlink_to_file1 -> file1
---------- - -     -            symlink_to_file2 -> file2

symlink_to_directory:
> # this gives the targets: symlink_to_file1 -> file1
> eza -1 -X symlink_* # should not give link targets
symlink_to_file1 -> file1
symlink_to_file2 -> file2

symlink_to_directory:
> # that one as well
> # correct behaviour (output redirected)
> echo "$(eza -l symlink_*)" # list; should give link targets
lrwxrwxrwx - vosje 17 Apr 20:17 symlink_to_file1 -> file1
lrwxrwxrwx - vosje 17 Apr 20:17 symlink_to_file2 -> file2

symlink_to_directory:
> echo "$(eza -1 symlink_*)" # list; should give link targets
symlink_to_file1 -> file1
symlink_to_file2 -> file2

symlink_to_directory:
> # incorrect behaviour (output redirected)
> # nothing here should show link targets: grouped should not, list and other list should not because of -X
> echo "$(eza -G symlink_*)" # grouped display, should not give link targets
symlink_to_file1 -> file1
symlink_to_file2 -> file2

symlink_to_directory:
> echo "$(eza -l -X symlink_*)" # -X given, should not give link targets
lrw-r--r-- 0 vosje 17 Apr 20:17 symlink_to_file1 -> file1
---------- - -     -            symlink_to_file2 -> file2

symlink_to_directory:
> echo "$(eza -1 -X symlink_*)" # -X given, should not give link targets
symlink_to_file1 -> file1
symlink_to_file2 -> file2

symlink_to_directory:
> # however all do. Grouped display even shows in list mode instead (the one without info)
```

</details>

Sorry if this is not clear, if I need to clarify anything I did here, please ask.
Thanks this seems perfect gonna take a deep dive when I have a bit of time

Fix patch:
diff --git a/src/fs/file.rs b/src/fs/file.rs
index ca0be62b5..ba2703d91 100644
--- a/src/fs/file.rs
+++ b/src/fs/file.rs
@@ -135,6 +135,8 @@ impl<'dir> File<'dir> {
             RecursiveSize::None
         };
 
+        debug!("deref_links {}", deref_links);
+
         let mut file = File {
             name,
             ext,
diff --git a/src/output/details.rs b/src/output/details.rs
index f7e0bc0e0..2ff581141 100644
--- a/src/output/details.rs
+++ b/src/output/details.rs
@@ -328,6 +328,8 @@ impl<'a> Render<'a> {
                 .paint()
                 .promote();
 
+            debug!("file_name {:?}", file_name);
+
             let row = Row {
                 tree: tree_params,
                 cells: egg.table_row,
diff --git a/src/output/file_name.rs b/src/output/file_name.rs
index 30c88a93c..313f26455 100644
--- a/src/output/file_name.rs
+++ b/src/output/file_name.rs
@@ -162,7 +162,9 @@ impl<'a, 'dir, C> FileName<'a, 'dir, C> {
     /// Sets the flag on this file name to display link targets with an
     /// arrow followed by their path.
     pub fn with_link_paths(mut self) -> Self {
-        self.link_style = LinkStyle::FullLinkPaths;
+        if !self.file.deref_links {
+            self.link_style = LinkStyle::FullLinkPaths;
+        }
         self
     }
 


Test patch: