From e1401360121785b7dd7b5b5d7b7ef5b337e5bb39 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 10 Oct 2014 16:25:47 +1300 Subject: Move array decs inline, remove quotes --- bash/bashrc.d/cf.bash | 3 +-- bash/bashrc.d/grep.bash | 9 +++------ bash/bashrc.d/ls.bash | 2 +- bash/bashrc.d/mysql.bash | 6 ++---- 4 files changed, 7 insertions(+), 13 deletions(-) (limited to 'bash') diff --git a/bash/bashrc.d/cf.bash b/bash/bashrc.d/cf.bash index db715c2f..66917375 100644 --- a/bash/bashrc.d/cf.bash +++ b/bash/bashrc.d/cf.bash @@ -19,9 +19,8 @@ cf() { # Count files and print; use a subshell so options are unaffected ( - declare -a files shopt -s dotglob nullglob - files=("$dir"/*) + declare -a files=("$dir"/*) printf '%d\t%s\n' "${#files[@]}" "$dir" ) } diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash index b2ff5daf..de225347 100644 --- a/bash/bashrc.d/grep.bash +++ b/bash/bashrc.d/grep.bash @@ -1,15 +1,12 @@ # Return appropriate options for grep grepopts() { + # Start with ignoring binary files + local -a grepopts=(-I) + # Snarf the output of `grep --help` into a variable local grephelp=$(grep --help 2>/dev/null) - # Start collecting available options - local -a grepopts - - # Add option to ignore binary files - grepopts=("${grepopts[@]}" '-I') - # If the --exclude option is available, exclude some VCS files if [[ $grephelp == *--exclude* ]] ; then for exclude_file in .gitignore .gitmodules ; do diff --git a/bash/bashrc.d/ls.bash b/bash/bashrc.d/ls.bash index 0dedfdcc..255d6cd3 100644 --- a/bash/bashrc.d/ls.bash +++ b/bash/bashrc.d/ls.bash @@ -11,7 +11,7 @@ lsopts() { # at least eight colors, add --color=auto to the options local colors=$(tput colors) if [[ $lshelp == *--color* ]] && ((colors >= 8)) ; then - lsopts=("${lsopts[@]}" '--color=auto') + lsopts=("${lsopts[@]}" --color=auto) fi # Print the options as a single string, space-delimited diff --git a/bash/bashrc.d/mysql.bash b/bash/bashrc.d/mysql.bash index d04b189d..24317b24 100644 --- a/bash/bashrc.d/mysql.bash +++ b/bash/bashrc.d/mysql.bash @@ -30,9 +30,8 @@ _mysql() { # Check directory exists and has at least one .cnf file local dir="$HOME"/.mysql if [[ ! -d $dir ]] || ( - declare -a files shopt -s nullglob dotglob - files=("$dir"/*.cnf) + declare -a files=("$dir"/*.cnf) ((! ${#files[@]})) ) ; then COMPREPLY=() @@ -40,8 +39,7 @@ _mysql() { fi # Return the names of the .cnf files sans prefix as completions - local -a items - items=("$dir"/*.cnf) + local -a items=("$dir"/*.cnf) items=("${items[@]##*/}") items=("${items[@]%%.cnf}") COMPREPLY=( $(compgen -W "${items[*]}" -- "$word") ) -- cgit v1.2.3