lsd icon indicating copy to clipboard operation
lsd copied to clipboard

git integration: hide when not listing files in a Git repository

Open Jackenmen opened this issue 2 years ago • 1 comments

Discussed in https://github.com/orgs/lsd-rs/discussions/846

Originally posted by Jackenmen May 26, 2023 Right now, enabling git column causes it to show in all directory listings, regardless of whether we're listing files inside a Git repository or not. In comparison, exa only shows the Git column when running it inside a directory that is part of a Git repository (i.e. inside ~/git-repo and ~/git-repo/subdir but not inside ~). I think that exa is better in this regard - it minimizes the clutter that isn't relevant when not run in a repository.

One potential edge case that you may want to handle is tree display mode where only part of a tree might be part of a Git repository. However, neither exa nor lsd currently shows the proper status on subdirectories that are git repositories so it would be fine to simply not show the git information at all.

Jackenmen avatar May 27 '23 17:05 Jackenmen

I have rewritten my alias, such that it does that for me, until it lands. The relevant part is (it might require you to redefine the whole blocks configuration in the alias, I'm not using a config file and haven't tested whether this option will be appended or overwrite the entire blocks config):

# fish
alias ls='ls -l (test -d .git; and echo "--blocks git")'
# bash
alias ls='lsd -l $([ -d .git ] && echo "--blocks git")'

ohcibi avatar Jul 24 '24 07:07 ohcibi