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.sh31
1 files changed, 11 insertions, 20 deletions
diff --git a/.config/wmii-hg/util.sh b/.config/wmii-hg/util.sh
index 71dbc41..f15031e 100644
--- a/.config/wmii-hg/util.sh
+++ b/.config/wmii-hg/util.sh
@@ -35,7 +35,6 @@ is_mounted() {
local dir="$(readlink -m $1)"
local mntpnt="$(cut -d' ' -f2 /proc/mounts|grep -Fx -- "$dir")"
[[ $dir = "$mntpnt" ]]
- return $?
}
################################################################################
@@ -85,7 +84,6 @@ lstags() {
##
connected_to_x_server() {
xdpyinfo &>/dev/null
- return $?
}
################################################################################
@@ -93,32 +91,25 @@ connected_to_x_server() {
################################################################################
##
-# Usage: scansection [SECTION]
+# Usage: scansection SECTION
# Reads the doc comments from a section of wmiirc.
-# If SECTION is not given, it reads all doc comments.
##
scansection() {
- 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"
- else
- # Remove extra lines that mark the end of a section
- < "$file" sed "/\s*}\s*##\s*End\s/d" > "$tmp"
- fi
- < "$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
+
+ local file=$(conffile config.sh)
+ # Isolate the section we want.
+ < "$file" sed -n "/^\s*$sec\s*()/,/^}/{ /##/p }" |
+ # Parse each line.
+ while read -r line; do
+ symbol="$(sed -nr 's/^\s*(.*)\)\s*##.*/\1/p' <<<"$line")"
+ comment="$(sed -r 's/.*## ?//' <<<"$line")"
+ if [ -z "$symbol" ]; then
printf '%s\n' "$comment"
else
- printf '\t%s\t%s\n' "$(echo "$var"|expand_variables)" "$comment"
+ printf '\t%s\t%s\n' "$(expand_variables <<<"$symbol")" "$comment"
fi
done
- rm -- "$tmp"
}
##