scripts

various script and utils
git clone git://z3bra.org/scripts
Log | Files | Refs

commit 1cbcba3dd3b3d231d6c0059f10a845c4a03ca18f
parent ab3decbcbe448c33385aaed0aa389523565dcfef
Author: Willy Goiffon <w.goiffon@gmail.com>
Date:   Mon Nov  4 01:14:05 +0100

Merge branch 'master' of gitorious.org:z3bra/scripts

Diffstat:
bar/config.sh | 94+++++++++++++++++++++++++------------------------------------------------------
bar/status.sh | 109++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
2 files changed, 97 insertions(+), 106 deletions(-)
diff --git a/bar/config.sh b/bar/config.sh @@ -14,7 +14,6 @@ bg="0" fg="9" hl="8" -dk="1" # separator sp=" " @@ -22,67 +21,40 @@ sp=" " # path to executable bar="/usr/bin/bar -f" -# pipe to feed the bar -fifo=/tmp/bar.fifo - -# refresh frenquency (in seconds) -refresh=0.75 - -# info icons (from stlarch_font package. use gbdfed to view/modify font) -# i_arch='\ue0a1' # arch logo -# # i_pkgs='\ue14d' # pacman -# i_pkgs='\ue0aa' # pacman ghost -# i_mail='\ue072' # mail icon -# i_wifi='\ue0f0' # signal -# i_netw='\ue149' # wired -# i_time='\ue017' # clock -# # i_batt='\ue040' # thunder -# i_batt='\ue10c' # power -# i_load='\ue021' # micro chip -# i_memy='\ue145' # floppy -# i_musk='\ue04d' # headphones -# i_alsa='\ue05d' # speaker -i_arch='SYS' -i_pkgs='PKG' -i_mail='MSG' -i_wifi='SIG' -i_netw='NET' -# i_time='CLK' -i_batt='BAT' -i_load='CPU' -i_memy='RAM' -i_grap='GPU' -i_fans='FAN' -i_musk='MPD' -i_alsa='VOL' -i_mail='MSG' -i_time='CLK' +#info icons (from stlarch_font package. use gbdfed to view/modify font) +i_arch='\ue0a1' # arch logo +i_pkgs='\ue14d' # pacman +i_pkgs='\ue0aa' # pacman ghost +i_mail='\ue072' # mail icon +i_wifi='\ue0f0' # signal +i_netw='\ue149' # wired +i_time='\ue017' # clock +i_batt='\ue040' # thunder +i_sect='\ue10c' # power (on A/C) +i_load='\ue021' # micro chip +i_memy='\ue145' # floppy +i_musk='\ue04d' # headphones +i_alsa='\ue05d' # speaker # workspace icons / names (α β γ δ ε ζ η θ ι κ λ) -# i_trm=$(echo -e '\ue09f') # default -# i_web=$(echo -e '\ue0ab') # web browsing -# i_dev=$(echo -e '\ue19a') # intense coding -# i_com=$(echo -e '\ue074') # irc, voip, etc.. -# i_fun=$(echo -e '\ue19d') # games -# i_sys=$(echo -e '\ue09e') # sys admin -# i_wrk=$(echo -e '\ue146') # reports, etc.. -# i_meh=$(echo -e '\ue14d') # just chillin' -# i_far=$(echo -e '\ue00e') # just chillin' -i_trm=$(echo -e 'ZSH') -i_web=$(echo -e 'WEB') -i_dev=$(echo -e 'DEV') -i_com=$(echo -e 'IRC') -i_fun=$(echo -e 'FUN') -i_sys=$(echo -e 'SYS') -i_wrk=$(echo -e 'WRK') -i_meh=$(echo -e 'MEH') -i_far=$(echo -e 'ALL') +i_trm=$(echo -e '0') +i_web=$(echo -e '1') +i_dev=$(echo -e '2') +i_com=$(echo -e '3') +i_fun=$(echo -e '4') +i_sys=$(echo -e '5') +i_wrk=$(echo -e '6') +i_meh=$(echo -e '7') +i_far=$(echo -e '8') # specific parameters # desktop names dskp_tag=('' $i_trm $i_web $i_dev $i_com $i_fun $i_sys $i_wrk $i_meh $i_far) +# colors +colors=(black red green yellow blue cyan magenta white black white) + # now playing format mpc_format='[%title% ]|[%file%]' @@ -90,17 +62,11 @@ mpc_format='[%title% ]|[%file%]' alsa_channel='Master' # define you own interfaces -net_wire='enp4s0' -net_wifi='enp3s0' -# which interface do you want to use ? -net_interface=$net_wire +net_wire='eth0' +net_wifi='wlan0' # Only the time ? with seconds ? Maybe the current year...? date_format="%H.%M" -# used to get current workspace -wm_lib_xcb="XCB" # DO NOT MODIFY -wm_lib_xlib="XLIB" # DO NOT MODIFY -wm_lib=$wm_lib_xcb # which library does your WM use ? - # xcb *should* work with any WM, as it uses `xprop`, whereas - # xlib uses `wmctrl` which works ONLY with Xlib. +# The default program to use, is -O <program> is not passed +default_output='bar' diff --git a/bar/status.sh b/bar/status.sh @@ -2,30 +2,45 @@ source $(dirname $0)/config.sh +OUT=$default_output + +function fg() { + case $1 in + bar) echo "\f$2" ;; + tmux) echo "#[fg=${colors[$2]}]" ;; + none) echo "" ;; + ?) echo "\f$2" ;; + esac +} + +function bg() { + case $1 in + bar) echo "\b$2" ;; + tmux) echo "#[bg=$2]" ;; + none) echo "" ;; + ?) echo "\b$2" ;; + esac +} + # print formatted output. need 2 params: display <value> <icon> function display () { - echo -n "\f${hl}" - echo -ne "$2 " - echo "${dl}\f${fg}$1" + echo -n "$(fg $OUT ${hl})" + echo -en "$2 " + echo "$(fg $OUT ${fg})$1" } function workspaces () { - if [ "$wm_lib" = "$wm_lib_xcb" ]; then - dskp_num=$(xprop -root _NET_NUMBER_OF_DESKTOPS | cut -d ' ' -f3) - dskp_cur=$(xprop -root _NET_CURRENT_DESKTOP | cut -d ' ' -f3) - elif [ "$wm_lib" = "$wm_lib_xlib" ]; then - dskp_num=$(wmctrl -d| wc -l) - dskp_cur=$(wmctrl -d |grep '*' |cut -d' ' -f1) - fi + dskp_num=$(xprop -root _NET_NUMBER_OF_DESKTOPS | cut -d ' ' -f3) + dskp_cur=$(xprop -root _NET_CURRENT_DESKTOP | cut -d ' ' -f3) buffer="" for w in $(seq 1 $(($dskp_num-1))); do if [ "$w" -eq "$dskp_cur" ]; then - buffer="$buffer $(echo -e '\ue190') " - #buffer="$buffer\u${fg} ${dskp_tag[$w]} \u${bg}" - else - buffer="$buffer \f${hl}$(echo -e '\ue190')\fr " + buffer="$buffer$(echo -e '\ue190')" + #buffer="$buffer\u${fg} ${dskp_tag[$w]} \u${bg}" + else + buffer="$buffer$(fg $OUT ${hl})$(echo -e '\ue190')$(fg $OUT ${fg})" #buffer="$buffer ${dskp_tag[$w]} " fi done @@ -61,8 +76,9 @@ function groups() { function mails () { new=$(~/bin/mcount ~/var/mail/INBOX/new/) - cur=$(~/bin/mcount ~/var/mail/INBOX/cur/) - val="$new/$cur" + #cur=$(~/bin/mcount ~/var/mail/INBOX/cur/) + #val="$new/$cur" + val="$new" ico=${i_mail} display "$val" "$ico" @@ -81,14 +97,14 @@ function mpd_now_playing () { } function volume () { - val=$(amixer sget $alsa_channel | sed -n 's/.*\[\([0-9/]*%\)\].*/\1/p') + val=$(amixer sget $alsa_channel | sed -n 's/.*\[\([0-9/]*%\)\].*/\1/p' | uniq) ico=${i_alsa} display "$val" "$ico" } function battery () { - val=$(acpi -b | sed 's/^.*[^0-9%]//') + val=$(acpi -b | sed 's/^.* \([0-9]*%\).*$/\1/') ico=${i_batt} display "$val" "$ico" @@ -168,33 +184,42 @@ function network () { function clock () { val=$(date +${date_format}) - #val=$((100*$(date +%H%M)/2400)) # Give the time in percentage ico=${i_time} display "$val" "$ico" } function fillbar () { - buffer="\b${bg}\f${fg}\l\u${bg} " - buffer="$buffer$(mpd_now_playing) " - buffer="$buffer\c" - buffer="$buffer$(groups) " - buffer="$buffer\r" - # buffer="$buffer$(network) ${sp}" - buffer="$buffer$(mails) ${sp}" - buffer="$buffer$(memory) ${sp}" - #buffer="$buffer$(processes) ${sp}" - #buffer="$buffer$(gputemp) ${sp}" - buffer="$buffer$(gpufanspeed) ${sp}" - buffer="$buffer$(volume) ${sp}" - #buffer="$buffer$(packages) ${sp}" - buffer="$buffer$(clock)" - buffer="$buffer " - echo "$buffer" -} - -while :; do - source $(dirname $0)/config.sh - fillbar - sleep ${refresh} -done | ${bar} + while getopts "B:F:H:LCRO:s:bcflmnprtvw" opt; do + case $opt in + # Specific options for bar-aint-recursive + B) bg=$OPTARG ;; # background color + F) fg=$OPTARG ;; # foreground color + H) hl=$OPTARG ;; # highlights color + L) buffer="${buffer}\l " ;; # left justify + C) buffer="${buffer}\c " ;; # center text + R) buffer="${buffer}\r " ;; # right justify + + # Which program is the output intended for ? (bar|tmux|none) + O) OUT=$OPTARG ;; + + # Content of the output + b) buffer="${buffer}$(battery) ${sp}" ;; + c) buffer="${buffer}$(clock) ${sp}" ;; + f) buffer="${buffer}$(gpufanspeed) ${sp}" ;; + l) buffer="${buffer}$(mpd_now_playing) ${sp}" ;; + m) buffer="${buffer}$(mails) ${sp}" ;; + n) buffer="${buffer}$(network) ${sp}" ;; + p) buffer="${buffer}$(processes) ${sp}" ;; + r) buffer="${buffer}$(memory) ${sp}" ;; + t) buffer="${buffer}$(gputemp) ${sp}" ;; + v) buffer="${buffer}$(volume) ${sp}" ;; + w) buffer="${buffer}$(groups) ${sp}" ;; + esac + done + + # Set the default fg/bg and remove trailing separator (if any) + echo "$(bg $OUT ${bg})$(fg $OUT ${fg}) $buffer " | sed "s/${sp}$//" +} + +fillbar $@