Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ls.fish is not setting the --color=auto option #9

Open
frederickjh opened this issue Apr 3, 2020 · 5 comments
Open

ls.fish is not setting the --color=auto option #9

frederickjh opened this issue Apr 3, 2020 · 5 comments

Comments

@frederickjh
Copy link
Contributor

I noticed that on remote host the ls directory listing were not in color.

In hunting this down I found that fish has a wrapper function for ls called ls.fish. On a remote host doing: functions ls return nothing, but it should return the location and code of the function. I built fish-portable from its repository following the instructions to get it running and then do:

$ functions ls
# Defined in /tmp/fish/share/fish/functions/ls.fish @ line 13
function ls --description 'List contents of directory'
    set -l opt --color=auto
            isatty stdout
            and set -a opt -F
            command ls $opt $argv
end

If I create a ls.fish function in the functions folder and then run ls the directory listings are back in color.

Any idea as to whether ls.fish is being included in portable-fish or if it is just not finding it for some reason?

@frederickjh
Copy link
Contributor Author

Here is .xxh/.xxh/shells/xxh-shell-fish/build/fish-portable/share/fish/functions/ls.fish

#
# Make ls use colors and show indicators if we are on a system that supports that feature and writing to stdout.
#

# BSD, macOS and others support colors with ls -G.
# GNU ls and FreeBSD ls takes --color=auto. Order of this test is important because ls also takes -G but it has a different meaning.
# Solaris 11's ls command takes a --color flag.
# Also test -F because we'll want to define this function even with an ls that can't do colors (like NetBSD).

for opt in --color=auto -G --color -F
    if command ls $opt / >/dev/null 2>/dev/null

        function ls --description "List contents of directory" -V opt
            isatty stdout
            and set -a opt -F
            command ls $opt $argv
        end

        if [ $opt = --color=auto ] && ! set -qx LS_COLORS && set -l cmd (command -s {g,}dircolors)[1]
            set -l colorfile
            for file in ~/.dir_colors ~/.dircolors /etc/DIR_COLORS
                if test -f $file
                    set colorfile $file
                    break
                end
            end
            # Here we rely on the legacy behavior of `dircolors -c` producing output
            # suitable for csh in order to extract just the data we're interested in.
            set -gx LS_COLORS ($cmd -c $colorfile | string split ' ')[3]
            # The value should always be quoted but be conservative and check first.
            if string match -qr '^([\'"]).*\1$' -- $LS_COLORS
                set LS_COLORS (string match -r '^.(.*).$' $LS_COLORS)[2]
            end
        end

        break
    end
end

This comment may help in figuring this out. $LS_COLORS should be defined the first time and a different ls.fish created. See the block of code that starts function ls. That is the function that should be create on the first run.

@frederickjh
Copy link
Contributor Author

frederickjh commented Apr 3, 2020

It looks like the ls.fish function that is created by the bigger ls.fish (above) is not written to disk, but when functions ls is run it appears to be in the users functions directory. Creating a ls.fish with the function created in the above function:

function ls --description "List contents of directory" -V opt
  isatty stdout
  and set -a opt -F
  command ls $opt $argv
end

in the users functions directory causes it to work and color directory listings.

@frederickjh
Copy link
Contributor Author

frederickjh commented Apr 3, 2020

Actually the the ls.fish that works is different. I copied the one from my computer to the remote.

function ls --description 'List contents of directory'
set -l opt --color=auto
  isatty stdout
  and set -a opt -F
  command ls $opt $argv
end

Note the -V opt that is missing from the end of the first line and the missing second line set -l opt --color=auto that is setting color to auto.

@anki-code
Copy link
Member

anki-code commented Apr 3, 2020

Are you trying to compare the same fish versions? xxh-shell-fish has fish 3.1.0 version. What is your local version?

@frederickjh frederickjh changed the title ls.fish seems to be missing or not in path ls.fish is not setting the --color=auto option Apr 3, 2020
@frederickjh
Copy link
Contributor Author

I changed the title, as ls.fish is present. There seems to be something in its logic that does not work with the portable setup. It is a bit complicated as the Fish shell programmers were trying to accommodate three different versions of ls.

Are you trying to compare the same fish versions? xxh-shell-fish has fish 3.1.0 version. What is your local version?

The local version is exactly the same 3.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants