From fd40e4ddaefc70acb2cedcbe69bce49077a62376 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 29 Jan 2015 00:53:11 -0500 Subject: wmii: Make rbar way cooler --- .config/wmii-hg/config.sh | 6 +++++- .config/wmii-hg/rbar.sh | 18 +++++++++++++++++ .config/wmii-hg/rbar_acpi | 27 +++++++++++++------------ .config/wmii-hg/rbar_clock | 23 ++++++++++++---------- .config/wmii-hg/rbar_wifi | 49 ++++++++++++++++++++++++++++++++++------------ 5 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 .config/wmii-hg/rbar.sh diff --git a/.config/wmii-hg/config.sh b/.config/wmii-hg/config.sh index d1da234..be75d65 100644 --- a/.config/wmii-hg/config.sh +++ b/.config/wmii-hg/config.sh @@ -154,7 +154,11 @@ Event() { ## RightBar events RightBarMouseDown) ## $1=button $2=bar_item - ;; + local button=$1 + local item=$2 + local name=${item#[0-9][0-9]_} + name=${name%.*} + Action "rbar_$name" "$button" & ;; RightBarClick) ## $1=button $2=bar_item ;; RightMouseDND) ## $1=button $2=bar_item diff --git a/.config/wmii-hg/rbar.sh b/.config/wmii-hg/rbar.sh new file mode 100644 index 0000000..8297b71 --- /dev/null +++ b/.config/wmii-hg/rbar.sh @@ -0,0 +1,18 @@ +#!/bin/bash +setup_trap() { + trap "rm -f -- ${HOME}/n/wmii*/rbar/${1}" EXIT +} + +write() { + dirs=("${HOME}"/n/wmii*/rbar/) + sponge|tee -a "${dirs[@]/%/${1}}" > /dev/null +} + +set -eE +shopt -s nullglob +case "$1" in + 1) left-click;; + 2) middle-click;; + 3) right-click;; + *) update "$1";; +esac diff --git a/.config/wmii-hg/rbar_acpi b/.config/wmii-hg/rbar_acpi index 1771875..bdcdf0f 100755 --- a/.config/wmii-hg/rbar_acpi +++ b/.config/wmii-hg/rbar_acpi @@ -1,15 +1,18 @@ #!/bin/bash -. include.sh -id=$1 -trap "rm -f ${WMII_DIR}/rbar/${id}.*" EXIT +update() { + id=$1 + setup_trap "${id}.*" -while connected_to_x_server; do - acpi -bt | sed -r \ - -e 's/^([A-Z])[a-z]+ ([0-9]+):/\1\2:/' \ - -e 's/\s*degrees\s*/°/g' | - cat -n | while read -r n line; do - printf "label %s\n" "$line" >> "${WMII_DIR}/rbar/${id}.${n}" - done - sleep 1 -done + while true; do + acpi -bt | sed -r \ + -e 's/^([A-Z])[a-z]+ ([0-9]+):/\1\2:/' \ + -e 's/\s*degrees\s*/°/g' | + cat -n | while read -r n line; do + printf "label %s\n" "$line" | write "${id}.${n}" + done + sleep 1 + done +} + +. "$(dirname "$0")/rbar.sh" diff --git a/.config/wmii-hg/rbar_clock b/.config/wmii-hg/rbar_clock index c1692da..a09f016 100755 --- a/.config/wmii-hg/rbar_clock +++ b/.config/wmii-hg/rbar_clock @@ -1,13 +1,16 @@ #!/bin/bash -. include.sh -id=$1 -trap "rm -f ${WMII_DIR}/rbar/${id}" EXIT +update() { + id=$1 + setup_trap "$id" -while connected_to_x_server; do - { - printf 'label ' - date +'%a, %F %T %Z(%:::z)' - } |sponge >> "${WMII_DIR}/rbar/${id}" - sleep .5 -done + while true; do + { + printf 'label ' + date +'%a, %F %T %Z(%:::z)' + } | write "$id" + sleep .5 + done +} + +. "$(dirname "$0")/rbar.sh" diff --git a/.config/wmii-hg/rbar_wifi b/.config/wmii-hg/rbar_wifi index 53464dc..63dc653 100755 --- a/.config/wmii-hg/rbar_wifi +++ b/.config/wmii-hg/rbar_wifi @@ -1,11 +1,7 @@ #!/bin/bash -. include.sh - -id=$1 -trap "rm -f ${WMII_DIR}/rbar/${id}" EXIT iwinfo() { - interface=$1 + local interface=$1 iwconfig "$interface" | sed -r 's/ {2,}/\n/g' | sed -e '/^\s*$/d' -e 's/:\s*/=/' \ @@ -13,10 +9,39 @@ iwinfo() { -e '2s/^/MAC Protocol=/' } -while connected_to_x_server; do - { - printf 'label ' - iwinfo wlp2s0|grep -E '^(ESSID|Link Quality)='|sed 'N;s/\n/ | /' - } | sponge >> "${WMII_DIR}/rbar/${id}" - sleep 1 -done +update() { + local id + id=$1 + setup_trap "$id" + while true; do + { + printf 'label ' + iwinfo wlp2s0|grep -E '^(ESSID|Link Quality)='|sed 'N;s/\n/ | /' + } | write "$id" + sleep 1 + done +} + +right-click() { + local list cur item + + list=() + IFS='' + while read -r line; do + list+=("$line") + done < <(netctl-auto list | sed 's,$,$,' | column -s '$' -t) + + cur='' + for item in "${list[@]}"; do + if [[ "$item" = '* '* ]]; then + cur="$item" + fi + done + + item=$(wmii9menu -i "$cur" "${list[@]}") + if [[ -n $item ]] && [[ "$item" != '* '* ]]; then + netctl-auto switch-to "$item" + fi +} + +. "$(dirname "$0")/rbar.sh" -- cgit v1.2.3-54-g00ecf