forked from sayan01/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatbar
More file actions
executable file
·34 lines (34 loc) · 766 Bytes
/
Copy pathbatbar
File metadata and controls
executable file
·34 lines (34 loc) · 766 Bytes
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
#!/bin/bash
if [ ! -r /sys/class/power_supply/BAT0/capacity ]; then
echo "Can't Access Battery"
exit 1
fi
level=$(cat /sys/class/power_supply/BAT0/capacity)
usage () {
echo 'usage'
echo " $(basename "$0") [columns] [options]"
echo ' options:'
echo ' -h --help help'
echo ' -c --clean dont print dashes and [ ]'
}
lb="["; rb="]"; uf="-"
columns=$(($(tput cols) - 2))
for arg in "$@"; do
case $arg in
--help) ;&
-h) usage; exit ;;
--clean) ;&
-c) lb=" "; rb=" "; uf=" ";;
*[!0-9]*) echo "argument $arg is not a valid number";;
*) columns="$arg";;
esac
done
filled=$(( level * columns / 100 ))
echo -n "$lb"
for i in $(seq 1 "$columns"); do
if [[ $i -le filled ]]; then echo -n "#"
else echo -n "$uf"
fi
done
echo "$rb"
exit 0