--color=... only works with GNU ls and grep. Test for that and
behave accordingly.
Reported-by: ChiCuong HA
Signed-off-by: Frank Terbeck <ft@bewatermyfriend.org>
GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
ZSH_NO_DEFAULT_LOCALE=${ZSH_NO_DEFAULT_LOCALE:-0}
GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
ZSH_NO_DEFAULT_LOCALE=${ZSH_NO_DEFAULT_LOCALE:-0}
+typeset -ga ls_options
+typeset -ga grep_options
+if ls --help 2> /dev/null | grep -q GNU; then
+ ls_options=( --color=auto )
+elif [[ $OSTYPE == freebsd* ]]; then
+ ls_options=( -G )
+fi
+if grep --help 2> /dev/null | grep -q GNU; then
+ grep_options=( --color=auto )
+fi
+
# utility functions
# this function checks if a command exists and returns either true
# or false. This avoids using 'which' and 'whence', which will
# utility functions
# this function checks if a command exists and returns either true
# or false. This avoids using 'which' and 'whence', which will
'....' '../../..'
'BG' '& exit'
'C' '| wc -l'
'....' '../../..'
'BG' '& exit'
'C' '| wc -l'
- 'G' '|& grep --color=auto '
+ 'G' '|& grep '${grep_options:+"${grep_options[*]} "}
'H' '| head'
'Hl' ' --help |& less -r' #d (Display help in pager)
'L' '| less'
'H' '| head'
'Hl' ' --help |& less -r' #d (Display help in pager)
'L' '| less'
fi
# do we have GNU ls with color-support?
fi
# do we have GNU ls with color-support?
-if ls --help 2>/dev/null | grep -- --color= >/dev/null \
- && [[ "$TERM" != dumb ]]
-then
+if [[ "$TERM" != dumb ]]; then
#a1# execute \kbd{@a@}:\quad ls with colors
#a1# execute \kbd{@a@}:\quad ls with colors
- alias ls='ls -b -CF --color=auto'
+ alias ls='ls -b -CF '${ls_options:+"${ls_options[*]} "}
#a1# execute \kbd{@a@}:\quad list all files, with colors
#a1# execute \kbd{@a@}:\quad list all files, with colors
- alias la='ls -la --color=auto'
+ alias la='ls -la '${ls_options:+"${ls_options[*]} "}
#a1# long colored list, without dotfiles (@a@)
#a1# long colored list, without dotfiles (@a@)
- alias ll='ls -l --color=auto'
+ alias ll='ls -l '${ls_options:+"${ls_options[*]} "}
#a1# long colored list, human readable sizes (@a@)
#a1# long colored list, human readable sizes (@a@)
- alias lh='ls -hAl --color=auto'
+ alias lh='ls -hAl '${ls_options:+"${ls_options[*]} "}
#a1# List files, append qualifier to filenames \\&\quad(\kbd{/} for directories, \kbd{@} for symlinks ...)
#a1# List files, append qualifier to filenames \\&\quad(\kbd{/} for directories, \kbd{@} for symlinks ...)
- alias l='ls -lF --color=auto'
+ alias l='ls -lF '${ls_options:+"${ls_options[*]} "}
else
alias ls='ls -b -CF'
alias la='ls -la'
else
alias ls='ls -b -CF'
alias la='ls -la'
echo "any - grep for process(es) by keyword" >&2
echo "Usage: any <keyword>" >&2 ; return 1
else
echo "any - grep for process(es) by keyword" >&2
echo "Usage: any <keyword>" >&2 ; return 1
else
- ps xauwww | grep -i --color=auto "[${1[1]}]${1[2,-1]}"
+ ps xauwww | grep -i "${grep_options[@]}" "[${1[1]}]${1[2,-1]}"
# use colors when GNU grep with color-support
#a2# Execute \kbd{grep -{}-color=auto}
# use colors when GNU grep with color-support
#a2# Execute \kbd{grep -{}-color=auto}
-(grep --help 2>/dev/null |grep -- --color) >/dev/null && alias grep='grep --color=auto'
+(( $#grml_options > 0 )) && alias grep='grep '${grml_options:+"${grml_options[*]} "}'
# Translate DE<=>EN
# 'translate' looks up fot a word in a file with language-to-language
# Translate DE<=>EN
# 'translate' looks up fot a word in a file with language-to-language