From The Compiler, 5 Years ago, written in Diff-output.
Embed
  1. From 745f7851d86f3af1946be50958c5824da416868d Mon Sep 17 00:00:00 2001
  2. From: Florian Bruhin <git@the-compiler.org>
  3. Date: Tue, 18 Jun 2013 15:20:33 +0200
  4. Subject: [PATCH] Cleanup, simplifications and bugfixes in scripts
  5.  
  6. Everywhere:
  7.  
  8.  - Replace all-caps variable names by lower-case ones, because upper-case
  9.    variable names should be reserved for environment variables.
  10.  
  11.    http://stackoverflow.com/a/673940/2085149
  12.  
  13.  - Replace multiple sed calls to the same file with one sed-call with multiple
  14.    -e arguments.
  15.  
  16.  - Use consistent spacing for pipes
  17.  
  18.  - Quote variables which could potentially have whitespace in them (monitor
  19.    names, tag names, file paths)
  20.  
  21.    http://mywiki.wooledge.org/Quotes#line-28
  22.  
  23. In release.sh:
  24.  
  25.  - Use "read -a" to read version into an array.
  26.    This does not depend on tr and saves an external binary call.
  27.  
  28.    http://mywiki.wooledge.org/BashGuide/Arrays#line-81
  29.  
  30.  - Fix typo in comment
  31.  
  32. In dumpbeautify.sh:
  33.  
  34.  - Remove unneeded semicolons in awk script
  35.  
  36.  - Print color clear character directly from awk, saving a sed call
  37.  
  38.  - Print an additional clear after output is finished
  39.  
  40.  - Use & for the backreference for sed (faster, easier to read)
  41.  
  42. In exec_on_tag.sh:
  43.  
  44.  - Use "hc attr" to get current tag
  45.  
  46. In floatmon.sh:
  47.  
  48.  - Replace grep | cut | sed by single sed call
  49.  
  50.  - Check if xwininfo exists
  51.  
  52. In q3terminal.sh:
  53.  
  54.  - Bugfix: hc add "$tag", not scratchpad hardcoded
  55.  
  56.  - Don't use $ for variables inside ((..)) (consistency)
  57.  
  58.  - Add whitespace in calculations (easier to read)
  59.  
  60. In panel.sh:
  61.  
  62.  - Change geometry comment to reflect real monitor_rect output
  63.  
  64.  - Replace 'if [ -e "$(which foo)" ]' by simple 'if which foo'.
  65.    which has an exit status saying if it has found anything or not, so there is
  66.    no need to check it's output.
  67.  
  68.  - Use "foo()" instead of "function foo()"
  69.    Consistency, and "function foo()" is not portable, not even across all bash
  70.    versions.
  71.  
  72.    http://mywiki.wooledge.org/BashPitfalls#function_foo.28.29
  73.  
  74.  - Use \" instead of quote-mixing to get literal " inside "..." (easier to
  75.    read)
  76.  
  77.  - Use simple sed call instead of cut | grep
  78.  
  79.  - Remove superfluous check if ${cmd[1]} is empty, as $monitor will never be
  80.    empty.
  81. ---
  82. release.sh              | 34 +++++++++++++++---------------
  83.  scripts/dmenu.sh        |  4 ++--
  84.  scripts/dumpbeautify.sh | 56 ++++++++++++++++++++++++-------------------------
  85.  scripts/exec_on_tag.sh  | 16 +++++---------
  86.  scripts/floatmon.sh     | 38 +++++++++++++++++++++------------
  87.  scripts/lasttag.sh      |  8 +++----
  88.  scripts/layout.sh       | 12 +++++------
  89.  scripts/loadstate.sh    |  4 ++--
  90.  scripts/q3terminal.sh   | 27 ++++++++++++------------
  91.  scripts/savestate.sh    |  4 ++--
  92.  share/panel.sh          | 26 +++++++++++------------
  93.  share/restartpanels.sh  | 10 ++++-----
  94.  12 files changed, 122 insertions(+), 117 deletions(-)
  95.  
  96. diff --git a/release.sh b/release.sh
  97. index 31ea228..9316314 100755
  98. --- a/release.sh
  99. +++ b/release.sh
  100. @@ -1,6 +1,6 @@
  101.  #!/bin/bash
  102.  
  103. -VERSION="$1"
  104. +version="$1"
  105.  
  106.  if [ -z "$1" ] || [ "$1" = -h ] ; then
  107.      echo "$0 VERSIONMAJOR.VERSIONMINOR.VERSIONPATCH"
  108. @@ -13,47 +13,47 @@ if git status --porcelain | grep '^ M' ; then
  109.      exit 1
  110.  fi
  111.  
  112. -VERSIONARGS=( $(tr . ' ' <<< "$VERSION") )
  113. +IFS=. read -a versionargs <<< "$version"
  114.  
  115.  
  116.  echo "==> Release commit"
  117.  echo ":: Patching version.mk"
  118. -sed -i "s/^VERSION_MAJOR.*$/VERSION_MAJOR = ${VERSIONARGS[0]}/" version.mk
  119. -sed -i "s/^VERSION_MINOR.*$/VERSION_MINOR = ${VERSIONARGS[1]}/" version.mk
  120. -sed -i "s/^VERSION_PATCH.*$/VERSION_PATCH = ${VERSIONARGS[2]}/" version.mk
  121. +sed -i -e "s/^VERSION_MAJOR.*$/VERSION_MAJOR = ${versionargs[0]}/" \
  122. +       -e "s/^VERSION_MINOR.*$/VERSION_MINOR = ${versionargs[1]}/" \
  123. +       -e "s/^VERSION_PATCH.*$/VERSION_PATCH = ${versionargs[2]}/" version.mk
  124.  
  125.  echo ":: Patching NEWS"
  126.  date=$(date +%Y-%m-%d)
  127. -newheader="Release $VERSION on $date"
  128. -newunderline="$(echo $newheader|sed 's/./-/g')"
  129. +newheader="Release $version on $date"
  130. +newunderline="$(echo $newheader | sed 's/./-/g')"
  131.  headerexp="^Next Release: [^ ]*$"
  132. -# this requires news sed
  133. -sed -i -e "/$headerexp/,+1s/^[-]*$/$newunderline/" NEWS
  134. -sed -i -e "s/$headerexp/$newheader/" NEWS
  135. +# this requires new sed
  136. +sed -i -e "/$headerexp/,+1s/^[-]*$/$newunderline/" \
  137. +       -e "s/$headerexp/$newheader/" NEWS
  138.  
  139.  echo ":: Commiting changes"
  140.  git add NEWS version.mk
  141. -git commit -m "Release $VERSION"
  142. +git commit -m "Release $version"
  143.  echo ":: Tagging commit"
  144. -git tag -s v$VERSION -m "Release $VERSION"
  145. +git tag -s "v$version" -m "Release $version"
  146.  
  147.  echo "==> Tarball"
  148.  echo ":: Tarball creation"
  149.  make tar
  150. -tarball=herbstluftwm-$VERSION.tar.gz
  151. -md5sum=$(md5sum $tarball| head -c 13 )
  152. +tarball="herbstluftwm-$version.tar.gz"
  153. +md5sum=$(md5sum "$tarball" | head -c 13 )
  154.  echo ":: Patching www/index.txt"
  155.  line=$(printf "| %-7s | $date | $md5sum...%15s| link:tarballs/%s[tar.gz]" \
  156. -                $VERSION                  ' '                 "$tarball" )
  157. +                $version                  ' '                 "$tarball" )
  158.  linerexp="// do not remove this: next version line will be added here"
  159.  sed -i "s#^$linerexp\$#$line\n$linerexp#" www/index.txt
  160.  echo ":: Commiting changes"
  161.  git add www/index.txt
  162. -git commit -m "www: Add $VERSION tarball"
  163. +git commit -m "www: Add $version tarball"
  164.  
  165.  echo
  166.  echo "Still to do:"
  167.  echo "1. Add the following line to the MD5SUMS file on the mirror:"
  168. -md5sum $tarball
  169. +md5sum "$tarball"
  170.  echo "2. Make www files and install them on the remote"
  171.  echo "3. Push the changes to all public remotes (including --tags)"
  172. diff --git a/scripts/dmenu.sh b/scripts/dmenu.sh
  173. index 24bd556..064e909 100755
  174. --- a/scripts/dmenu.sh
  175. +++ b/scripts/dmenu.sh
  176. @@ -8,8 +8,8 @@ dmenu_cmd() {
  177.  }
  178.  
  179.  simple_command() {
  180. -    arg=$($hc complete 1 "$@"|dmenu_cmd -p "$@:") \
  181. -    && exec $hc "$@" "$arg"
  182. +    arg=$("$hc" complete 1 "$@" | dmenu_cmd -p "$@:") \
  183. +    && exec "$hc" "$@" "$arg"
  184.  }
  185.  
  186.  simple_command "$1"
  187. diff --git a/scripts/dumpbeautify.sh b/scripts/dumpbeautify.sh
  188. index 3301306..423d167 100755
  189. --- a/scripts/dumpbeautify.sh
  190. +++ b/scripts/dumpbeautify.sh
  191. @@ -7,54 +7,54 @@
  192.  awkcode='
  193.  BEGIN {
  194.      indent=2
  195. -    ORS="";
  196. -    x=0;
  197. -    open=0;
  198. +    ORS=""
  199. +    x=0
  200. +    open=0
  201.      first=1
  202. -    i=0;
  203. -    color[i++]="\033[1;31m";
  204. -    color[i++]="\033[1;32m";
  205. -    color[i++]="\033[1;33m";
  206. -    color[i++]="\033[1;34m";
  207. -    color[i++]="\033[1;35m";
  208. -    color[i++]="\033[1;36m";
  209. -    color[i++]="\033[1;37m";
  210. -    color[i++]="\033[0;31m";
  211. -    color[i++]="\033[0;32m";
  212. -    color[i++]="\033[0;33m";
  213. -    color[i++]="\033[0;34m";
  214. -    color[i++]="\033[0;35m";
  215. -    color[i++]="\033[0;36m";
  216. -    color[i++]="\033[0;37m";
  217. +    i=0
  218. +    color[i++]="\033[1;31m"
  219. +    color[i++]="\033[1;32m"
  220. +    color[i++]="\033[1;33m"
  221. +    color[i++]="\033[1;34m"
  222. +    color[i++]="\033[1;35m"
  223. +    color[i++]="\033[1;36m"
  224. +    color[i++]="\033[1;37m"
  225. +    color[i++]="\033[0;31m"
  226. +    color[i++]="\033[0;32m"
  227. +    color[i++]="\033[0;33m"
  228. +    color[i++]="\033[0;34m"
  229. +    color[i++]="\033[0;35m"
  230. +    color[i++]="\033[0;36m"
  231. +    color[i++]="\033[0;37m"
  232.  }
  233.  
  234.  $1 ~ "^[(]" {
  235.      if (first == 0) {
  236. -        printf "\n";
  237. -        printf "%"(indent*x)"s" , "" ;
  238. +        printf "\n"
  239. +        printf "%"(indent*x)"s" , ""
  240.      } else {
  241. -        first=0;
  242. +        first=0
  243.      }
  244.      color_bracket[x]=open
  245.      print color[(color_bracket[x]) % length(color)]
  246. -    print ;
  247. +    gsub("[(]", "&" clear)
  248. +    print
  249.      x++
  250. -    open++;
  251. +    open++
  252.  }
  253.  
  254.  $1 ~ "[)]" {
  255. -    x-- ;
  256. +    x--
  257.      print color[(color_bracket[x]) % length(color)]
  258.      print
  259.  }
  260.  
  261.  END {
  262. -    printf "\n"
  263. +    printf clear "\n"
  264.  }
  265.  '
  266.  
  267.  clear=$(tput sgr0) || clear=$(echo -e '\e[0m')
  268.  
  269. -sed 's/\([()]\)/\n/g' | # insert newlines before (
  270. -    awk "$awkcode" |
  271. -    sed 's#(#('"$clear"'#g'
  272. +sed 's/[()]/\n&/g' | # insert newlines before (
  273. +    awk -v "clear=$clear" "$awkcode"
  274. diff --git a/scripts/exec_on_tag.sh b/scripts/exec_on_tag.sh
  275. index 5c552db..a0d7f6a 100755
  276. --- a/scripts/exec_on_tag.sh
  277. +++ b/scripts/exec_on_tag.sh
  278. @@ -1,7 +1,7 @@
  279.  #!/bin/bash
  280.  
  281. -TAG="$1"
  282. -EXPIRE="120" # expiry time in seconds
  283. +tag="$1"
  284. +expire="120" # expiry time in seconds
  285.  shift
  286.  
  287.  if [ -z "$1" ] ;then
  288. @@ -16,18 +16,12 @@ hc() {
  289.      herbstclient "$@"
  290.  }
  291.  
  292. -curtag() {
  293. -     hc tag_status \
  294. -        | grep -oE "$(echo -ne '\t')#[^$(echo -ne '\t')]*" \
  295. -        | tail -c +3
  296. -}
  297. -
  298. -TAG=${TAG:-$(curtag)}
  299. +tag=${tag:-$(hc attr tags.focus.name)}
  300.  
  301.  # ensure tag exists
  302. -hc add "$TAG"
  303. +hc add "$tag"
  304.  
  305.  # move next window from this process to this tag
  306. -hc rule maxage="$EXPIRE" pid="$$" tag="$TAG" once
  307. +hc rule maxage="$expire" pid="$$" tag="$tag" once
  308.  
  309.  exec "$@"
  310. diff --git a/scripts/floatmon.sh b/scripts/floatmon.sh
  311. index 9f1f053..50267f8 100755
  312. --- a/scripts/floatmon.sh
  313. +++ b/scripts/floatmon.sh
  314. @@ -7,21 +7,33 @@ Floatkey=${Floatkey:-Shift-f}
  315.  
  316.  hc() { herbstclient "$@" ; }
  317.  
  318. -size=$(xwininfo -root |
  319. -                grep -E '^  (Width|Height):' |
  320. -                cut -d' ' -f4 |
  321. -                sed 'N;s/\n/x/')
  322. +if which xwininfo &> /dev/null; then
  323. +    size=$(xwininfo -root |
  324. +           sed -n -e '/^  Width: / {
  325. +                          s/.*: //;
  326. +                          h
  327. +                      }
  328. +                      /^  Height: / {
  329. +                          s/.*: //g;
  330. +                          H;
  331. +                          x;
  332. +                          s/\n/x/p
  333. +                      }')
  334. +else
  335. +    echo "This script requires the xwininfo binary."
  336. +    exit 1
  337. +fi
  338.  
  339. -hc chain , add $tag , floating $tag on
  340. -hc or , add_monitor "$size"+0+0 $tag $monitor \
  341. -      , move_monitor $monitor "$size"+0+0
  342. -hc raise_monitor $monitor
  343. -hc lock_tag $monitor
  344. +hc chain , add "$tag" , floating "$tag" on
  345. +hc or , add_monitor "$size"+0+0 "$tag" "$monitor" \
  346. +      , move_monitor "$monitor" "$size"+0+0
  347. +hc raise_monitor "$monitor"
  348. +hc lock_tag "$monitor"
  349.  
  350.  cmd=(
  351.  or  case: and
  352.          # if not on floating monitor
  353. -        . compare monitors.focus.name != $monitor
  354. +        . compare monitors.focus.name != "$monitor"
  355.          # and if a client is focused
  356.          . get_attr clients.focus.winid
  357.          # then remember the last monitor of the client
  358. @@ -30,12 +42,12 @@ or  case: and
  359.          . substitute M monitors.focus.index
  360.              set_attr clients.focus.my_lastmon M
  361.          # and then move the client to the floating tag
  362. -        . shift_to_monitor $monitor
  363. -        . focus_monitor $monitor
  364. +        . shift_to_monitor "$monitor"
  365. +        . focus_monitor "$monitor"
  366.          . true
  367.      case: and
  368.          # if on the floating monitor
  369. -        . compare monitors.focus.name = $monitor
  370. +        . compare monitors.focus.name = "$monitor"
  371.          # and if a client is focused
  372.          . get_attr clients.focus.winid
  373.          # then send it back to the original monitor
  374. diff --git a/scripts/lasttag.sh b/scripts/lasttag.sh
  375. index c329227..43388e6 100755
  376. --- a/scripts/lasttag.sh
  377. +++ b/scripts/lasttag.sh
  378. @@ -8,14 +8,14 @@
  379.  
  380.  herbstclient --idle '(tag_changed|goto_last_tag|reload)' \
  381.      | while read line ; do
  382. -        ARGS=( $line )
  383. +        args=( $line )
  384.          case ${ARGS[0]} in
  385.              tag_changed)
  386. -                LASTTAG="$TAG"
  387. -                TAG=${ARGS[1]}
  388. +                lasttag="$tag"
  389. +                tag=${args[1]}
  390.                  ;;
  391.              goto_last_tag)
  392. -                ! [ -z "$LASTTAG" ] && herbstclient use "$LASTTAG"
  393. +                [ "$lasttag" ] && herbstclient use "$lasttag"
  394.                  ;;
  395.              reload)
  396.                  exit
  397. diff --git a/scripts/layout.sh b/scripts/layout.sh
  398. index c631a84..68d8ed5 100755
  399. --- a/scripts/layout.sh
  400. +++ b/scripts/layout.sh
  401. @@ -3,14 +3,14 @@
  402.  # print layout of all tags, and colorizes all window ids
  403.  # it's useful to get a overview over the list of all windows
  404.  
  405. -hc=${herbstclient_command:-herbstclient}
  406. +hc="${herbstclient_command:-herbstclient}"
  407.  
  408. -$hc complete 1 use |
  409. +"$hc" complete 1 use |
  410.  while read tag ; do
  411.      echo -n "$tag "
  412. -    indent=$(echo -n "$tag "|sed 's/./ /g')
  413. +    indent=$(echo -n "$tag " | sed 's/./ /g')
  414.      # prepend indent, except in first line
  415. -    $hc layout "$tag" \
  416. -        | sed "2,\$ s/^/$indent/" \
  417. -        | sed "s/\(0x[0-9a-f]\{1,\}\)/$(tput setaf 3)$(tput sgr0)/g"
  418. +    "$hc" layout "$tag" \
  419. +        | sed -e "2,\$ s/^/$indent/" \
  420. +              -e "s/0x[0-9a-f]\+/$(tput setaf 3)&$(tput sgr0)/g"
  421.  done
  422. diff --git a/scripts/loadstate.sh b/scripts/loadstate.sh
  423. index 1c5e0a0..75ccbe9 100755
  424. --- a/scripts/loadstate.sh
  425. +++ b/scripts/loadstate.sh
  426. @@ -13,6 +13,6 @@ hc=${herbstclient_command:-herbstclient}
  427.  while read line ; do
  428.      tag="${line%%: *}"
  429.      tree="${line#*: }"
  430. -    $hc add "$tag"
  431. -    $hc load "$tag" "$tree"
  432. +    "$hc" add "$tag"
  433. +    "$hc" load "$tag" "$tree"
  434.  done
  435. diff --git a/scripts/q3terminal.sh b/scripts/q3terminal.sh
  436. index 9d74580..498a5c2 100755
  437. --- a/scripts/q3terminal.sh
  438. +++ b/scripts/q3terminal.sh
  439. @@ -20,20 +20,20 @@ hc() {
  440.  }
  441.  
  442.  mrect=( $(hc monitor_rect -p "" ) )
  443. -termwidth=$(((${mrect[2]}*8)/10))
  444. +termwidth=$(( (${mrect[2]} * 8) / 10 ))
  445.  termheight=400
  446.  
  447.  rect=(
  448.      $termwidth
  449.      $termheight
  450. -    $((${mrect[0]}+(${mrect[2]}-termwidth)/2))
  451. -    $((${mrect[1]}-termheight))
  452. +    $(( ${mrect[0]} + (${mrect[2]} - termwidth) / 2 ))
  453. +    $(( ${mrect[1]} - termheight ))
  454.  )
  455.  
  456.  y_line=${mrect[1]}
  457.  
  458.  
  459. -hc add scratchpad
  460. +hc add "$tag"
  461.  
  462.  
  463.  monitor=q3terminal
  464. @@ -45,9 +45,9 @@ if ! hc add_monitor $(printf "%dx%d%+d%+d" "${rect[@]}") \
  465.  else
  466.      # remember which monitor was focused previously
  467.      hc chain \
  468. -        , new_attr string monitors.by-name.$monitor.my_prev_focus \
  469. +        , new_attr string monitors.by-name."$monitor".my_prev_focus \
  470.          , substitute M monitors.focus.index \
  471. -            set_attr monitors.by-name.$monitor.my_prev_focus M
  472. +            set_attr monitors.by-name."$monitor".my_prev_focus M
  473.  fi
  474.  
  475.  update_geom() {
  476. @@ -61,19 +61,18 @@ interval=0.01
  477.  animate() {
  478.      progress=( "$@" )
  479.      for i in "${progress[@]}" ; do
  480. -        rect[3]=$((${y_line}-(i*termheight)/$steps))
  481. +        rect[3]=$((y_line - (i * termheight) / steps))
  482.          update_geom
  483.          sleep "$interval"
  484.      done
  485.  }
  486.  
  487.  show() {
  488. -
  489.      hc lock
  490. -    hc raise_monitor $monitor
  491. -    hc focus_monitor $monitor
  492. +    hc raise_monitor "$monitor"
  493. +    hc focus_monitor "$monitor"
  494.      hc unlock
  495. -    hc lock_tag $monitor
  496. +    hc lock_tag "$monitor"
  497.      animate $(seq $steps -1 0)
  498.  }
  499.  
  500. @@ -91,10 +90,10 @@ hide() {
  501.      animate $(seq 0 +1 $steps)
  502.      # if q3terminal still is focused, then focus the previously focused monitor
  503.      # (that mon which was focused when starting q3terminal)
  504. -    hc substitute M monitors.by-name.$monitor.my_prev_focus \
  505. -        and + compare monitors.focus.name = $monitor \
  506. +    hc substitute M monitors.by-name."$monitor".my_prev_focus \
  507. +        and + compare monitors.focus.name = "$monitor" \
  508.              + focus_monitor M
  509. -    hc remove_monitor $monitor
  510. +    hc remove_monitor "$monitor"
  511.  }
  512.  
  513.  [ $exists = true ] && hide || show
  514. diff --git a/scripts/savestate.sh b/scripts/savestate.sh
  515. index b717f46..d5ab007 100755
  516. --- a/scripts/savestate.sh
  517. +++ b/scripts/savestate.sh
  518. @@ -10,8 +10,8 @@ hc=${herbstclient_command:-herbstclient}
  519.  # and sometime later:
  520.  # loadstate.sh < mystate
  521.  
  522. -$hc complete 1 use |
  523. +"$hc" complete 1 use |
  524.  while read tag ; do
  525.      echo -n "$tag: "
  526. -    $hc dump "$tag"
  527. +    "$hc" dump "$tag"
  528.  done
  529. diff --git a/share/panel.sh b/share/panel.sh
  530. index 6bb01b1..849795e 100755
  531. --- a/share/panel.sh
  532. +++ b/share/panel.sh
  533. @@ -10,7 +10,7 @@ if [ -z "$geometry" ] ;then
  534.      echo "Invalid monitor $monitor"
  535.      exit 1
  536.  fi
  537. -# geometry has the format: WxH+X+Y
  538. +# geometry has the format W H X Y
  539.  x=${geometry[0]}
  540.  y=${geometry[1]}
  541.  panel_width=${geometry[2]}
  542. @@ -23,9 +23,9 @@ selfg='#101010'
  543.  ####
  544.  # Try to find textwidth binary.
  545.  # In e.g. Ubuntu, this is named dzen2-textwidth.
  546. -if [ -e "$(which textwidth 2> /dev/null)" ] ; then
  547. +if which textwidth &> /dev/null ; then
  548.      textwidth="textwidth";
  549. -elif [ -e "$(which dzen2-textwidth 2> /dev/null)" ] ; then
  550. +elif which dzen2-textwidth &> /dev/null ; then
  551.      textwidth="dzen2-textwidth";
  552.  else
  553.      echo "This script requires the textwidth tool of the dzen2 project."
  554. @@ -41,8 +41,8 @@ else
  555.      dzen2_svn=""
  556.  fi
  557.  
  558. -function uniq_linebuffered() {
  559. -    awk -W interactive '$0 != l { print ; l=$0 ; fflush(); }' "$@"
  560. +uniq_linebuffered() {
  561. +    awk -W interactive '$0 != l { print ; l=$0 ; fflush(); }' "$@" 2>/dev/null
  562.  }
  563.  
  564.  herbstclient pad $monitor $panel_height
  565. @@ -52,12 +52,12 @@ herbstclient pad $monitor $panel_height
  566.      while true ; do
  567.          date +'date ^fg(#efefef)%H:%M^fg(#909090), %Y-%m-^fg(#efefef)%d'
  568.          sleep 1 || break
  569. -    done > >(uniq_linebuffered)  &
  570. +    done > >(uniq_linebuffered) &
  571.      childpid=$!
  572.      herbstclient --idle
  573.      kill $childpid
  574.  } 2> /dev/null | {
  575. -    TAGS=( $(herbstclient tag_status $monitor) )
  576. +    tags=( $(herbstclient tag_status $monitor) )
  577.      visible=true
  578.      date=""
  579.      windowtitle=""
  580. @@ -65,7 +65,7 @@ herbstclient pad $monitor $panel_height
  581.          bordercolor="#26221C"
  582.          separator="^bg()^fg($selbg)|"
  583.          # draw tags
  584. -        for i in "${TAGS[@]}" ; do
  585. +        for i in "${tags[@]}" ; do
  586.              case ${i:0:1} in
  587.                  '#')
  588.                      echo -n "^bg($selbg)^fg($selfg)"
  589. @@ -84,7 +84,7 @@ herbstclient pad $monitor $panel_height
  590.                      ;;
  591.              esac
  592.              if [ ! -z "$dzen2_svn" ] ; then
  593. -                echo -n "^ca(1,herbstclient focus_monitor $monitor && "'herbstclient use "'${i:1}'") '"${i:1} ^ca()"
  594. +                echo -n "^ca(1,herbstclient focus_monitor $monitor && herbstclient use \"${i:1}\") ${i:1} ^ca()"
  595.              else
  596.                  echo -n " ${i:1} "
  597.              fi
  598. @@ -93,7 +93,7 @@ herbstclient pad $monitor $panel_height
  599.          echo -n "^bg()^fg() ${windowtitle//^/^^}"
  600.          # small adjustments
  601.          right="$separator^bg() $date $separator"
  602. -        right_text_only=$(echo -n "$right"|sed 's.\^[^(]*([^)]*)..g')
  603. +        right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g')
  604.          # get width of right aligned text.. and add some space..
  605.          width=$($textwidth "$font" "$right_text_only    ")
  606.          echo -n "^pa($(($panel_width - $width)))$right"
  607. @@ -105,7 +105,7 @@ herbstclient pad $monitor $panel_height
  608.          case "${cmd[0]}" in
  609.              tag*)
  610.                  #echo "resetting tags" >&2
  611. -                TAGS=( $(herbstclient tag_status $monitor) )
  612. +                tags=( $(herbstclient tag_status $monitor) )
  613.                  ;;
  614.              date)
  615.                  #echo "resetting date" >&2
  616. @@ -115,8 +115,8 @@ herbstclient pad $monitor $panel_height
  617.                  exit
  618.                  ;;
  619.              togglehidepanel)
  620. -                currentmonidx=$(herbstclient list_monitors |grep ' \[FOCUS\]$'|cut -d: -f1)
  621. -                if [ -n "${cmd[1]}" ] && [ "${cmd[1]}" -ne "$monitor" ] ; then
  622. +                currentmonidx=$(herbstclient list_monitors | sed -n '/\[FOCUS\]$/s/:.*//p')
  623. +                if [ "${cmd[1]}" -ne "$monitor" ] ; then
  624.                      continue
  625.                  fi
  626.                  if [ "${cmd[1]}" = "current" ] && [ "$currentmonidx" -ne "$monitor" ] ; then
  627. diff --git a/share/restartpanels.sh b/share/restartpanels.sh
  628. index 320a3fe..9d9110c 100755
  629. --- a/share/restartpanels.sh
  630. +++ b/share/restartpanels.sh
  631. @@ -2,15 +2,15 @@
  632.  
  633.  installdir=/
  634.  
  635. -XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
  636. +XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
  637.  defaultpanel="$XDG_CONFIG_HOME/herbstluftwm/panel.sh"
  638.  
  639. -[ -x "$defaultpanel" ] || defaultpanel=$installdir/etc/xdg/herbstluftwm/panel.sh
  640. +[ -x "$defaultpanel" ] || defaultpanel="$installdir/etc/xdg/herbstluftwm/panel.sh"
  641.  
  642. -panelcmd=${1:-$defaultpanel}
  643. +panelcmd="${1:-$defaultpanel}"
  644.  
  645.  herbstclient emit_hook quit_panel
  646.  
  647. -for i in $(herbstclient list_monitors|cut -d':' -f1) ; do
  648. -    $panelcmd $i &
  649. +for i in $(herbstclient list_monitors | cut -d':' -f1) ; do
  650. +    "$panelcmd" $i &
  651.  done
  652. --
  653. 1.8.3.1
  654.