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

utility: add support for g-prefixed coreutils ls #1786

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 21 additions & 8 deletions modules/utility/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,41 @@ if zstyle -T ':prezto:module:utility' safe-ops; then
alias ln="${aliases[ln]:-ln} -i"
fi

# ls
if is-callable 'dircolors'; then
# GNU Core Utilities
function -define-coreutils-aliases {
# Prefix will either be g or empty. This is to account for GNU Coreutils being
# installed alongside BSD Coreutils
local prefix=$1

if zstyle -T ':prezto:module:utility:ls' dirs-first; then
alias ls="${aliases[ls]:-ls} --group-directories-first"
alias ${prefix}ls="${aliases[${prefix}ls]:-${prefix}ls} --group-directories-first"
fi

if zstyle -t ':prezto:module:utility:ls' color; then
# Call dircolors to define colors if they're missing
if [[ -z "$LS_COLORS" ]]; then
if [[ -s "$HOME/.dir_colors" ]]; then
eval "$(dircolors --sh "$HOME/.dir_colors")"
eval "$(${prefix}dircolors --sh "$HOME/.dir_colors")"
else
eval "$(dircolors --sh)"
eval "$(${prefix}dircolors --sh)"
fi
fi

alias ls="${aliases[ls]:-ls} --color=auto"
alias ${prefix}ls="${aliases[${prefix}ls]:-${prefix}ls} --color=auto"
else
alias ls="${aliases[ls]:-ls} -F"
alias ${prefix}ls="${aliases[${prefix}ls]:-${prefix}ls} -F"
fi
}

# ls

# GNU Core Utilities
if is-callable 'gdircolors'; then
-define-coreutils-aliases g
alias ls="${aliases[gls]:-gls}"

elif is-callable 'dircolors'; then
-define-coreutils-aliases
Comment on lines +103 to +108
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we consider honoring user configured ':prezto:module:gnu-utility' zstyle instead of assuming g?
Granted Homebrew doesn't honor customizing g prefix for gnu coreutils anymore, but macport still does.

Besides, if a user loads gnu-utility module, both ls and gls would be candidate for alias modification. Shouldn't we support both?

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, it might be tricky with some of the g_ prefixed GNU utility commands/aliases -- particularly the ones used with git module (gls is aliased to git log for example).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catches. I'm not 100% sure what the proper fix is on this... coreutils are a bit of a pain to detect and work with especially with the git aliases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Took another (rather opinionated) attempt at addressing this here #1917. Criticism/comment appreciated :)


else
# BSD Core Utilities
if zstyle -t ':prezto:module:utility:ls' color; then
Expand Down