daler / dotfiles

dotfiles, batteries included
https://daler.github.io/dotfiles/
19 stars 13 forks source link

Update .path and setup.sh --conda-env for macos ls #35

Closed rhodesch closed 10 months ago

rhodesch commented 10 months ago

See #33. On macos with coreutils installed into base conda environment, minor changes to files to improve ls color consistency.

Tested conditions:

Follow .setup.sh RECOMMENDED ORDER with minimal changes:

    1)  ./setup.sh --dotfiles
    2)  ./setup.sh --install-neovim
    3)  ./setup.sh --install-conda
    4)  ./setup.sh --set-up-bioconda
    5) CLOSE TERMINAL, OPEN A NEW ONE
    Optional:
       conda config --set ssl_verify /asbolute/path/to/CA.crt
    6) Open vim (which should now be aliased to nvim) and allow plugins to install, then quit
    7)  ./setup.sh --install-fzf
    8)  ./setup.sh --install-ripgrep
    9)  ./setup.sh --install-vd
    10) ./setup.sh --install-pyp
    11) ./setup.sh --install-fd

  On Mac:
       ./setup.sh --mac-stuff
       # ./setup.sh --install-tmux    # skip
       ./setup.sh --conda-env    # requirements.txt empty for testing
  On Linux:
       ./setup.sh --conda-env    # requirements.txt empty for testing

old ls behavior on mac (not tested on linux):

la    # no conda activated, ls -G colors
ca fd
la    # ls -G colors
conda_deactivate_all
la    # ls -G colors
ca
la    # no term colors
conda activate $HOME/mambaforge/envs/pyp
la    # ls -G colors
ca
la    # no term colors
source ~/.bashrc
la    # alias ls='ls --color=auto'

new ls behavior on mac and linux:

la    # no conda activated, alias ls='ls --color=auto'
ca fd
la    # alias ls='ls --color=auto'
conda_deactivate_all
la    # alias ls='ls --color=auto'
ca
la    # alias ls='ls --color=auto'
conda activate $HOME/mambaforge/envs/pyp
la    # alias ls='ls --color=auto'
ca
la    # alias ls='ls --color=auto'
source ~/.bashrc    # not needed, adding for consistency
la    # alias ls='ls --color=auto'; which ls: $HOME/mambaforge/bin/ls
sa    # visidata
daler commented 10 months ago

Thanks, good point and thanks for the fix.

I'm not sure I want to introduce this additional complexity. The solution here strictly requires the conda installation location to be correct (which is likely to change yet again as conda now includes libmamba) and requires coreutils to have been installed. And all of this happens at setup time.

After going down a bit of a rabbit hole just now, I found out that to configure colors for the BSD ls, you can use LSCOLORS. This is from the man page but also https://superuser.com/a/1746907 which refers to https://geoff.greer.fm/lscolors. That latter web tool takes both dircolors (Linux LS_COLORS, note the underscore) as well as BSD LSCOLORS (no underscore).

It turns out you can largely match dircolors with built-in /bin/ls: first activate an env with dircolors (e.g., ca), then run dircolors, then paste the value of dircolors-reported LS_COLORS into that web tool. It reports that the LSCOLORS equivalent is exGxBxDxCxEgEdxbxgxcxd.

So if you do export LSCOLORS=exGxBxDxCxEgEdxbxgxcxd and then /bin/ls -G, the colors look reasonable.

I noticed that the web tool wasn't making directories bold like dircolors was, so I changed it to export LSCOLORS=ExGxBxDxCxEgEdxbxgxcx (note capital "E" at the beginning).

That is, in .aliases, use:

if [[ $OSTYPE == darwin* ]]; then
    export LSCOLORS=ExGxBxDxCxEgEdxbxgxcxd
    alias ls='/bin/ls -G'
else
    if [ `command -v dircolors` ]; then
        test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    fi
    alias ls='ls --color=auto'
fi

The main limitation here is that some colors created from the more complete dircolors configuration do not show up in a different color. For me, most notably that means compressed files and image files don't show up in a different color.

So I think the decision boils down to, "are the colors of other files (like compressed files and images) important?".

If not, then I think exporting LSCOLORS makes the ls output mostly similar to coreutils ls and fixes #33. If colors of other files are important, we should continue looking for a good solution here.

I could go either way, but currently leaning towards simplicity and solving 80% of the problem with LSCOLORS.

Thoughts?

rhodesch commented 10 months ago

Thanks - I also prefer your option, which fixes #33

Updating the conditional block in .aliases with your code above makes colors mostly consistent, which seems more important than colorizing all files. Completely agree that it's best to avoid requiring conda installation location to be correct.

If the related issue and this PR are not closed by end of week, I can close.

daler commented 10 months ago

Thanks for the discussion, this is now addressed in #36.