Open eggbean opened 5 years ago
Not only the muscle memory, but also many scripts call ls -A
. Lack of this switch, indeed, makes aliasing ls to exa a bit problematic.
I'm loving exa! It would be really nice to have -a
and -A
as in GNU/BSD ls
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
I occasionally use ls -al
when wanting to view the .
directory (in particular).
With GNU ls, I set up the following aliases (which are a little different to the ones typically set up in /etc/bashrc
):
alias ls='ls --color --classify'
alias l='ls -l --human-readable'
alias ll='l --almost-all' # and prefer -A to -a. Don't need '.' and '..' often.
alias la='l --all'
I can't find a way to do similarly with exa. AFAICT, I must fallback to GNU ls:
alias ls='exa --classify'
alias l='ls --long'
alias ll='l --all'
# Fallback to GNU ls.
alias la='\ls --color --classify -l --human-readable --all'
I've discovered that --all
is equivalent to --almost-all
and that --all --all
is equivalent to GNU --all
. So, I am able to define my la
alias as:
alias la='ll --all'
which expands to exa --classify --long --all --all
I found the reference to the repeated --all
option in this comment. It appears to be undocumented.
This makes me happy 😃.
@eggbean, a way around your muscle-memory predicament is to write a little ls-wrapper that takes GNU ls style arguments and converts then to exa
ones... or get used to using a set of aliases like I do. I can switch between GNU ls, BSD ls
, lsd
, and now exa
depending on what's available and my current preference.
the first thing I tried was alias ls=exa
because I want to keep typing ls
and didn't want to go through the hassle of changing my aliases like la=ls -lhAF
.
I wonder what is the reason for not conforming to the GNU ls style arguments? It would help having exa as a drop-in replacement for GNU ls. Is it a parsing issue?
@steshaw It looks like this alias is not being added, so could you explain how to make this wrapper, please?
I've actually been waiting for you to appear online on freenode so that I could ask you, ha.
@eggbean I don't log into freenode very often.
You can write your wrapper in any language. You can knock something up in Bash like:
#!/usr/bin/env bash
set -euo pipefail
exa_opts=""
while getopts 'ahlA' o; do
case $o in
a) exa_opts="${exa_opts} -a -a" ;;
A) exa_opts="${exa_opts} -a" ;;
h|l) exa_opts="${exa_opts} -${o}" ;;
?) echo "usage: exa-wrapper ..."
exit 2
;;
esac
done
shift $((OPTIND - 1))
exa -Bg ${exa_opts} "$@"
I've added your -Bg
arguments that you like to emulate ls. You'd need to embellish that with other options from ls that you use.
Then put exa-wrapper
on your path and do alias ls=exa-wrapper
.
it is not that easy if you are used to use ll -ltr
, and ls itself is an alias to ls -lhF
.
@bmhm you can redefine the ll
alias.
ll -ltr
would still fail if I just replace the alias.
ll -tlr
or ll -l -t -r
would be hard to capture with a bash wrapper script.
exa is a modern replacement for the command-line program
ls
This makes it not a drop-in replacement. But exa
never claimed this. So, getting back to the original question: This is not an issue, only a question. And this question is solved:
Update I've discovered that --all is equivalent to --almost-all and that --all --all is equivalent to GNU --all.
LGTM.
@steshaw Thanks!
@bmhm for your use case, you have to embellish the above script to implement the -t
option. It looks like the following works:
#!/usr/bin/env bash
set -euo pipefail
exa_opts=""
while getopts 'ahlrtAF' o; do
case $o in
a) exa_opts="${exa_opts} -a -a" ;;
A) exa_opts="${exa_opts} -a" ;;
h) ;;
t) exa_opts="${exa_opts} --sort oldest" ;;
l|r|F) exa_opts="${exa_opts} -${o}" ;;
?) echo "usage: exa-wrapper ..."
exit 2
;;
esac
done
shift $((OPTIND - 1))
exa -Bg ${exa_opts} "$@"
Not only the muscle memory, but also many scripts call
ls -A
.
Example:
Shall we try a PR? I assume @ogham isn’t strongly objective to this feature, just not having the time to implement it.
I’m not sure if anyone has realized that exa -laa
is equivalent to exa -l --all -all
. Anyway, I don’t see why -A
shouldn’t be supported as well.
There’s a lot to do on exa’s side so I can’t promise I’ll have the time to implement that soon, but I think I would merge a PR which does.
Someone created a PR for this a few months ago: https://github.com/ogham/exa/pull/1064
I like exa, but I use it with a
alias ls='exa -Bg'
, to act more like ls.The problem is that I have a decade of muscle memory typing
ls -lA
.I know that exa's
-la
switch works in the same way asls -lA
, as it doesn't include the current and parent dot directories, but I think it would be cool if the -A switch was included as an alias for -a, just for compatibility and people like me.