1
0
Fork 0
mirror of synced 2024-11-26 17:25:35 -05:00

[utility] BSD uses LSCOLORS and GREP_COLOR

and GNU uses LS_COLORS and GREP_COLORS. So change logic to only set
these environment variables for each OSTYPE.

Also original code was setting the `ls` alias with `-G` instead of
`--color=auto` if in a GNU without `dircolors`. Fix that too.

Simplify arithmetic command expression without using `${var}`, but
`var` instead. The second construct does not fail if `var` is not
defined, but defaults its value to `0` in that case.

Closes #225
This commit is contained in:
Eric Nielsen 2017-11-20 11:01:32 -05:00
parent e4e0c55ef3
commit 6022fe46c5

View file

@ -6,38 +6,37 @@
# Colours # Colours
# #
if [[ ! -z ${terminfo[colors]} ]] && (( ${terminfo[colors]} >= 8 )); then if (( terminfo[colors] >= 8 )); then
# ls Colours if [[ ${OSTYPE} == (*bsd*|darwin*) ]]; then
if (( ${+commands[dircolors]} )); then
# GNU
if [[ -s ${HOME}/.dir_colors ]]; then
eval "$(dircolors --sh ${HOME}/.dir_colors)"
else
eval "$(dircolors --sh)"
fi
alias ls='ls --group-directories-first --color=auto'
else
# BSD # BSD
# colours for ls and completion
(( ! ${+LSCOLORS} )) && export LSCOLORS='exfxcxdxbxGxDxabagacad' (( ! ${+LSCOLORS} )) && export LSCOLORS='exfxcxdxbxGxDxabagacad'
(( ! ${+LS_COLORS} )) && export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:'
# stock OpenBSD ls does not support colors at all, but colorls does. if [[ ${OSTYPE} == openbsd* ]]; then
if [[ $OSTYPE == openbsd* ]]; then # stock OpenBSD ls does not support colours at all, but colorls does.
if (( ${+commands[colorls]} )); then if (( ${+commands[colorls]} )); then
alias ls='colorls -G' alias ls='colorls -G'
fi fi
else else
alias ls='ls -G' alias ls='ls -G'
fi fi
(( ! ${+GREP_COLOR} )) && export GREP_COLOR='37;45'
else
# GNU
(( ! ${+LS_COLORS} )) && if [[ ${+commands[dircolors]} -ne 0 && -s ${HOME}/.dir_colors ]]; then
eval "$(dircolors --sh ${HOME}/.dir_colors)"
else
export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=1;36:cd=1;33:su=30;41:sg=30;46:tw=30;42:ow=30;43'
fi
alias ls='ls --group-directories-first --color=auto'
(( ! ${+GREP_COLORS} )) && export GREP_COLORS="mt=37;45"
fi fi
# grep Colours # grep Colours
(( ! ${+GREP_COLOR} )) && export GREP_COLOR='37;45' #BSD
(( ! ${+GREP_COLORS} )) && export GREP_COLORS="mt=${GREP_COLOR}" #GNU
if [[ ${OSTYPE} == openbsd* ]]; then if [[ ${OSTYPE} == openbsd* ]]; then
if (( ${+commands[ggrep]} )); then if (( ${+commands[ggrep]} )); then
alias grep='ggrep --color=auto' alias grep='ggrep --color=auto'