summaryrefslogtreecommitdiff
path: root/.config/wmii-hg/util.sh
diff options
context:
space:
mode:
Diffstat (limited to '.config/wmii-hg/util.sh')
-rw-r--r--.config/wmii-hg/util.sh35
1 files changed, 18 insertions, 17 deletions
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"
}