Skip to content

Instantly share code, notes, and snippets.

@xyzshantaram
Last active August 30, 2020 01:15
Show Gist options
  • Save xyzshantaram/b377197b5fb8b675658978a465671376 to your computer and use it in GitHub Desktop.
Save xyzshantaram/b377197b5fb8b675658978a465671376 to your computer and use it in GitHub Desktop.
#!/bin/bash
FGCOLOR='f5f4f0'
BGCOLOR='555555'
BG_ALPHA='51'
max_len=50
Clock() {
#TIME=$(date "+%S seconds past %H%M")
TIME=$(date "+%H%M+%S")
echo -e -n "\uf017 ${TIME}"
}
Cal() {
DATE=$(date "+%a, %d %B %Y")
echo -e -n " ${DATE}"
}
ActiveWindow() {
len=$(echo -n "$(xdotool getwindowfocus getwindowname)" | wc -m)
name=$(xdotool getwindowfocus getwindowname)
if [ "$len" -gt "$max_len" ];then
echo -n "$(echo $name | cut -c 1-$max_len)..."
else
echo -n "$(xdotool getwindowfocus getwindowname)"
fi
}
Sound() {
echo -n $(volume)
}
CPUTemp() {
temp=$($(echo cat "/sys/class/thermal/$(ls /sys/class/thermal/ | grep thermal_zone | tail -1)/temp") | sed s/000//)
echo -e "\uf769 ${temp}C"
}
Buttons() {
echo -e "%{A:xdotool windowkill $(xdotool getactivewindow):}\uf00d%{A} "\
"%{F#$FGCOLOR}%{T3}%{A:xdotool windowminimize $(xdotool getwindowfocus getactivewindow):}\uf2d1%{A} "\
"%{T2}%{A:wmctrl -r \:ACTIVE\: -b toggle,maximized_vert,maximized_horz:}\uf2d0%{A}"
}
Battery() {
BATPERC="$(acpi --battery | cut -d, -f2)"
if [[ -z "$(acpi --battery | grep -i discharging)" ]]; then
# Charging.
echo "\uf5e7$BATPERC"
else
echo "\uf244$BATPERC"
fi
}
Network() {
if iwconfig wlan0 | grep -q 'Link Quality'; then
signal=$(iwconfig wlan0 | awk '/Link Quality/{print "scale=0;100*" substr($2,9,5)}' | bc)
echo "\uf1eb $signal% ";
else
if ping -q -c 1 -W 1 8.8.8.8 > /dev/null; then
echo "\uf6ff "
else
echo "\uf6ff \uf00d"
fi
fi
}
while true; do
constant="%{B#$BG_ALPHA$BGCOLOR}%{l}\
%{F#F92672}$(Buttons)\
%{T1}%{F#$FGCOLOR}%{B#$BG_ALPHA$BGCOLOR} $(ActiveWindow) %{c}$(Clock) %{r}$(Cal)\
|%{A:gnome-system-monitor:} $(CPUTemp) %{A}|\
%{A:volume mute:}%{A4:volume up:}%{A5:volume down:}$(Sound)%{A}%{A}%{A}"
if [[ "$mobile" == "1" ]]; then # mobile=1 because laptop mode, it displays WiFi and battery status.
final=$constant" | $(Battery) | $(Network)"
else
final=$constant;
fi
echo -ne $final' ';
sleep 0.4s;
toEcho="";
done
#!/bin/bash
if pidof lemonbar; then killall -9 lemon.sh; fi
sleep 1 && mobile=1 sh -c "./lemon.sh | lemonbar -g 1362x28+2+0 -f \"Source Code Pro:size=10\" -f \"Font Awesome 5 Free Regular\" -f \"Font Awesome 5 Free Solid\" -n \"openbox\" | /bin/sh > /dev/null" & disown;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment