diff options
Diffstat (limited to '.config/wmii-hg/util.sh')
-rw-r--r-- | .config/wmii-hg/util.sh | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/.config/wmii-hg/util.sh b/.config/wmii-hg/util.sh index 71dbc41..b28a3b6 100644 --- a/.config/wmii-hg/util.sh +++ b/.config/wmii-hg/util.sh @@ -1,8 +1,5 @@ #!/bin/bash -# I moved "fixes" into a separate file because it isn't so much configuration... -. fixes.sh - ################################################################################ # Added shell features # ################################################################################ @@ -25,17 +22,17 @@ dquote() { # Usage: expand_variables # Expands variables read from /dev/stdin ## -expand_variables() { - while read; do - eval printf "'%s\n'" "$(dquote "$REPLY")" +expand_variables() ( + IFS='' + while read -r line; do + eval printf "'%s\n'" "$(dquote "$line")" done -} +) is_mounted() { local dir="$(readlink -m $1)" local mntpnt="$(cut -d' ' -f2 /proc/mounts|grep -Fx -- "$dir")" [[ $dir = "$mntpnt" ]] - return $? } ################################################################################ @@ -72,7 +69,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' } ################################################################################ @@ -85,7 +82,6 @@ lstags() { ## connected_to_x_server() { xdpyinfo &>/dev/null - return $? } ################################################################################ @@ -93,32 +89,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" } ## |