diff options
-rw-r--r-- | bash/bashrc.d/grep.bash | 35 | ||||
-rw-r--r-- | bash/bashrc.d/ls.bash | 20 | ||||
-rw-r--r-- | sh/profile.d/grep.sh | 9 | ||||
-rw-r--r-- | sh/shrc.d/grep.sh | 35 | ||||
-rw-r--r-- | sh/shrc.d/ls.sh | 15 |
5 files changed, 51 insertions, 63 deletions
diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash deleted file mode 100644 index 624baf30..00000000 --- a/bash/bashrc.d/grep.bash +++ /dev/null @@ -1,35 +0,0 @@ -# Our ~/.profile should already have made a directory with the supported -# options for us -[[ -d $HOME/.cache/grep ]] || return - -# Store whether we have colors in a variable -declare -i colors -colors=$( { - tput Co || tput colors -} 2>/dev/null ) - -# Use GREPOPTS to add some useful options to grep(1) calls if applicable; we -# use a function wrapper to do this, rather than GREP_OPTIONS as we don't want -# to change grep(1)'s actual behaviour inside scripts -declare -a GREPOPTS -GREPOPTS=() -if ((colors >= 8)) && [[ -n $GREP_COLORS ]] ; then - GREPOPTS[${#GREPOPTS[@]}]='--color=auto' -fi -if [[ -e $HOME/.cache/grep/binary-files ]] ; then - GREPOPTS[${#GREPOPTS[@]}]='--binary-files=without-match' -fi -if [[ -e $HOME/.cache/grep/exclude ]] ; then - GREPOPTS[${#GREPOPTS[@]}]='--exclude={.gitignore,.gitmodules}' -fi -if [[ -e $HOME/.cache/grep/exclude-dir ]] ; then - GREPOPTS[${#GREPOPTS[@]}]='--exclude-dir={.cvs,.git,.hg,.svn}' -fi - -# Done, unset color var -unset -v colors - -# Define function proper -grep() { - command grep "${GREPOPTS[@]}" "$@" -} diff --git a/bash/bashrc.d/ls.bash b/bash/bashrc.d/ls.bash deleted file mode 100644 index 4b647163..00000000 --- a/bash/bashrc.d/ls.bash +++ /dev/null @@ -1,20 +0,0 @@ -# Store whether we have colors in a variable -declare -i colors -colors=$( { - tput Co || tput colors -} 2>/dev/null ) - -# Use LSOPTS to add some useful options to ls(1) calls if applicable; we use a -# function wrapper to do this -declare -a LSOPTS -if [[ -n $LS_COLORS ]] && ((colors >= 8)) ; then - LSOPTS[${#LSOPTS[@]}]='--color=auto' -fi - -# Done, unset helper var -unset -v colors - -# Define function proper -ls() { - command ls "${LSOPTS[@]}" "$@" -} diff --git a/sh/profile.d/grep.sh b/sh/profile.d/grep.sh index 8c1c5836..892351ca 100644 --- a/sh/profile.d/grep.sh +++ b/sh/profile.d/grep.sh @@ -18,11 +18,4 @@ touch -- "$gcd"/"$opt" || exit done fi -) || return - -# If one of the available options is --color, set the GREP_COLORS environment -# variable -if [ -e "$HOME"/.cache/grep/color ] ; then - GREP_COLORS='ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36' - export GREP_COLORS -fi +) diff --git a/sh/shrc.d/grep.sh b/sh/shrc.d/grep.sh new file mode 100644 index 00000000..df2101aa --- /dev/null +++ b/sh/shrc.d/grep.sh @@ -0,0 +1,35 @@ +# Our ~/.profile should already have made a directory with the supported +# options for us; if not, we won't be wrapping grep(1) with a function at all +[ -d "$HOME"/.cache/grep ] || return + +# Define function proper +grep() { + + # Add --color if the terminal has at least 8 colors + [ -e "$HOME"/.cache/grep/color ] && + [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] && + set -- --color=auto "$@" + + # Add --binary-files=without-match to gracefully skip binary files + [ -e "$HOME"/.cache/grep/binary-files ] && + set -- --binary-files=without-match "$@" + + # Add --exclude to ignore .gitignore and .gitmodules files + [ -e "$HOME"/.cache/grep/exclude ] && + set -- \ + --exclude=.gitignore \ + --exclude=.gitmodules \ + "$@" + + # Add --exclude-dir to ignore version control dot-directories + [ -e "$HOME"/.cache/grep/exclude-dir ] && + set -- \ + --exclude-dir=.cvs \ + --exclude-dir=.git \ + --exclude-dir=.hg \ + --exclude-dir=.svn \ + "$@" + + # Run grep(1) with the concluded arguments + command grep "$@" +} diff --git a/sh/shrc.d/ls.sh b/sh/shrc.d/ls.sh new file mode 100644 index 00000000..eec25eb7 --- /dev/null +++ b/sh/shrc.d/ls.sh @@ -0,0 +1,15 @@ +# Our ~/.profile should already have made a directory with the supported +# options for us; if not, we won't be wrapping ls(1) with a function at all +[ -d "$HOME"/.cache/ls ] || return + +# Define function proper +ls() { + + # Add --color if the terminal has at least 8 colors + [ -e "$HOME"/.cache/ls/color ] && + [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] && + set -- --color=auto "$@" + + # Run ls(1) with the concluded arguments + command ls "$@" +} |