ogham / exa

A modern replacement for ‘ls’.
https://the.exa.website/
MIT License
23.68k stars 659 forks source link

FR: Respect environment variables GIT_DIR and GIT_WORK_TREE #722

Open jonathf opened 4 years ago

jonathf commented 4 years ago

Thanks for creating such an awesome upgrade to the ls command!

I use git-bare to manage my dotfiles: https://www.atlassian.com/git/tutorials/dotfiles TL;DR we change git-dir and git-work-tree so $HOME acts as repo root in a more elegant way.

I'd like to get exa working with this setup for its --git flag (using a function wrapper). Would it be possible to let exa read GIT_DIR and GIT_WORK_TREE and pass them to git when they exists and where appropriate?

ariasuni commented 3 years ago

Why the FR in the title?

It seems possible to respect GIT_DIR since it’s mentioned in git2-rs documentation: https://docs.rs/git2/0.13.15/git2/struct.Repository.html#method.open_from_env

And it’s totally possible to have GIT_WORK_TREE points to a git repository that exa could use.

jonathf commented 3 years ago

Because I consider this a "feature request". But I can remove it if it is a bad fit for the issue or if I a misunderstood what FR means here.

Yes I imagined it would be possible. However I am not a rust-dev, so I have no idea how complicated sych a feature will be.

iamkroot commented 2 years ago

+1 on this, with the same usecase.

Will try to raise a PR if I get time

iamkroot commented 2 years ago

1141 solves this.

Note that I'm seeing very long delays to output (almost 3-4 seconds) when GIT_DIR points to my dotfiles repo. This is probably a libgit slowness issue because that repo is quite large, and the delays disappear on a small repo.

jonathf commented 2 years ago

Awesome! This would be great to have merged.

@iamkroot, Will this also respect GIT_WORK_TREE?

iamkroot commented 2 years ago

@iamkroot, Will this also respect GIT_WORK_TREE?

Probably not. libgit does not seem to support this according to the flag documentation.

  • In the future, this flag will also cause git_repository_open_ext
    • to respect $GIT_WORK_TREE and $GIT_COMMON_DIR; currently,
    • git_repository_open_ext with this flag will error out if either
    • $GIT_WORK_TREE or $GIT_COMMON_DIR is set.
jonathf commented 2 years ago

Okay thanks. I should be able to make something work with that.

eggbean commented 2 years ago

So with https://github.com/ogham/exa/pull/1141 you can use something like direnv and a .envrc file like...

export GIT_DIR=$HOME/.cfg
export GIT_WORK_TREE=$HOME

...and the exa's git column will work in bare repositories?