diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2013-08-18 23:34:23 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2013-08-18 23:34:23 +1200 |
commit | b376e929cfd3e9bea42d2fe6abf164211c6bc6a6 (patch) | |
tree | ebd3f3311e0c6a048144fe991a11c23dea315dfb /bash | |
parent | Use double-quoted printf strings for newlines (diff) | |
download | dotfiles-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.bash | 11 | ||||
-rw-r--r-- | bash/bashrc.d/ls.bash | 6 |
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 |