Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 129 lines (114 sloc) 3.741 kb
648126dc »
2012-03-23 initial commit
1 #!/bin/bash
ab926053 »
2012-03-27 update dwm-start & script headers
2 #
3 # ~/bin/dwm-statusbar
4 #
2009cfb0 »
2013-01-26 dwm-statusbar: make code a little neater
5 # Status bar for dwm. Expanded from:
a889240d »
2013-01-24 dwm-statusbar: cosmetic changes
6 # https://bitbucket.org/jasonwryan/eeepc/src/73dadb289dead8ef17ef29a9315ba8f1706927cb/Scripts/dwm-status
648126dc »
2012-03-23 initial commit
7
0e71bd19 »
2013-03-15 dwm-statusbar: use variables for colour and glyph codes
8 # Colour codes from dwm/config.h
9 colour_gry="\x01" # grey on black
10 colour_wht="\x02" # white on black
11 colour_dgry="\x04" # darkgrey on black
12 colour_blk="\x05" # black on darkgrey
13 colour_red="\x06" # colour_red on black
14 colour_grn="\x07" # green on black
15 colour_dylw="\x08" # orange on black
16 colour_ylw="\x09" # yellow on black
17 colour_blu="\x0A" # colour_blue on darkgrey
18 colour_mag="\x0B" # colour_magenta on darkgrey
19 colour_cyn="\x0C" # cyan on darkgrey
20
21 # Icon glyphs from font xbmicons.pcf
22 glyph_msc="\uE00E"
23 glyph_cpu="\uE00F"
24 glyph_mem="\uE010"
25 glyph_dl="\uE011"
26 glyph_ul="\uE012"
27 glyph_com="\uE013"
28 glyph_eml="\uE014"
29 glyph_vol="\uE015"
30 glyph_tim="\uE016"
31 glyph_tor="\uE017"
32 sep_solid="\uE01A"
33 sep_line="\uE01B"
7762cf45 »
2013-12-21 dwm-statusbar: rm powerline glyphs; add vertbar glyph
34 sep_bar="\uE020"
0e71bd19 »
2013-03-15 dwm-statusbar: use variables for colour and glyph codes
35
57436bee »
2012-04-19 add torrent download status
36 print_song_info() {
7762cf45 »
2013-12-21 dwm-statusbar: rm powerline glyphs; add vertbar glyph
37 song_info="$(ncmpcpp --now-playing '{{{{%a - }%t}}|{%f}}' | head -c 75)"
2009cfb0 »
2013-01-26 dwm-statusbar: make code a little neater
38 if [[ ! $song_info ]]; then
39 song_info="Off"
40 fi
7762cf45 »
2013-12-21 dwm-statusbar: rm powerline glyphs; add vertbar glyph
41 echo -ne "${colour_cyn} ${glyph_msc} ${song_info} "
57436bee »
2012-04-19 add torrent download status
42 }
43
44 print_torrent_status() {
2009cfb0 »
2013-01-26 dwm-statusbar: make code a little neater
45 torrent_status="$(transmission-remote -l | awk -F " +" '$5 ~ /^[0-9]/ {print $5}')"
46 if [[ ! $torrent_status ]]; then
47 torrent_status="Idle"
48 fi
7762cf45 »
2013-12-21 dwm-statusbar: rm powerline glyphs; add vertbar glyph
49 echo -ne "${colour_dylw} ${glyph_tor} ${torrent_status} "
648126dc »
2012-03-23 initial commit
50 }
51
e4fc86fe »
2013-01-22 dwm-statusbar: add wongdev new mail count
52 print_email_unread() {
7762cf45 »
2013-12-21 dwm-statusbar: rm powerline glyphs; add vertbar glyph
53 echo -ne "${colour_ylw} ${glyph_eml} "
2009cfb0 »
2013-01-26 dwm-statusbar: make code a little neater
54 for maildir in $(find $HOME/.mutt/maildir/*/inbox/new -type d); do
55 unread_count="$(ls "${maildir}" | wc -l)"
7762cf45 »
2013-12-21 dwm-statusbar: rm powerline glyphs; add vertbar glyph
56 echo -n "${unread_count} "
2009cfb0 »
2013-01-26 dwm-statusbar: make code a little neater
57 done
6e78d31f »
2012-04-26 vimpowerline appearance
58 }
59
60 print_last_msg() {
36898d89 »
2012-04-29 mv dotfiles/logs, rename ~ to $HOME
61 last_msg="$(cat $HOME/.logs/irssi_pipe)"
7762cf45 »
2013-12-21 dwm-statusbar: rm powerline glyphs; add vertbar glyph
62 echo -ne "${colour_dylw} ${glyph_com} ${last_msg} "
648126dc »
2012-03-23 initial commit
63 }
64
65 print_mem_used() {
2009cfb0 »
2013-01-26 dwm-statusbar: make code a little neater
66 mem_used="$(free -m | awk 'NR==3 {print $3}')"
be1b9c67 »
2013-12-21 dwm-statusbar: fix spacing
67 echo -ne "${sep_bar} ${glyph_mem} ${mem_used}M "
648126dc »
2012-03-23 initial commit
68 }
69
70 print_volume() {
eb4fb610 »
2012-05-18 volume: use PCM instead of Master
71 volume="$(amixer get PCM | tail -n1 | sed -r 's/.*\[(.*)%\].*/\1/')"
7762cf45 »
2013-12-21 dwm-statusbar: rm powerline glyphs; add vertbar glyph
72 echo -ne "${colour_mag} ${glyph_vol} ${volume}% "
648126dc »
2012-03-23 initial commit
73 }
74
75 print_datetime() {
be1b9c67 »
2013-12-21 dwm-statusbar: fix spacing
76 datetime="$(date "+%a %d %b ${sep_bar} %H:%M")"
7762cf45 »
2013-12-21 dwm-statusbar: rm powerline glyphs; add vertbar glyph
77 echo -ne "${colour_wht} ${glyph_tim} ${datetime} "
648126dc »
2012-03-23 initial commit
78 }
79
a889240d »
2013-01-24 dwm-statusbar: cosmetic changes
80 # network (from: http://dzen.geekmode.org/dwiki/doku.php?id=dzen:network-meter)
81 # cpu (from: https://bbs.archlinux.org/viewtopic.php?pid=661641#p661641)
4517a482 »
2013-12-23 dwm-statusbar: s/eth0/enp4s0/
82 rx_old=$(cat /sys/class/net/enp4s0/statistics/rx_bytes)
83 tx_old=$(cat /sys/class/net/enp4s0/statistics/tx_bytes)
648126dc »
2012-03-23 initial commit
84
85 while true; do
86 # get new cpu idle and total usage
85144d4d »
2012-03-23 fix readability
87 eval $(awk '/^cpu /{print "cpu_idle_now=" $5 "; cpu_total_now=" $2+$3+$4+$5 }' /proc/stat)
648126dc »
2012-03-23 initial commit
88 cpu_interval=$((cpu_total_now-${cpu_total_old:-0}))
89 # calculate cpu usage (%)
85144d4d »
2012-03-23 fix readability
90 let cpu_used="100 * ($cpu_interval - ($cpu_idle_now-${cpu_idle_old:-0})) / $cpu_interval"
98432ee8 »
2012-03-23 fix indents
91
648126dc »
2012-03-23 initial commit
92 # get new rx/tx counts
4517a482 »
2013-12-23 dwm-statusbar: s/eth0/enp4s0/
93 rx_now=$(cat /sys/class/net/enp4s0/statistics/rx_bytes)
94 tx_now=$(cat /sys/class/net/enp4s0/statistics/tx_bytes)
648126dc »
2012-03-23 initial commit
95 # calculate the rate (K) and total (M)
96 let rx_rate=($rx_now-$rx_old)/1024
97 let tx_rate=($tx_now-$tx_old)/1024
a889240d »
2013-01-24 dwm-statusbar: cosmetic changes
98 # let rx_total=$rx_now/1048576
99 # let tx_total=$tx_now/1048576
648126dc »
2012-03-23 initial commit
100
101 # output vars
0e71bd19 »
2013-03-15 dwm-statusbar: use variables for colour and glyph codes
102 print_cpu_used() {
be1b9c67 »
2013-12-21 dwm-statusbar: fix spacing
103 printf "%-10b" "${colour_blu} ${glyph_cpu} ${cpu_used}% "
0e71bd19 »
2013-03-15 dwm-statusbar: use variables for colour and glyph codes
104 }
105 print_rx_rate() {
be1b9c67 »
2013-12-21 dwm-statusbar: fix spacing
106 printf "%-11b" "${colour_grn} ${glyph_dl} ${rx_rate}K "
0e71bd19 »
2013-03-15 dwm-statusbar: use variables for colour and glyph codes
107 }
108 print_tx_rate() {
be1b9c67 »
2013-12-21 dwm-statusbar: fix spacing
109 printf "%-15b" "${colour_gry}${sep_bar} ${colour_red}${glyph_ul} ${tx_rate}K"
0e71bd19 »
2013-03-15 dwm-statusbar: use variables for colour and glyph codes
110 }
648126dc »
2012-03-23 initial commit
111
112 # Pipe to status bar, not indented due to printing extra spaces/tabs
a889240d »
2013-01-24 dwm-statusbar: cosmetic changes
113 xsetroot -name "$(print_song_info)\
114 $(print_torrent_status)\
115 $(print_email_unread)\
116 $(print_last_msg)\
117 $(print_cpu_used)$(print_mem_used)\
118 $(print_rx_rate)$(print_tx_rate)\
119 $(print_volume)\
120 $(print_datetime)"
648126dc »
2012-03-23 initial commit
121
122 # reset old rates
123 rx_old=$rx_now
124 tx_old=$tx_now
125 cpu_idle_old=$cpu_idle_now
126 cpu_total_old=$cpu_total_now
127 # loop stats every 1 second
128 sleep 1
129 done
Something went wrong with that request. Please try again.