exa icon indicating copy to clipboard operation
exa copied to clipboard

No -A switch

Open eggbean opened this issue 5 years ago • 13 comments

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 as ls -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.

eggbean avatar May 02 '19 12:05 eggbean

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.

PiotrZierhoffer avatar Oct 22 '19 14:10 PiotrZierhoffer

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'

Update

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.

steshaw avatar Feb 05 '20 04:02 steshaw

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?

mversic avatar Apr 03 '20 17:04 mversic

@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 avatar Apr 07 '20 04:04 eggbean

@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.

steshaw avatar Apr 07 '20 05:04 steshaw

it is not that easy if you are used to use ll -ltr, and ls itself is an alias to ls -lhF.

bmarwell avatar Apr 07 '20 05:04 bmarwell

@bmhm you can redefine the ll alias.

steshaw avatar Apr 07 '20 05:04 steshaw

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.

bmarwell avatar Apr 07 '20 09:04 bmarwell

@steshaw Thanks!

eggbean avatar Apr 07 '20 13:04 eggbean

@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} "$@"

steshaw avatar Apr 07 '20 23:04 steshaw

Not only the muscle memory, but also many scripts call ls -A.

Example:

https://github.com/postmodern/chruby/blob/824db2625aa78d1bce2fd25c2fc9be76f161b332/share/chruby/chruby.sh#L5

Shall we try a PR? I assume @ogham isn’t strongly objective to this feature, just not having the time to implement it.

FranklinYu avatar May 25 '20 07:05 FranklinYu

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.

ariasuni avatar Jan 01 '21 14:01 ariasuni

Someone created a PR for this a few months ago: https://github.com/ogham/exa/pull/1064

viseztrance avatar Aug 22 '22 12:08 viseztrance