Merge lp:~jamesodhunt/byobu/unicode-enhancements into lp:byobu
- unicode-enhancements
- Merge into trunk
Proposed by
James Hunt
Status: | Merged |
---|---|
Merged at revision: | 1297 |
Proposed branch: | lp:~jamesodhunt/byobu/unicode-enhancements |
Merge into: | lp:byobu |
Diff against target: |
978 lines (+921/-2) 7 files modified
debian/changelog (+13/-0) usr/lib/byobu/Makefile.am (+1/-1) usr/lib/byobu/uclock (+173/-0) usr/lib/byobu/ugraph (+212/-0) usr/lib/byobu/ulevel (+481/-0) usr/lib/byobu/wastebasket (+39/-0) usr/lib/byobu/wifi_quality (+2/-1) |
To merge this branch: | bzr merge lp:~jamesodhunt/byobu/unicode-enhancements |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dustin Kirkland | Pending | ||
Review via email: mp+48561@code.launchpad.net |
Commit message
Description of the change
[ James Hunt <email address hidden> ]
* usr/lib/
(requires bash) (LP: #705037).
* usr/lib/
ulevel data (required bash).
* usr/lib/
some 'level' using various unicode characters (requires bash)
(LP: #705032).
* usr/lib/
contents of wastebasket.
* usr/lib/
Hi Dustin - lots of updates to the unicode notifications. You can now pass floating point values. I've got some test scripts that could be added at a later stage maybe?
Cheers,
James.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'debian/changelog' |
2 | --- debian/changelog 2011-02-01 19:24:03 +0000 |
3 | +++ debian/changelog 2011-02-03 23:10:35 +0000 |
4 | @@ -1,9 +1,22 @@ |
5 | byobu (3.28) unreleased; urgency=low |
6 | |
7 | + [ Dustin Kirkland ] |
8 | * usr/lib/byobu/wifi_quality: don't show wifi-quality if connectivity == 0 |
9 | * usr/lib/byobu/disk_io: don't show disk_io if rate = 0 |
10 | * usr/lib/byobu/services: finally fix that nagging, mysterious whitespace |
11 | |
12 | + [ James Hunt <james.hunt@ubuntu.com> ] |
13 | + * usr/lib/byobu/uclock: New UTF-8 notification showing time in binary |
14 | + (requires bash) (LP: #705037). |
15 | + * usr/lib/byobu/ugraph: New UTF-8 notification utility showing historical |
16 | + ulevel data (required bash). |
17 | + * usr/lib/byobu/ulevel: New UTF-8 notification utility which displays |
18 | + some 'level' using various unicode characters (requires bash) |
19 | + (LP: #705032). |
20 | + * usr/lib/byobu/wastebasket: New ASCII+UTF-8 notification indicating |
21 | + contents of wastebasket. |
22 | + * usr/lib/byobu/wifi_quality: added UTF-8 icon. |
23 | + |
24 | -- Dustin Kirkland <kirkland@ubuntu.com> Fri, 28 Jan 2011 17:12:27 -0600 |
25 | |
26 | byobu (3.27-0ubuntu1) natty; urgency=low |
27 | |
28 | === modified file 'usr/lib/byobu/Makefile.am' |
29 | --- usr/lib/byobu/Makefile.am 2010-11-19 02:43:19 +0000 |
30 | +++ usr/lib/byobu/Makefile.am 2011-02-03 23:10:35 +0000 |
31 | @@ -1,3 +1,3 @@ |
32 | libdirdir = $(prefix)/lib/@PACKAGE@ |
33 | -libdir_SCRIPTS = apport arch battery cpu_count cpu_freq cpu_temp custom date disk disk_io ec2_cost fan_speed hostname ip_address load_average logo mail mem_available mem_used menu network .notify_osd notify_osd processes raid rcs_cost reboot_required release services swap time time_utc updates_available uptime users whoami wifi_quality |
34 | +libdir_SCRIPTS = apport arch battery cpu_count cpu_freq cpu_temp custom date disk disk_io ec2_cost fan_speed hostname ip_address load_average logo mail mem_available mem_used menu network .notify_osd notify_osd processes raid rcs_cost reboot_required release services swap time time_utc uclock ugraph ulevel updates_available uptime users wastebasket whoami wifi_quality |
35 | |
36 | |
37 | === added file 'usr/lib/byobu/uclock' |
38 | --- usr/lib/byobu/uclock 1970-01-01 00:00:00 +0000 |
39 | +++ usr/lib/byobu/uclock 2011-02-03 23:10:35 +0000 |
40 | @@ -0,0 +1,173 @@ |
41 | +#!/bin/bash -e |
42 | +#--------------------------------------------------------------------- |
43 | +# Script to display a "binary clock" using unicode characters from the |
44 | +# braille block. |
45 | +# |
46 | +# Designed to work with the wonderful byoby(1) but can be run |
47 | +# stand-alone. |
48 | +#--------------------------------------------------------------------- |
49 | +# |
50 | +# Copyright (C) 2011 Canonical Ltd. |
51 | +# |
52 | +# Author: James Hunt <james.hunt@canonical.com> |
53 | +# |
54 | +# This program is free software: you can redistribute it and/or modify |
55 | +# it under the terms of the GNU General Public License as published by |
56 | +# the Free Software Foundation, version 3 of the License. |
57 | +# |
58 | +# This program is distributed in the hope that it will be useful, |
59 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
60 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
61 | +# GNU General Public License for more details. |
62 | +# |
63 | +# You should have received a copy of the GNU General Public License |
64 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
65 | +# |
66 | +#--------------------------------------------------------------------- |
67 | + |
68 | +script_name=${0##*/} |
69 | + |
70 | +# Selected Unicode Braille characters: |
71 | +# |
72 | +# 0x2800, 0x2880, 0x2820, 0x28a0, 0x2810, 0x2890, 0x2830, 0x28b0, 0x2808, 0x2888, |
73 | +# 0x2840, 0x28c0, 0x2860, 0x28e0, 0x2850, 0x28d0, 0x2870, 0x28f0, 0x2848, 0x28c8, |
74 | +# 0x2804, 0x2884, 0x2824, 0x28a4, 0x2814, 0x2894, 0x2834, 0x28b4, 0x280c, 0x288c, |
75 | +# 0x2844, 0x28c4, 0x2864, 0x28e4, 0x2854, 0x28d4, 0x287b, 0x28f4, 0x284c, 0x28cc, |
76 | +# 0x2802, 0x2882, 0x2822, 0x28a2, 0x2812, 0x2892, 0x2832, 0x28b2, 0x280a, 0x288a, |
77 | +# 0x2842, 0x28c2, 0x2862, 0x28e2, 0x2852, 0x28d2, 0x2872, 0x28f2, 0x284a, 0x28ca, |
78 | +# 0x2806, 0x2886 |
79 | +# |
80 | +# Index of this array is 0-61 with character returned being |
81 | +# "two column" binary representation of a time segment. |
82 | +# |
83 | +binary=(⠀ ⢀ ⠠ ⢠ ⠐ ⢐ ⠰ ⢰ ⠈ ⢈ \ |
84 | + ⡀ ⣀ ⡠ ⣠ ⡐ ⣐ ⡰ ⣰ ⡈ ⣈ \ |
85 | + ⠄ ⢄ ⠤ ⢤ ⠔ ⢔ ⠴ ⢴ ⠌ ⢌ \ |
86 | + ⡄ ⣄ ⡤ ⣤ ⡔ ⣔ ⡻ ⣴ ⡌ ⣌ \ |
87 | + ⠂ ⢂ ⠢ ⢢ ⠒ ⢒ ⠲ ⢲ ⠊ ⢊ \ |
88 | + ⡂ ⣂ ⡢ ⣢ ⡒ ⣒ ⡲ ⣲ ⡊ ⣊ ⠆ ⢆) |
89 | + |
90 | +usage() |
91 | +{ |
92 | +cat <<EOT |
93 | +Description: A clock that displays the time in binary. |
94 | + |
95 | +Usage: $script_name [options] |
96 | + |
97 | + |
98 | +Options: |
99 | + |
100 | + -b : Display binary clock (default) |
101 | + -h : Show this help. |
102 | + -l : Display leading zeros (hex and octal modes only). |
103 | + -m : Show time in 24-hour military format |
104 | + (default: 12-hour format). |
105 | + -n : Suppress newline at end of time. |
106 | + -o : Display time in octal (base 8). |
107 | + -s <sep> : Specify separator between hours and minutes |
108 | + (and seconds if not disabled). |
109 | + -u : Display alphabetics in upper-case (hex mode only). |
110 | + -x : Disable time in hexadecimal (base 16). |
111 | + -z : Disable display of seconds. |
112 | + |
113 | +EOT |
114 | +} |
115 | + |
116 | +suppress_seconds=n |
117 | +clock_type=binary |
118 | +format=std |
119 | +ending="\n" |
120 | +uppercase=n |
121 | +leading_zeros=n |
122 | + |
123 | +while getopts "bhlmnos:uxz" opt |
124 | +do |
125 | + case "$opt" in |
126 | + b) |
127 | + clock_type=binary |
128 | + ;; |
129 | + |
130 | + h) |
131 | + usage |
132 | + exit 0 |
133 | + ;; |
134 | + |
135 | + l) |
136 | + leading_zeros=y |
137 | + ;; |
138 | + |
139 | + m) |
140 | + format=mil |
141 | + ;; |
142 | + |
143 | + n) |
144 | + ending= |
145 | + ;; |
146 | + |
147 | + o) |
148 | + clock_type=oct |
149 | + ;; |
150 | + |
151 | + s) |
152 | + sep=$OPTARG |
153 | + ;; |
154 | + |
155 | + u) |
156 | + uppercase=y |
157 | + ;; |
158 | + |
159 | + x) |
160 | + clock_type=hex |
161 | + ;; |
162 | + |
163 | + z) |
164 | + suppress_seconds=y |
165 | + ;; |
166 | + esac |
167 | +done |
168 | + |
169 | +if [ -z "$clock_type" ] |
170 | +then |
171 | + echo "ERROR: must specify clock type" |
172 | + exit 1 |
173 | +fi |
174 | + |
175 | +shift $[$OPTIND-1] |
176 | + |
177 | +# get current time, handling 12-hour or 24-hour |
178 | +if [ $format = std ] |
179 | +then |
180 | + hrs_format=%l |
181 | +else |
182 | + hrs_format=%k |
183 | +fi |
184 | + |
185 | +time=($(date "+${hrs_format} %M %S")) |
186 | +h=$(printf ${time[0]}) |
187 | +m=$(printf ${time[1]}) |
188 | +s=$(printf ${time[2]}) |
189 | + |
190 | +if [ $clock_type = binary ] |
191 | +then |
192 | + [ $suppress_seconds = n ] && seconds="${sep}${binary[10#$s]}" |
193 | + display_time="${binary[10#$h]}${sep}${binary[10#$m]}${seconds}${ending}" |
194 | +else |
195 | + if [ $clock_type = hex ] |
196 | + then |
197 | + conversion=x |
198 | + [ $uppercase = y ] && conversion=X |
199 | + else |
200 | + conversion=o |
201 | + fi |
202 | + precision= |
203 | + [ $leading_zeros = y ] && precision=.2 |
204 | + base_format=%2${precision}${conversion} |
205 | + |
206 | + hh=$(printf "$base_format" $h) |
207 | + hm=$(printf "$base_format" $m) |
208 | + [ "$suppress_seconds" = n ] && hs="${sep}$(printf "$base_format" $s)" |
209 | + display_time="${hh}${sep}${hm}${hs}${ending}" |
210 | +fi |
211 | + |
212 | +echo -ne "$display_time" |
213 | +exit 0 |
214 | |
215 | === added file 'usr/lib/byobu/ugraph' |
216 | --- usr/lib/byobu/ugraph 1970-01-01 00:00:00 +0000 |
217 | +++ usr/lib/byobu/ugraph 2011-02-03 23:10:35 +0000 |
218 | @@ -0,0 +1,212 @@ |
219 | +#!/bin/bash |
220 | +#--------------------------------------------------------------------- |
221 | +# Script to display a byobo notification "history graph". |
222 | +# |
223 | +# Designed to work with the wonderful byoby(1) but can be run |
224 | +# stand-alone. |
225 | +#--------------------------------------------------------------------- |
226 | +# |
227 | +# Copyright (C) 2011 Canonical Ltd. |
228 | +# |
229 | +# Author: James Hunt <james.hunt@canonical.com> |
230 | +# |
231 | +# This program is free software: you can redistribute it and/or modify |
232 | +# it under the terms of the GNU General Public License as published by |
233 | +# the Free Software Foundation, version 3 of the License. |
234 | +# |
235 | +# This program is distributed in the hope that it will be useful, |
236 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
237 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
238 | +# GNU General Public License for more details. |
239 | +# |
240 | +# You should have received a copy of the GNU General Public License |
241 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
242 | +# |
243 | +#--------------------------------------------------------------------- |
244 | + |
245 | +script_name=${0##*/} |
246 | +min_default=0 |
247 | +max_default=100 |
248 | +points_default=5 |
249 | +theme_default=vbars_8 |
250 | +newline="\n" |
251 | +rotate=y |
252 | + |
253 | +error() |
254 | +{ |
255 | + msg="$*" |
256 | + echo "ERROR: $msg" >&2 |
257 | +} |
258 | + |
259 | +die() |
260 | +{ |
261 | + error "$*" |
262 | + exit 1 |
263 | +} |
264 | + |
265 | +usage() |
266 | +{ |
267 | +cat <<EOT |
268 | +Description: Display a graph of historical indicator values using |
269 | + ulevel. |
270 | + |
271 | +Usage: $script_name [options] [command [args...]] |
272 | + |
273 | +Options: |
274 | + |
275 | + -f <file> : File to read data points from. |
276 | + (only required if no command specified). |
277 | + -h : Show this help. |
278 | + -m <num> : Minimum value (default=$min_default). |
279 | + -n : Supress output of newline character. |
280 | + -p <points> : Specify number of data points in graph |
281 | + (default=$points_default). |
282 | + -r : Do not rotate file <file> (default is to rotate). |
283 | + Option implies file <file> should not be written to |
284 | + so a command cannot follow script options in this case. |
285 | + -t <theme> : 'ulevel' theme to use (default=$theme_default). |
286 | + -x <num> : Maximum value (default=$max_default). |
287 | + |
288 | + |
289 | +Examples: |
290 | + |
291 | + Using $script_name to run a command, rotate log and display graph. |
292 | + |
293 | + Here we specify a command to display available memory. |
294 | + Trailing echo adds a required newline |
295 | + Note no filename specified. |
296 | + |
297 | + $script_name "(/usr/lib/byobu/mem_used |sed 's/% //g';echo)" |
298 | + |
299 | + |
300 | + Using $script_name just to rotate log and display the graph |
301 | + |
302 | + file=/tmp/load.dat |
303 | + awk '{ print \$1}' /proc/loadavg >> \$file |
304 | + $script_name -f \$file |
305 | + |
306 | +Notes: |
307 | + |
308 | + - If you specify 'command', care must be taken with shell quoting to |
309 | + avoid expansion prior to this script running the command. |
310 | + - If '-r' is not specified, the file <file> will be rotated such that |
311 | + at most <points> lines are retained on each invocation of this |
312 | + script. |
313 | + |
314 | +EOT |
315 | +} |
316 | + |
317 | +get_data() |
318 | +{ |
319 | + needed_lines=$points |
320 | + |
321 | + if [ ! -f $file ] |
322 | + then |
323 | + return |
324 | + fi |
325 | + |
326 | + lines=$(wc -l $file|awk '{print $1}') |
327 | + |
328 | + if [ $lines -lt $needed_lines ] |
329 | + then |
330 | + # insufficient data |
331 | + return |
332 | + fi |
333 | + |
334 | + bytes=$(<${file}) |
335 | + bytes=$(echo "$bytes"|tail -n ${needed_lines}) |
336 | + [ $lines -eq $needed_lines -o $rotate = n ] && echo "$bytes" && return |
337 | + |
338 | + # rotate |
339 | + tmp=`tempfile` |
340 | + echo "$bytes" > $tmp |
341 | + mv $tmp $file |
342 | + |
343 | + echo "$bytes" |
344 | +} |
345 | + |
346 | +while getopts "f:hm:np:rt:x:" opt |
347 | +do |
348 | + case "$opt" in |
349 | + f) |
350 | + file="$OPTARG" |
351 | + ;; |
352 | + |
353 | + h) |
354 | + usage |
355 | + exit 0 |
356 | + ;; |
357 | + |
358 | + m) |
359 | + min=$OPTARG |
360 | + ;; |
361 | + |
362 | + n) |
363 | + newline= |
364 | + ;; |
365 | + |
366 | + p) |
367 | + points=$OPTARG |
368 | + ;; |
369 | + |
370 | + r) |
371 | + rotate=n |
372 | + ;; |
373 | + |
374 | + t) |
375 | + theme="$OPTARG" |
376 | + ;; |
377 | + |
378 | + x) |
379 | + max=$OPTARG |
380 | + ;; |
381 | + esac |
382 | +done |
383 | + |
384 | +shift $[$OPTIND-1] |
385 | + |
386 | +cmd="$@" |
387 | + |
388 | +[ -z "$theme" ] && theme=$theme_default |
389 | + |
390 | +if [ -z "$cmd" ] |
391 | +then |
392 | + if [ -z "$file" ] |
393 | + then |
394 | + error "must specify file" |
395 | + usage |
396 | + exit 1 |
397 | + fi |
398 | +fi |
399 | + |
400 | +if [ -z "$file" ] |
401 | +then |
402 | + # we could go cryptic+safe by calling tempfile(1), but that then |
403 | + # makes it very difficult to find in case of need. |
404 | + file=/tmp/${USER}-${script_name}-$$.dat |
405 | +fi |
406 | + |
407 | +[ -z "$min" ] && min=$min_default |
408 | +[ -z "$max" ] && max=$max_default |
409 | +[ -z "$points" ] && points=$points_default |
410 | + |
411 | +if [ ! -z "$cmd" ] |
412 | +then |
413 | + if [ $rotate = n ] |
414 | + then |
415 | + error "cannot write to file if rotate disabled" |
416 | + usage |
417 | + exit 1 |
418 | + fi |
419 | + |
420 | + eval "$cmd >>$file" |
421 | +fi |
422 | + |
423 | +data=$(get_data) |
424 | + |
425 | +[ -z "$data" ] && printf "%*.s${newline}" $points && exit 0 |
426 | + |
427 | +for datum in $data |
428 | +do |
429 | + ulevel.sh -n -m $min -x $max -c $datum -t $theme |
430 | +done |
431 | |
432 | === added file 'usr/lib/byobu/ulevel' |
433 | --- usr/lib/byobu/ulevel 1970-01-01 00:00:00 +0000 |
434 | +++ usr/lib/byobu/ulevel 2011-02-03 23:10:35 +0000 |
435 | @@ -0,0 +1,481 @@ |
436 | +#!/bin/bash |
437 | +#--------------------------------------------------------------------- |
438 | +# Script to display unicode characters representing the level of |
439 | +# some indicator. |
440 | +# |
441 | +# Designed to work with the wonderful byoby(1) but can be run |
442 | +# stand-alone. |
443 | +#--------------------------------------------------------------------- |
444 | +# |
445 | +# Copyright (C) 2011 Canonical Ltd. |
446 | +# |
447 | +# Author: James Hunt <james.hunt@canonical.com> |
448 | +# |
449 | +# This program is free software: you can redistribute it and/or modify |
450 | +# it under the terms of the GNU General Public License as published by |
451 | +# the Free Software Foundation, version 3 of the License. |
452 | +# |
453 | +# This program is distributed in the hope that it will be useful, |
454 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
455 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
456 | +# GNU General Public License for more details. |
457 | +# |
458 | +# You should have received a copy of the GNU General Public License |
459 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
460 | +# |
461 | +#--------------------------------------------------------------------- |
462 | + |
463 | +#------------------------------ |
464 | +# Themes with 2 values. |
465 | +# |
466 | +# Two-value themes are handled differently to other n-value types of |
467 | +# theme: the first array entry in each theme is generally some unfilled |
468 | +# glyph, denoting an "off" value and the second value is the filled |
469 | +# version of the unfilled glyph and denotes an "on" value. Note that |
470 | +# you can always change the ordering of these values using the 'invert' |
471 | +# command-line option. |
472 | + |
473 | +circles_2=(○ ●) |
474 | +diamonds_2=(◇ ◆) |
475 | +flags_2=(⚐ ⚑) |
476 | +hearts_2=(♡ ♥) |
477 | +squares_2=(◻ ◼) |
478 | +squares_small_2=(◽ ◾) |
479 | +stars_2=(☆ ★) |
480 | + |
481 | +#------------------------------ |
482 | +# Themes with 4 values. |
483 | + |
484 | +vdots_thick_4=(⣀ ⣤ ⣶ ⣿) |
485 | +vdots_thin_4=(⢀ ⢠ ⢰ ⢸) |
486 | +fractions_4=(¼ ½ ¾ ¹) |
487 | +quadrants_4=(◔ ◑ ◕ ●) |
488 | +shades_4=(░ ▒ ▓ █) |
489 | + |
490 | +#------------------------------ |
491 | +# Themes with 5 values. |
492 | + |
493 | +circles_5=(◦ ○ ◎ ◉ ●) |
494 | + |
495 | +#------------------------------ |
496 | +# Themes with 6 values. |
497 | + |
498 | +dice_6=(⚀ ⚁ ⚂ ⚃ ⚄ ⚅) |
499 | + |
500 | +#------------------------------ |
501 | +# Themes with 8 values. |
502 | + |
503 | +hbars_8=(▏ ▎ ▍ ▌ ▋ ▊ ▉ █) |
504 | +vbars_8=(▁ ▂ ▃ ▄ ▅ ▆ ▇ █) |
505 | + |
506 | +#------------------------------ |
507 | +# Themes with 10 values. |
508 | + |
509 | +circle_number_10=(➀ ➁ ➂ ➃ ➄ ➅ ➆ ➇ ➈ ➉) |
510 | +solid_numbers_a_10=(➊ ➋ ➌ ➍ ➎ ➏ ➐ ➑ ➒ ➓) |
511 | +solid_numbers_b_10=(❶ ❷ ❸ ❹ ❺ ❻ ❼ ❽ ❾ ❿) |
512 | + |
513 | +#------------------------------ |
514 | +# XXX: remember to update if you add new themes above! |
515 | + |
516 | +theme_list=\ |
517 | +( |
518 | + 'circles_2 diamonds_2 flags_2 hearts_2 squares_2 squares_small_2 stars_2' |
519 | + 'vdots_thick_4 vdots_thin_4 fractions_4 quadrants_4 shades_4' |
520 | + 'circles_5' |
521 | + 'dice_6' |
522 | + 'hbars_8 vbars_8' |
523 | + 'circle_number_10 solid_numbers_a_10 solid_numbers_b_10' |
524 | +) |
525 | + |
526 | +#------------------------------ |
527 | + |
528 | +debug_enabled=n |
529 | +newline= |
530 | +list=n |
531 | +quiet=n |
532 | +invert=n |
533 | +reverse=n |
534 | +script_name=${0##*/} |
535 | +min_default=0 |
536 | +max_default=100 |
537 | +width_default=5 |
538 | +zero_as_space=n |
539 | +theme_default=vbars_8 |
540 | + |
541 | +debug() |
542 | +{ |
543 | + msg="$*" |
544 | + [ $debug_enabled = y ] && echo "DEBUG: $msg" |
545 | +} |
546 | + |
547 | +error() |
548 | +{ |
549 | + msg="$*" |
550 | + echo "ERROR: $msg" >&2 |
551 | +} |
552 | + |
553 | +die() |
554 | +{ |
555 | + error "$*" |
556 | + exit 1 |
557 | +} |
558 | + |
559 | +bc_test() |
560 | +{ |
561 | + expr="$*" |
562 | + echo $(echo "if ( $expr ) { print \"1\" }"|bc -l) |
563 | +} |
564 | + |
565 | +assert() |
566 | +{ |
567 | + expr="$1" |
568 | + str="$2" |
569 | + |
570 | + debug "assert: expr='$expr'" |
571 | + ret=$(bc_test "$expr") |
572 | + |
573 | + [ ! -z "$ret" ] && return |
574 | + |
575 | + die "$str" |
576 | +} |
577 | + |
578 | +usage() |
579 | +{ |
580 | +cat <<EOT |
581 | +Description: Display unicode characters representing the relative |
582 | + level of some indicator value within a range. |
583 | + |
584 | +Usage: $script_name [options] -c <current_num> |
585 | + $script_name [options] <current_num> |
586 | + $script_name <current_num> |
587 | + |
588 | +Options: |
589 | + |
590 | + -b : Display current value as space if zero, rather than lowest |
591 | + 'value' of theme. |
592 | + -c <num> : Current value of your indicator. |
593 | + -d : Enable debug output. |
594 | + -h : Show this help. |
595 | + -i : Invert colour scheme (rating themes only). |
596 | + -l : List available themes. If '-t' also specified, |
597 | + show all values for specified theme. |
598 | + -m <num> : Minimum value (default=$min_default). |
599 | + -n : Supress output of newline character. |
600 | + -q : Suppress messages (requires '-t'). |
601 | + -r : Reverse 'direction' of display (rating theme only). |
602 | + -t <theme> : Name of theme (default=$theme_default). |
603 | + -u <chars> : Specify a user theme (2 or more values). |
604 | + -w <int> : Width of rating theme (default=$width_default). |
605 | + -x <num> : Maximum value (default=$max_default). |
606 | + |
607 | + |
608 | +Examples: |
609 | + |
610 | + # Display character representing 27% using default theme. |
611 | + $script_name 27 |
612 | + |
613 | + # As above. |
614 | + $script_name -c 27 |
615 | + |
616 | + # Example showing floating-point and negative values. |
617 | + $script_name -c 1.100001 -m -5.00234 -x 2.71828 -t dice_6 |
618 | + |
619 | + # Display value using a "rating theme" (displayed left-to-right). |
620 | + $script_name -c 83 -t stars_2 |
621 | + |
622 | + # Display right-to-left inverted "rating theme". |
623 | + $script_name -c 60 -t diamonds_2 -ri |
624 | + |
625 | + # Display all glyphs in 'solid_numbers_a_10' theme. |
626 | + $script_name -l -t solid_numbers_a_10 |
627 | + |
628 | + # Display a user-specified rating theme 10 glyphs wide. |
629 | + $script_name -c 666.321 -m -273.15 -x 1370 -u "· ☢" -w 10 |
630 | + |
631 | + # A multi-element user theme (this prints 'e'). |
632 | + $script_name -c 50 -u "a b c d e f g h i j" |
633 | + |
634 | + |
635 | +Notes: |
636 | + |
637 | + - Arguments of type "<int>" denote an integer value, whereas arguments |
638 | + of type "<num>" denotes either an integer or a floating-point |
639 | + number. |
640 | + - The final '_<number>' in a theme name denotes the number of glyphs |
641 | + in it. |
642 | + - "Rating themes" are those with only 2 values. |
643 | + - The <chars> argument to '-u' must contain space-delimited |
644 | + characters. |
645 | + |
646 | +EOT |
647 | +} |
648 | + |
649 | +# this is horribly inefficient - we should probably do some clever |
650 | +# tricks using printf formats to avoid the silly while loop. |
651 | +# Additionally, it is rather similar to show_theme_entry() but was split |
652 | +# out from that in a vain attempt to make the overall logic clearer :) |
653 | +show_rating_theme() |
654 | +{ |
655 | + theme="$1" |
656 | + min="$2" |
657 | + max="$3" |
658 | + current="$4" |
659 | + quotient="$5" |
660 | + |
661 | + if [ $invert = n ] |
662 | + then |
663 | + on=1 |
664 | + off=0 |
665 | + else |
666 | + on=0 |
667 | + off=1 |
668 | + fi |
669 | + |
670 | + percent=$(echo "$quotient * 100"|bc -l) |
671 | + debug "width=$width" |
672 | + debug "percent=$percent" |
673 | + |
674 | + percent_per_glyph=$(echo "scale=4;100/${width}"|bc -l) |
675 | + assert "$percent_per_glyph > 1.0" "width ($width) too great" |
676 | + debug "percent_per_glyph=$percent_per_glyph" |
677 | + |
678 | + debug "glyph_count=$glyph_count" |
679 | + |
680 | + g=$percent_per_glyph |
681 | + i=0 |
682 | + value="" |
683 | + while [ $i -lt $width ] |
684 | + do |
685 | + if [ ! -z "$(bc_test "$g <= $percent")" ] |
686 | + then |
687 | + eval content="\${$theme[${on}]}" |
688 | + else |
689 | + eval content="\${$theme[${off}]}" |
690 | + fi |
691 | + if [ $reverse = n ] |
692 | + then |
693 | + value="${value}${content}" |
694 | + else |
695 | + value="${content}${value}" |
696 | + fi |
697 | + g=$(echo "$g + $percent_per_glyph"|bc -l) |
698 | + i=$((i + 1)) |
699 | + done |
700 | + echo $newline "$value" |
701 | +} |
702 | + |
703 | +show_theme_entry() |
704 | +{ |
705 | + theme="$1" |
706 | + min="$2" |
707 | + max="$3" |
708 | + current="$4" |
709 | + |
710 | + debug "theme=$theme" |
711 | + debug "min=$min" |
712 | + debug "max=$max" |
713 | + debug "current=$current" |
714 | + |
715 | + range=$(echo "($max - $min)"|bc -l) |
716 | + |
717 | + quotient=$(echo "scale=4;((${current} - ${min})/${range})"|bc -l) |
718 | + |
719 | + glyph_count=$(echo $theme|awk -F\_ '{print $NF}') |
720 | + |
721 | + debug "range=$range" |
722 | + debug "quotient=$quotient" |
723 | + debug "glyph_count=$glyph_count" |
724 | + |
725 | + if [ $glyph_count -eq 2 ] |
726 | + then |
727 | + show_rating_theme "$theme" "$min" "$max" "$current" "$quotient" |
728 | + return |
729 | + fi |
730 | + |
731 | + percent_per_glyph=$(echo "100/$glyph_count"|bc -l) |
732 | + debug "percent_per_glyph=$percent_per_glyph" |
733 | + |
734 | + assert "$percent_per_glyph > 1.0" "width ($width) too great" |
735 | + |
736 | + # with this scheme, assuming current value is 0-100 and theme has 10 |
737 | + # elements: |
738 | + # |
739 | + # current glyph from theme |
740 | + # |
741 | + # 0-19 1st |
742 | + # 20-29 2nd |
743 | + # 30-39 3rd |
744 | + # : |
745 | + # 90-99 9th |
746 | + # 100 10th |
747 | + i=$(echo|awk \ |
748 | + -v quotient=$quotient \ |
749 | + -v glyph_count=$glyph_count \ |
750 | + '{ |
751 | + x= int( (quotient * glyph_count) ) - 1; |
752 | + x = (x > (glyph_count-1) ? (glyph_count-1) : x); |
753 | + if ( x < 0 ) x = 0; |
754 | + printf("%d", x); |
755 | + }') |
756 | + |
757 | + debug "index=$i" |
758 | + eval content="\${$theme[$i]}" |
759 | + |
760 | + [ ! -z "$(bc_test "$current == 0")" -a $zero_as_space = y ] && content=' ' |
761 | + echo $newline "$content" |
762 | + |
763 | + return |
764 | +} |
765 | + |
766 | +list_theme() |
767 | +{ |
768 | + theme="$1" |
769 | + eval content="\${$theme[@]}" |
770 | + echo |
771 | + for c in $content |
772 | + do |
773 | + echo -n "$c " |
774 | + done |
775 | + echo -e "\n" |
776 | +} |
777 | + |
778 | +list_themes() |
779 | +{ |
780 | + for entry in ${theme_list[@]} |
781 | + do |
782 | + for arg in "$entry" |
783 | + do |
784 | + echo "$arg" |
785 | + done |
786 | + done |
787 | +} |
788 | + |
789 | +theme_valid() |
790 | +{ |
791 | + theme="$1" |
792 | + [ -z "`list_themes|grep "^${theme}$"`" ] && return 1 |
793 | + return 0 |
794 | +} |
795 | + |
796 | +# XXX: the seemingly pointless 'tr' calls translate unicode dashes (look |
797 | +# closely!) into ASCII dashes. This is required since 'bc' borks on |
798 | +# unicode and it is easy to mistakenly pass unicode dashes if you paste |
799 | +# characters from another application, such as a web-browser. |
800 | +while getopts "bc:dhilm:nqrt:u:w:x:" opt |
801 | +do |
802 | + case "$opt" in |
803 | + b) |
804 | + zero_as_space=y |
805 | + ;; |
806 | + |
807 | + c) |
808 | + current=$(echo $OPTARG|tr '−' '-') |
809 | + ;; |
810 | + |
811 | + d) |
812 | + debug_enabled=y |
813 | + ;; |
814 | + |
815 | + h) |
816 | + usage |
817 | + exit 0 |
818 | + ;; |
819 | + |
820 | + i) |
821 | + invert=y |
822 | + ;; |
823 | + |
824 | + l) |
825 | + list=y |
826 | + ;; |
827 | + |
828 | + m) |
829 | + min=$(echo $OPTARG|tr '−' '-') |
830 | + ;; |
831 | + |
832 | + n) |
833 | + newline=-n |
834 | + ;; |
835 | + |
836 | + q) |
837 | + quiet=y |
838 | + ;; |
839 | + |
840 | + r) |
841 | + reverse=y |
842 | + ;; |
843 | + |
844 | + t) |
845 | + theme=$OPTARG |
846 | + ;; |
847 | + |
848 | + u) |
849 | + user_theme="$OPTARG" |
850 | + ;; |
851 | + |
852 | + w) |
853 | + width=$OPTARG |
854 | + ;; |
855 | + |
856 | + x) |
857 | + max=$(echo $OPTARG|tr '−' '-') |
858 | + ;; |
859 | + esac |
860 | +done |
861 | + |
862 | +shift $[$OPTIND-1] |
863 | + |
864 | +if [ ! -z "$user_theme" ] |
865 | +then |
866 | + elements=$(echo "$user_theme"|awk '{print NF}') |
867 | + |
868 | + assert "$elements >= 2" "user themes need >= 2 values" |
869 | + |
870 | + # create new theme |
871 | + name="_user_${elements}" |
872 | + eval "$name=($user_theme)" |
873 | + |
874 | + # add it to list |
875 | + theme_list=("${theme_list[@]}" $name) |
876 | + |
877 | + [ -z "$theme" ] && theme=$name |
878 | +fi |
879 | + |
880 | +if [ "$list" = y ] |
881 | +then |
882 | + if [ -z "$theme" ] |
883 | + then |
884 | + list_themes && exit 0 |
885 | + else |
886 | + theme_valid "$theme" || die "invalid theme: $theme" |
887 | + [ "$quiet" = n ] && echo "Listing theme '$theme'" |
888 | + list_theme $theme && exit 0 |
889 | + fi |
890 | +fi |
891 | +[ -z "$min" ] && min=$min_default |
892 | +[ -z "$max" ] && max=$max_default |
893 | +[ -z "$width" ] && width=$width_default |
894 | + |
895 | +assert "$min <= $max" "minimum ($min) > maximum ($max)" |
896 | +assert "$min != $max" "minimum ($min) == maximum" |
897 | + |
898 | +[ -z "$current" -a ! -z "$1" ] && current="$1" |
899 | + |
900 | +if [ -z "$current" ] |
901 | +then |
902 | + error "must specify current value" |
903 | + usage |
904 | + exit 1 |
905 | +fi |
906 | + |
907 | +assert "$current >= $min" "current ($current) < minimum ($min)" |
908 | +assert "$current <= $max" "current ($current) > maximum ($max)" |
909 | + |
910 | +[ -z "$theme" ] && theme=$theme_default |
911 | + |
912 | +theme_valid "$theme" || die "invalid theme: $theme" |
913 | + |
914 | +show_theme_entry $theme $min $max $current |
915 | + |
916 | +exit 0 |
917 | |
918 | === added file 'usr/lib/byobu/wastebasket' |
919 | --- usr/lib/byobu/wastebasket 1970-01-01 00:00:00 +0000 |
920 | +++ usr/lib/byobu/wastebasket 2011-02-03 23:10:35 +0000 |
921 | @@ -0,0 +1,39 @@ |
922 | +#!/bin/sh -e |
923 | +# |
924 | +# wastebasket: show icon (and optionally count) if entries in wastebasket. |
925 | +# Copyright (C) 2011 Canonical Ltd. |
926 | +# |
927 | +# Authors: James Hunt <james.hunt@canonical.com> |
928 | + |
929 | +# This program is free software: you can redistribute it and/or modify |
930 | +# it under the terms of the GNU General Public License as published by |
931 | +# the Free Software Foundation, version 3 of the License. |
932 | +# |
933 | +# This program is distributed in the hope that it will be useful, |
934 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
935 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
936 | +# GNU General Public License for more details. |
937 | +# |
938 | +# You should have received a copy of the GNU General Public License |
939 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
940 | +# |
941 | + |
942 | +PKG="byobu" |
943 | +color 2>/dev/null || color() { true; } |
944 | + |
945 | +[ "$UTF8" = "1" ] && ICON="♸" || ICON="W" |
946 | + |
947 | +dir=$HOME/.local/share/Trash/files |
948 | + |
949 | +[ ! -d $dir ] && exit 0 |
950 | +count=$(ls $dir|wc -l) |
951 | +[ "$count" -eq 0 ] && exit 0 |
952 | + |
953 | +if [ "$1" = "--detail" ] |
954 | +then |
955 | + echo -n "${ICON}[$count]" |
956 | +else |
957 | + echo -n $ICON |
958 | +fi |
959 | + |
960 | +exit 0 |
961 | |
962 | === modified file 'usr/lib/byobu/wifi_quality' |
963 | --- usr/lib/byobu/wifi_quality 2011-01-31 23:19:40 +0000 |
964 | +++ usr/lib/byobu/wifi_quality 2011-02-03 23:10:35 +0000 |
965 | @@ -19,6 +19,7 @@ |
966 | |
967 | PKG="byobu" |
968 | color 2>/dev/null || color() { true; } |
969 | +[ "$UTF8" = "1" ] && ICON="⚚" || ICON= |
970 | |
971 | if [ "$1" = "--detail" ]; then |
972 | /sbin/iwconfig 2>/dev/null |
973 | @@ -35,4 +36,4 @@ |
974 | quality=`echo "$quality" | awk -F/ '{printf "%.0f", 100*$1/$2}'` |
975 | fi |
976 | [ "$quality" = "0" ] && exit 0 |
977 | -printf "$(color b C k)%s$(color -)$(color C k)%s,$(color -)$(color b C k)%s$(color -)$(color C k)%%$(color -) " "$bitrate" "Mbps" "$quality" |
978 | +printf "${ICON}$(color b C k)%s$(color -)$(color C k)%s,$(color -)$(color b C k)%s$(color -)$(color C k)%%$(color -) " "$bitrate" "Mbps" "$quality" |