aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-08-18 23:34:23 +1200
committerTom Ryder <tom@sanctum.geek.nz>2013-08-18 23:34:23 +1200
commitb376e929cfd3e9bea42d2fe6abf164211c6bc6a6 (patch)
treeebd3f3311e0c6a048144fe991a11c23dea315dfb /bash
parentUse double-quoted printf strings for newlines (diff)
downloaddotfiles-b376e929cfd3e9bea42d2fe6abf164211c6bc6a6.tar.gz
dotfiles-b376e929cfd3e9bea42d2fe6abf164211c6bc6a6.zip
Use arrays to collect options for ls/grep aliases
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc.d/grep.bash11
-rw-r--r--bash/bashrc.d/ls.bash6
2 files changed, 9 insertions, 8 deletions
diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash
index 37061916..da391193 100644
--- a/bash/bashrc.d/grep.bash
+++ b/bash/bashrc.d/grep.bash
@@ -1,17 +1,18 @@
# Function returns calculated options for grep
__grepopts() {
- local grepopts='-I'
+ local -a grepopts
local grephelp="$(grep --help 2>/dev/null)"
+ grepopts[${#grepopts[@]}]='-I'
if [[ "$grephelp" == *--color* && "$(tput colors)" -ge 8 ]]; then
- grepopts="${grepopts} --color=auto"
+ grepopts[${#grepopts[@]}]='--color=auto'
fi
if [[ "$grephelp" == *--exclude* ]]; then
- grepopts="${grepopts} --exclude=.git{,ignore,modules}"
+ grepopts[${#grepopts[@]}]='--exclude=.git{,ignore,modules}'
fi
if [[ "$grephelp" == *--exclude-dir* ]]; then
- grepopts="${grepopts} --exclude-dir=.{cvs,git,hg,svn}"
+ grepopts[${#grepopts[@]}]='--exclude-dir=.{cvs,git,hg,svn}'
fi
- printf '%s' "$grepopts"
+ printf -- "${grepopts[*]}"
}
# Alias grep with those options
diff --git a/bash/bashrc.d/ls.bash b/bash/bashrc.d/ls.bash
index 0fda4ed8..9446c56e 100644
--- a/bash/bashrc.d/ls.bash
+++ b/bash/bashrc.d/ls.bash
@@ -1,11 +1,11 @@
# Function returns calculated options for ls
__lsopts() {
- local lsopts=
+ local -a lsopts
local lshelp="$(ls --help 2>/dev/null)"
if [[ "$lshelp" == *--color* && "$(tput colors)" -ge 8 ]]; then
- lsopts="${lsopts} --color=auto"
+ lsopts[${#lsopts[@]}]='--color=auto'
fi
- printf '%s' "$lsopts"
+ printf -- "${lsopts[*]}"
}
# Alias ls with these options