guest@dotshare [~/groups/wms/herbstluft] $ ls I-got-the-herbst/ | cat

I got the herbst (scrot)

mahatman2 Apr 10, 2012 (wms/herbstluft)

autostart(raw, dl)

SCROT

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash

# this is a simple config for herbstluftwm

function hc() {
    herbstclient "$@"
}

hc emit_hook reload

# remove all existing keybindings
hc keyunbind --all

# modules
## colors
hfsdir="$HOME/.config/herbstluftwm/scripts"
source "$hfsdir/colors";

# keybindings
Mod=Mod4
hc keybind $Mod-Shift-q quit
hc keybind $Mod-Shift-r reload
hc keybind $Mod-c close
## apps
hc keybind $Mod-Return spawn urxvtc
hc keybind $Mod-w spawn luakit
hc keybind $Mod-m spawn urxvtc -e mutt
hc keybind $Mod-n spawn urxvtc -e newsbeuter -r
hc keybind $Mod-p spawn urxvtc -e ncmpcpp
hc keybind $Mod-f spawn urxvtc -e ranger
hc keybind $Mod-e spawn urxvtc -e vim
hc keybind $Mod-space spawn dmenu_run -i -nb "${color['black']}" \
              -nf "${color['white']}" -sb "${color['blue']}" \
              -sf "${color['black']}"
hc keybind $Mod-F3 spawn $hfsdir/volume.sh Master 5%-
hc keybind $Mod-F4 spawn $hfsdir/volume.sh Master 5%+
hc keybind $Mod-F2 spawn $hfsdir/volume.sh Master toggle
hc keybind $Mod-Shift-w spawn urxvtc -e wicd-curses

# tags
TAG_NAMES=( {1..9} )
TAG_KEYS=( {1..9} 0 )

hc rename default "${TAG_NAMES[0]}" || true
for i in ${!TAG_NAMES[@]} ; do
    hc add "${TAG_NAMES[$i]}"
    key="${TAG_KEYS[$i]}"
    if ! [ -z "$key" ] ; then
        hc keybind "$Mod-$key" use_index "$i"
        hc keybind "$Mod-Shift-$key" move_index "$i"
    fi
done

# cycle through tags
hc keybind $Mod-period spawn $hfsdir/nexttag.sh
hc keybind $Mod-comma  spawn $hfsdir/prevtag.sh
hc keybind $Mod-Right use_index +1
hc keybind $Mod-Left  use_index -1

# layouting
hc keybind $Mod-d remove
hc keybind $Mod-semicolon cycle_layout 1
hc keybind $Mod-u split vertical 0.5
hc keybind $Mod-o split horizontal 0.5
hc keybind $Mod-backslash floating toggle
hc keybind $Mod-equal fullscreen toggle
hc keybind $Mod-minus pseudotile toggle

# resizing
RESIZESTEP=0.05
hc keybind $Mod-Control-h resize left +$RESIZESTEP
hc keybind $Mod-Control-j resize down +$RESIZESTEP
hc keybind $Mod-Control-k resize up +$RESIZESTEP
hc keybind $Mod-Control-l resize right +$RESIZESTEP

# mouse
hc mousebind $Mod-Button1 move
hc mousebind $Mod-Button3 resize
hc mousebind $Mod-Button2 zoom

# focus
hc keybind $Mod-BackSpace   cycle_monitor
hc keybind $Mod-Tab         cycle +1
hc keybind $Mod-Shift-Tab   cycle -1
hc keybind $Mod-Control-Tab cycle_all +1
hc keybind $Mod-Control-Shift-Tab cycle_all -1
#hc keybind $Mod-Shift-c cycle
hc keybind $Mod-h focus left
hc keybind $Mod-j focus down
hc keybind $Mod-k focus up
hc keybind $Mod-l focus right
hc keybind $Mod-Shift-h shift left
hc keybind $Mod-Shift-j shift down
hc keybind $Mod-Shift-k shift up
hc keybind $Mod-Shift-l shift right

# crazy stuff !
## open a horizontal split & move active window into it
hc keybind $Mod-Shift-o spawn $hfsdir/opensplit.sh h 0.5
hc keybind $Mod-Shift-u spawn $hfsdir/opensplit.sh v 0.5

# settings
hc set tree_style "╾ ╼"
hc set frame_bg_transparent 1
hc set default_frame_layout 2

## colors
hc set frame_border_active_color ${color["magenta"]}
hc set frame_border_normal_color ${color["black"]}
hc set frame_bg_normal_color ${color["black"]}
hc set frame_bg_active_color ${color["gray"]}
hc set frame_border_width 1
hc set window_border_width 1
hc set window_border_normal_color ${color["black"]}
hc set window_border_active_color ${color["blue"]}
hc set always_show_frame 1
hc set window_gap 4

# panel
(sleep 1s && hc spawn $hfsdir/panel.sh)

# rules
hc unrule -F
#hc rule class=XTerm tag=3 # move all xterms to tag 3
hc rule focus=on # normally *DO* focus new clients
# give focus to most common terminals
hc rule class~'(.*[Rr]xvt.*|.*[Tt]erm|Konsole)' focus=on
hc rule windowtype~'_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)' pseudotile=on
hc rule windowtype='_NET_WM_WINDOW_TYPE_DIALOG' focus=on
hc rule windowtype~'_NET_WM_WINDOW_TYPE_(NOTIFICATION|DOCK)' manage=off
hc rule class='Gvim' pseudotile=on
hc rule class='feh' pseudotile=on
hc rule class='Gcolor2' pseudotile=on
hc rule class='Agave' pseudotile=on
## GIMP
# use tag 9
hc load 9 '
(split horizontal:0.850000:0
  (split horizontal:0.200000:1
    (clients vertical:0)
    (clients max:0))
  (clients vertical:0))
'                         #load predefined layout
# center all other gimp windows on tag 9
hc rule class=Gimp tag=9 index=01 pseudotile=on
hc rule class=Gimp windowrole~'gimp-(image-window|toolbox|dock)' \
  pseudotile=off
hc rule class=Gimp windowrole=gimp-toolbox focus=off index=00
hc rule class=Gimp windowrole=gimp-dock focus=off index=1

CLICK TO VIEW

x

panel.sh(raw, dl)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash

# CONFIG
## get colors
source "$HOME/.config/herbstluftwm/scripts/colors"
cFG=${color["white"]};
cBG=${color["black"]};
## icon dir
iDir="$HOME/.config/herbstluftwm/scripts/icons"
monitor=${1:-0}
geometry=( $(herbstclient monitor_rect "$monitor") )
if [ -z "$geometry" ]; then
  echo "Invalid monitor $monitor"
  exit 1
fi
## geometry has the format: WxH+X+Y
x=${geometry[0]}
y=${geometry[1]}
width=${geometry[2]}
height=16
font="-*-terminus-*-*-*-*-14-*-*-*-*-*-*-*"
sep="^fg(${color['gray']})^ro(1x$height)^fg()"
align="left" # l, c, r
hci="$HOME/.config/herbstluftwm/hci"
long_string_cutoff=45
hfsdir="$HOME/.config/herbstluftwm/scripts"

# MODULES
icon() { # $1=<letter>|<icon name> $2=color
  if [ ${#1} -eq 1 ]; then # allow also to input letters
    echo -n "^fg(${color[${2}]})^bg($cBG)${1}^bg()^fg()"; 
  else
    echo -n "^fg(${color[${2}]})^bg($cBG)^i(${iDir}/${1}.xbm)^bg()^fg()";
  fi
}
herbstags() {
  local tFG=${color["black"]}  # normal tag
  local tBG=${color["black"]} 
  local tAfg=${color["brightcyan"]}  # active tag local tAbg=${color["black"]}
  local tPfg=${color["gray"]}  # populated tag
  local tPbg=${color["black"]}
  local tNfg=${color["brightred"]}   # urgent (notice) tag
  local tNbg=${color["black"]}
  echo -n "$(icon t brightmagenta)["
  TAGS=( $(herbstclient tag_status $monitor) )
  for i in "${TAGS[@]}"; do
    local click="^ca(1,herbstclient use ${i:1})"
    case ${i:0:1} in
      '#') echo -n "^fg($tAfg)^bg($tAbg)$click${i:1}"
      ;;
      ':') echo -n "^fg($tPfg)^bg($tPbg)$click${i:1}"
      ;;
      '!') echo -n "^fg($tNfg)^bg($tNbg)$click${i:1}"
      ;;
      *) 
      echo -n ""
      #echo -n "^fg($tFG)^bg($tBG)${i:1}"
      ;;
    esac
    echo -n "^fg()^bg()^ca()"
  done
  echo -n "]"
}
wintitle() {
  local title="$(xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d' ' -f5) _NET_WM_NAME | sed 's/_NET_WM_NAME.*= "\(.*\)"/\1/')"
  echo -n "$(cut -c -$long_string_cutoff <<<$title)"
}
m() {
  mpc -f %$1% current | sed 's/ä/ae/g' | sed 's/ö/oe/g' | sed 's/ü/ue/g'
}
tunes() {
  echo -n "^ca(1,urxvtc -e ncmpcpp)"
  case "$(mpc | head -2 | tail -1 | awk '{print $1}' | sed 's/\[\(.*\)\]/\1/g')" in
    playing)
    local icon="$(icon note brightblue)"
    local before="[^fg(${color['magenta']})"
    local playing="$(m artist) | $(m title) | $(m album)]"
    local after="^fg()]";;
    paused)
    local icon="$(icon stop brightblue)"
    local before="[^fg(${color['gray']})"
    local playing="$(m artist) | $(m title) | $(m album)"
    local after="^fg()]";;
    *)
    local icon="$(icon note brightblue)"
    local playing="[]";;
  esac
  echo -n "$icon$before$(cut -c -$long_string_cutoff <<<$playing)$after^ca()"
}
volume() { # $1=channel
  local stat=$(amixer sget $1 | awk '/\[on\]/{print $4}')
  if [ -z $stat ]; then
    local iVol=$(icon spkr_02 white)
    local stat="^fg(${color["gray"]})$(amixer sget $1 | awk '/\[off\]/{print $4}')^fg()"
  else
    local iVol=$(icon spkr_01 brightyellow)
  fi
  echo -n "^ca(1,$hfsdir/volume.sh Master toggle)$iVol$stat^ca()"
}
bat() {
  local status=$(acpi | awk '{print $3}' | sed 's/,//')
  local percent=$(acpi | awk '{print $4}' | sed 's/[,%]//g')
  case $status in
    Discharging) power_color="brightmagenta"; pwr_sign="-" ;;
    Charging) power_color="brightgreen"; pwr_sign="+";;
    Full) power_color="brightblue"; pwr_sign="";;
  esac
  local lo_power=15;
  local hi_power=75;
  if [ $percent -le $lo_power ]; then
    power_icon="bat_empty_01";
  elif [ $percent -gt $lo_power ] && [ $percent -le $hi_power ]; then
    power_icon="bat_low_01"
  elif [ $percent -gt $hi_power ] && [ $percent -lt 100 ]; then
    power_icon="bat_full_01"
  elif [ $percent -eq 100 ]; then
    power_icon="ac_01"
  fi
  echo -n "$(icon ${power_icon} ${power_color})[$pwr_sign$percent%]"
}
wifi() { # $1=interface
  iwconfig $1 | awk '/Quality/ {print $2}' | sed 's/.*=//' | \
  awk -F"/" '{printf("%.0f%%\n", $1/$2*100)}'
}
eth() { # (internet) $1=interface
  ifconfig $1 | awk -F: '/inet addr:/ {print $2}' | sed 's/[^0-9.]//g'
}
net() {
  local prog="urxvtc -e wicd-curses"
  if [ -n "$(wifi wlan0)" ]; then
    local Net="$(icon wifi_02 brightyellow)[$(wifi wlan0)]";
  elif [ -n "$(eth eth0)" ]; then
    local Net="$(icon net_wired brightblue)[$(eth eth0)]";
  else
    local Net="$(icon i brightred)[]";
  fi
  echo -n "^ca(1,$prog)$Net^ca()"
}
mail() { # $1=user $2=pass
  local prog="urxvt -c mutt"
  local mail_feed="https://mail.google.com/mail/feed/atom"
  local new=$(curl -u "$1":"$2" --silent $mail_feed | grep "<fullcount>" | \
              sed 's/<\/\?\w\+>//g')
  if [[ $new -gt 0 && "$(net)" != "$(icon i brightred)[]" ]]; then
    echo -n "^ca(1,$prog)$(icon mail brightcyan)[$new]^ca()";
  else
    echo -n "";
  fi
}

# GETTING THINGS DONE
function uniq_linebuffered() {
awk '$0 != l { print ; l=$0 ; fflush(); }' "$@"
}
herbstclient pad $monitor $height
(
while true ; do
        date +"date $(icon clock brightgreen)[$(date +"%H.%M %a.%d")]"
        mpcshow="$(tunes)"
        echo "mpc $mpcshow $sep"
        Bat="$(bat)"
        echo "bat $Bat $sep"
        Net="$(net) "
        echo "net $Net"
        Mail="$(mail user pass)"
        echo "mail $Mail $sep"
        sleep 1 || break
done | uniq_linebuffered &

herbstclient --idle &
)|(
Tag="$(herbstags) $sep"
date=""
mpcshow=""
Title=""
Volume="$(volume Master) $sep"
while true; do
    #echo -n "$Tag $Title $mpcshow $Volume $Bat $Net$Mail $date"
    echo -n "$Tag $Title"
    # right alignment
    right=""
    for func in $mpcshow $Volume $Bat $Net $Mail $date; do
      right="${right} ${func}"
    done
    right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g')
    ## get width of right-aligned text. and add some space.
    width=$(textwidth "$font" "$right_text_only  ")
    echo -n "^p(_RIGHT)^p(-$width)$right"
    echo

    # listen for events
    read line || break
    cmd=( $line )
    case "$cmd[0]" in
        date*)          date="${cmd[@]:1}"             ;;
        tag*)           Tag="$(herbstags) $sep"        ;;
        mpc*)           mpcshow="${cmd[@]:1}"          ;;
        focus*|*title*) Title="$(wintitle)"            ;;
        volume*)        Volume="$(volume Master) $sep" ;;
        bat*)           Bat="${cmd[@]:1}"              ;;
        net*)           Net="${cmd[@]:1} "             ;;
        mail*)          Mail="${cmd[@]:1}"             ;;
        quit_panel*)    exit 0                         ;;
        reload*)        exit 0                         ;;
    esac
done
)|dzen2 -w $width -h $height -x $x -y $y -fn "$font" \
  -ta $align -bg "$cBG" -fg "$cFG"
 

x

colors(raw, dl)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash
# To try to get the colors from xdefaults

xrdb=( $(xrdb -query | grep -P "color[0-9]*:" | sort | cut -f 2-) )

declare -A color

index=0

for name in black brightgreen brightyellow brightblue brightmagenta brightcyan brightwhite red green yellow blue magenta cyan white gray brightred; do
  color[${name}]=${xrdb[$index]}
  ((index++))
done
 

x

opensplit.sh(raw, dl)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash

dir=$1;
amount=$2;

herbstclient split $1 $2;
case $dir in
  v*) herbstclient shift down ;;
  h*) herbstclient shift right;;
  *)  echo "Nope"; exit 1     ;;
esac

exit 0;
 

x

seektag.sh(raw, dl)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash

# set vars
tags="$1" # all, busy
case $2 in
  +|next) dir="+";;
  -|prev) dir="-";;
esac
lobound=1; # first tag
hibound=9; # last tag

tagstat=$(herbstclient tag_status)

function checkbusy() {
  case "$tagstat" in
    *':'$next*) busy=1;;
    *)          busy=2;;
  esac
}
function checkbound() {
  if [ $next -gt $hibound ]; then
    next=$lobound;
  fi
  if [ $next -lt $lobound ]; then
    next=$hibound;
  fi
}

# get current tag
for t in {1..9}; do
  case "$tagstat" in
    *"#$t"*) curtag=$t;;
  esac
done

case $tags in
  "busy")
    # only switch to busy tags
    if [[ "$tagstat" == *':'* ]]; then
      busy=2
      next=$curtag
      while [ $busy != 1 ]; do
        next=$(($next $dir 1))
        checkbound
        checkbusy
      done
      herbstclient use $next
    else
      exit
    fi
  ;;
  "all")
    # switch between all tags
    next=$(($curtag $dir 1))
    checkbound
    herbstclient use $next
  ;;
  *)
    exit 1
  ;;
esac
 

x

Notes

Gets colors from xdefaults. Woopwoop