Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(alias): ls alias lx is an illegal option on darwin bsd style ls #1752

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion modules/utility/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,17 @@ alias ll='ls -lh' # Lists human readable sizes.
alias lr='ll -R' # Lists human readable sizes, recursively.
alias la='ll -A' # Lists human readable sizes, hidden files.
alias lm='la | "$PAGER"' # Lists human readable sizes, hidden files through pager.
alias lx='ll -XB' # Lists sorted by extension (GNU only).
alias lk='ll -Sr' # Lists sorted by size, largest last.
alias lt='ll -tr' # Lists sorted by date, most recent last.
alias lc='lt -c' # Lists sorted by date, most recent last, shows change time.
alias lu='lt -u' # Lists sorted by date, most recent last, shows access time.
alias sl='ls' # I often screw this up.

# Only make alias if ls supports -XB (darwins BSD style ls doesn't)
if ls -XB &> /dev/null; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if you would consider if is-callable 'dircolors' instead.
ls -XB might be expensive depending on the directory on which it is executed.

These things keep on adding to the startup time (unless we memoize it on first call).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use ls /dev/null since that should only be a single file and should be fast.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ls -XB /dev/null would be a great idea! That said, would be nice to be consistently using one way to detect BSD/GNU versions. Turns out we use is-callable 'dircolors' to detect this already.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just detect the options via --help like so:

if grep -q '\-X' <(ls --help 2>&1); then
  # ...
fi

We do similar thing in rsync module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@indrajitr I wasn't aware of the performance penalty my idea could introduce, and your concern makes quite a lot of sense.

On the part of finding a better solution:

At first glance the most straight forward solution @belak has suggested ls -XB /dev/null seems feasible, but in the end the callable 'dircolors' appears to be the most efficient and elegant alternative.

But regarding the test with dircolors, I have one question: Is there an unlikeley case I might not see, where dircolors is not callable and gnu-ls is present or the other way around?

alias lx='ll -XB' # Lists sorted by extension (GNU only).
fi

# Grep
if zstyle -t ':prezto:module:utility:grep' color; then
export GREP_COLOR='37;45' # BSD.
Expand Down