From 927aedb7605bba96a6ea2fc707ab026946b4d2b0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 21 Mar 2014 16:10:08 -0400 Subject: backport changes from my laptop --- .config/wmii-hg/util.sh | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to '.config/wmii-hg/util.sh') 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-2-g168b