From 9af5f9a09be1a755630c4c9f3cf99e93da65c285 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 6 Dec 2013 11:05:42 -0500 Subject: wmii-hg: clean up quoting, variables --- .config/wmii-hg/fixes.sh | 6 +++--- .config/wmii-hg/util.sh | 35 ++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.config/wmii-hg/fixes.sh b/.config/wmii-hg/fixes.sh index aa09157..5858859 100644 --- a/.config/wmii-hg/fixes.sh +++ b/.config/wmii-hg/fixes.sh @@ -7,11 +7,11 @@ ## unalias ls &>/dev/null ls() { - real_ls="`which ls` -1F" - [ $# = 0 ] && set -- "`pwd`" + local real_ls=("$(which ls)" -1F) + [ $# = 0 ] && set -- "$PWD" f="${1/#${WMII_DIR}/}" if [ "$f" = "$1" ]; then - $real_ls "$f" + "${real_ls[@]}" "$f" else wmiir ls "$f" fi diff --git a/.config/wmii-hg/util.sh b/.config/wmii-hg/util.sh index a4c4bb4..71dbc41 100644 --- a/.config/wmii-hg/util.sh +++ b/.config/wmii-hg/util.sh @@ -13,7 +13,7 @@ # It escapes ways to execute code, but not variables. ## dquote() { - str=$1 + local str=$1 str="${str//\\/\\\\}" # backslash str="${str//\"/\\\"}" # dquote str="${str//\$(/\\\$(}" # $(...) @@ -32,8 +32,8 @@ expand_variables() { } is_mounted() { - dir="$(readlink -m $1)" - mntpnt="$(cut -d' ' -f2 /proc/mounts|grep -- "$dir")" + local dir="$(readlink -m $1)" + local mntpnt="$(cut -d' ' -f2 /proc/mounts|grep -Fx -- "$dir")" [[ $dir = "$mntpnt" ]] return $? } @@ -47,8 +47,9 @@ is_mounted() { # List executables in PATH (PATH is delimited by `:') ## path_ls() { - dirs="`echo "$@"|sed 'y/:/ /'`" - find -L $dirs -maxdepth 1 -type f -executable -printf '%f\n' 2>/dev/null | sort -u + local dirs + IFS=: dirs=($@) + find -L "${dirs[@]}" -maxdepth 1 -type f -executable -printf '%f\n' 2>/dev/null | sort -u } ## @@ -56,9 +57,9 @@ path_ls() { # Find the full path of PROGRAM by searching PATH ## path_which() { - mypath=$1 - prog=$2 - which=`which which` + local mypath=$1 + local prog=$2 + local which=$(which which) PATH="$mypath" "$which" -- "$prog" 2>/dev/null } @@ -71,7 +72,7 @@ path_which() { # Lists wmii tags ## lstags() { - ls $WMII_DIR/tag | sed -e 's@/@@' -e '/^sel$/d' + ls "$WMII_DIR/tag" | sed -e 's@/$@@' -e '/^sel$/d' } ################################################################################ @@ -97,18 +98,18 @@ connected_to_x_server() { # If SECTION is not given, it reads all doc comments. ## scansection() { - file=`conffile config.sh` - sec=$1 - tmp=`mktemp` + local file=$(conffile config.sh) + local sec=$1 + local tmp=$(mktemp --tmpdir wmii-scansecion.XXXXXXXXXX) # Isolate the sections we want. if [ -n "$sec" ]; then # Find the section - < "$file" sed -n "/^\s*$sec\s*()/,/##\s*End $sec/p" | sed '1d;$d'> $tmp + < "$file" sed -n "/^\s*$sec\s*()/,/##\s*End $sec/p" | sed '1d;$d'> "$tmp" else # Remove extra lines that mark the end of a section - < "$file" sed "/\s*}\s*##\s*End\s/d" > $tmp + < "$file" sed "/\s*}\s*##\s*End\s/d" > "$tmp" fi - < $tmp sed -n '/##/p' | while read; do + < "$tmp" sed -n '/##/p' | while read; do var="$(echo "$REPLY" | sed -nr 's/^\s*(.*)\)\s*##.*/\1/p')" comment="$(echo "$REPLY" | sed -r 's/.*## ?//')" if [ -z "$var" ]; then @@ -117,12 +118,12 @@ scansection() { printf '\t%s\t%s\n' "$(echo "$var"|expand_variables)" "$comment" fi done - rm $tmp + rm -- "$tmp" } ## # Usage: conffile FILE ## conffile() { - echo "$HOME/.wmii-hg/$@" + echo "$HOME/.wmii-hg/$1" } -- cgit v1.2.3