Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2017 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2f4cf25f5098b30259e689372fffb871 to your computer and use it in GitHub Desktop.
Save anonymous/2f4cf25f5098b30259e689372fffb871 to your computer and use it in GitHub Desktop.
collection of scripts for taskbar using lemonbar-xft
#!/usr/bin/python
import cpu
import datetime
import time
import subprocess
import threading
import os
cpu_feed = cpu.CpuUsage()
def cpu_get():
while True:
cpu_feed.run()
with open("/home/sen/.scripts/lemonbar_fifo", "w") as fp:
final = "P" + cpu_feed.value + " \n"
fp.write(final)
time.sleep(1)
def clock_get():
with open("/home/sen/.scripts/lemonbar_fifo", "w") as fp:
now = datetime.datetime.now().strftime('%I:%M %p')
clock_value = "C " + now + "\n"
date = time.strftime('%x')
fp.write(clock_value)
fp.write("D " + date + "\n")
while True:
with open("/home/sen/.scripts/lemonbar_fifo", "w") as fp:
now = datetime.datetime.now().strftime('%I:%M %p')
clock_value = "C " + now + "\n"
fp.write(clock_value)
if now == "12:01 AM":
date = time.strftime('%x')
fp.write("D " + date + "\n")
time.sleep(10)
def bat_get():
counter = 0
while True:
with open("/home/sen/.scripts/lemonbar_fifo", "w") as fp:
with open("/sys/class/power_supply/BAT0/capacity", "r") as bat_cap:
with open("/sys/class/power_supply/BAT0/status", "r") as st:
state = st.read().strip()
cap = bat_cap.read().strip()
if int(cap) > 88:
output = " %{F-}" + cap + "%"
elif int(cap) > 65:
output = " %{F-}" + cap + "%"
elif int(cap) > 25:
output = " %{F-}" + cap + "%"
elif int(cap) > 10:
output = " %{F-}" + cap + "%"
else:
output = " %{F-}" + cap + "%"
if state == "Charging":
counters = [" ", " ", " ", " "]
output = counters[counter] + "%{F-}" + cap + "%"
if counter != 3:
counter += 1
elif counter == 3:
counter = 0
fp.write("B" + output + "\n")
if state == "Charging":
time.sleep(1)
else:
time.sleep(10)
def music_get():
while True:
with open("/home/sen/.scripts/lemonbar_fifo", "w") as fp:
hicolor = open("/home/sen/.cache/wal/colors.sh", "r") \
.readlines()[14].strip().split("\'")[1]
song_name = subprocess.check_output('mpc')\
.decode('UTF-8').strip().split('\n')[0]
song_state = subprocess.check_output('mpc_state')\
.decode('UTF-8').strip()
randomized = subprocess.check_output('mpc')\
.decode("UTF-8").split("\n")[-2].split(" ")[2].split()[-1]
if song_state == 'playing':
state_icon = "" # ||
else:
state_icon = "" # |>
if randomized == "on":
final_song_name = "%{F#9588ff}" + song_name + "%{F-}"
elif randomized == "off":
final_song_name = song_name
if os.path.exists("/home/sen/.mpvy"):
mpv_current = open("/home/sen/.mpvy", "r")
if os.path.exists("/home/sen/.mpv_playing"):
mpv_state_icon = \
"%{A1:echo cycle pause > /tmp/mpv-fifo && \
rm /home/sen/.mpv_playing && \
mpc random > /dev/null && \
mpc random > /dev/null:}  %{A}\n "
else:
mpv_state_icon = \
"%{A1:echo cycle pause > /tmp/mpv-fifo && \
touch /home/sen/.mpv_playing && \
mpc random > /dev/null && \
mpc random > /dev/null:}  %{A}\n "
music_string = mpv_current.read().strip() \
+ mpv_state_icon \
else:
music_string = "M%{T1}%{F" + hicolor + "}[mpc]%{F-} " \
+ "%{A1:mpc random:}" + final_song_name \
+ " %{F" + hicolor \
+ "}%{A}%{A1:mpc prev:}\ue054%{A}%{A1:mpc toggle:}" \
+ state_icon \
+ "%{A}%{A1:mpc next:}\ue05a%{A} \n"
fp.write(music_string)
subprocess.call(['mpc', 'idle'],
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
def network_get():
with open("/home/sen/.scripts/lemonbar_fifo", "w") as fp:
network = subprocess.check_output('addr').decode("UTF-8")
if not network.strip():
network = "%{F#bbaa00} %{F-}No Connection"
else:
network = " %{F-}" + network
fp.write("I" + network + "\n")
while True:
with open("/home/sen/.scripts/lemonbar_fifo", "w") as fp:
network = subprocess.check_output('addr').decode("UTF-8")
if not network.strip():
network = "%{F#bbaa00} %{F-}No Connection"
else:
network = " %{F-}" + network
fp.write("I" + network + "\n")
time.sleep(60)
def ram_get():
while True:
fp = open("/home/sen/.scripts/lemonbar_fifo", "w")
ram_percentage = subprocess.check_output('ram_use')\
.decode("UTF-8").strip()
fp.write("R" + ram_percentage + "\n")
time.sleep(10)
cpu_thread = threading.Thread(target=cpu_get)
bat_thread = threading.Thread(target=bat_get)
network_thread = threading.Thread(target=network_get)
clock_thread = threading.Thread(target=clock_get)
music_thread = threading.Thread(target=music_get)
ram_thread = threading.Thread(target=ram_get)
network_thread.start()
cpu_thread.start()
bat_thread.start()
clock_thread.start()
music_thread.start()
ram_thread.start()
#!/bin/bash
. $HOME/.cache/wal/colors.sh
. $HOME/.scripts/colors.sh
# Call lemonbar
while [[ $# -gt 1 ]]
do
key=$1
case $key in
-p|--postition)
POSITION=$2
shift
;;
-d|--docked)
DOCKED=$2
shift
;;
-h|--height)
height=$2
shift
;;
esac
shift
done
echo $height $POSITION $DOCKED
f_back="${background//\#}"
if [[ "$DOCKED" == "false" ]]; then
if [ -z "$height" ]; then
height=22
fi
resolution=$(expr $(xrandr | fgrep '*' | cut -d"x" -f1) - 24)
if [[ "$POSITION" == "top" ]]; then
# Floating, on top
cat <>$HOME/.scripts/lemonbar_fifo | $HOME/.scripts/fifo_reader.sh | lemonbar -pd \
-g "${resolution}x${height}+10+10" \
-B "#ff${f_back}" -F "$foreground" \
-f "FontAwesome:size=9" \
-o -2 -o -3 -o 0 -o 0 -o 0 \
-f "Terminus:style=Regular:pixelsize=12" \
-f "Terminess Powerline:style=Regular:size=8" \
-f "-xos4-terminusicons2mono-medium-r-normal--12-120-72-72-m-60-iso8859-1" \
-f "siji:style=Regular:pixelsize=13" \
-r 2 -R "$light_bg" -n BAR_2 -u 2 | bash &
i3-msg exec "lemonbar -n BAR_1 -p -g${resolution}x$(expr $height + 15)"
else
# Floating, bottom
cat <>$HOME/.scripts/lemonbar_fifo | $HOME/.scripts/fifo_reader.sh | lemonbar -pbd \
-g "${resolution}x${height}+10+10" \
-B "#ff${f_back}" -F "$foreground" \
-f "FontAwesome:size=9" \
-o -2 -o -3 -o 0 -o 0 -o 0 \
-f "Terminus:style=Regular:pixelsize=12" \
-f "Terminess Powerline:style=Regular:size=8" \
-f "-xos4-terminusicons2mono-medium-r-normal--12-120-72-72-m-60-iso8859-1" \
-f "siji:style=Regular:pixelsize=13" \
-r 2 -R "$light_bg" -n BAR_2 -u 2 | bash &
i3-msg exec "lemonbar -n BAR_1 -pb -g${resolution}x$(expr $height + 12)"
fi
elif [[ "$DOCKED" == "true" ]]; then
if [ -z "$height" ]; then
height=18
fi
resolution=$(xrandr | fgrep '*' | cut -d"x" -f1)
geom="${resolution}x${height}"
echo $geom
if [[ "$POSITION" == "bottom" ]]; then
# Docked, bottom
cat <>$HOME/.scripts/lemonbar_fifo | ~/.scripts/fifo_reader.sh | lemonbar -pb \
-g $geom \
-B "#ff${f_back}" -F "$foreground" \
-f "FontAwesome:size=9" \
-o 0 -o -1 -o 0 -o 0 -o 0 \
-f "Terminus:style=Regular:pixelsize=12" \
-f "Terminess Powerline:style=Regular:size=8" \
-f "-xos4-terminusicons2mono-medium-r-normal--12-120-72-72-m-60-iso8859-1" \
-f "siji:style=Regular:pixelsize=13" \
-r 0 -R "#ae95c7" -n BAR_2d -u 2 | bash &
else
# Docked, top
cat <>$HOME/.scripts/lemonbar_fifo | $HOME/.scripts/fifo_reader.sh | lemonbar -p \
-g $geom \
-B "#ff${f_back}" -F "$foreground" \
-f "FontAwesome:size=9" \
-o -3 -o -3 -o 0 -o 0 -o -2 \
-f "Terminus:style=Regular:pixelsize=12" \
-f "Terminess Powerline:style=Regular:size=8" \
-f "-xos4-terminusicons2mono-medium-r-normal--12-120-72-72-m-60-iso8859-1" \
-f "siji:style=Regular:pixelsize=11" \
-r 0 -R "#ae95c7" -n BAR_2d -u 2 | bash &
fi
fi
# Window Title loop: if you are not on gentoo this will probably be xtitle, not xtitle-git
xtitle-git -s | sed -un 's/^/T/p' > $HOME/.scripts/lemonbar_fifo &
# Main feed into the fifo
sleep 0.5 && $HOME/Utilities/bar_scripts/bar_feed.py &
# Initial print of workspaces into the bar
sleep 1 && echo_ws
# Initial print of volume module into the bar
sleep 0.5 && echo -e 'V' "$($HOME/Utilities/volumebar.sh)" > $HOME/.scripts/lemonbar_fifo
# Shadow
shadow = true; # Enabled client-side shadows on windows.
no-dock-shadow = false; # Avoid drawing shadows on dock/panel windows.
no-dnd-shadow = false; # Don't draw shadows on DND windows.
clear-shadow = true; # Zero the part of the shadow's mask behind the window (experimental).
shadow-radius = 7; # The blur radius for shadows. (default 12)
shadow-offset-x = -5; # The left offset for shadows. (default -15)
shadow-offset-y = -5; # The top offset for shadows. (default -15)
shadow-exclude = [
"! name~=''",
"name = 'BAR_1'",
"name = 'BAR_2d'",
"name *= 'lemonbar'",
"name *= '[i3 con] workspace'"
];
# Fading
#fading = true; # Fade windows during opacity changes.
#fade-delta = 5; # The time between steps in a fade in milliseconds. (default 10).
#fade-in-step = 0.03; # Opacity change between steps while fading in. (default 0.028).
#fade-out-step = 0.03; # Opacity change between steps while fading out. (default 0.03).
# no-fading-openclose = true; # Fade windows in/out when opening/closing
#detect-rounded-corners = true;
### highlighted top window rest dimmed
#inactive-dim = 0.2;
#inactive-dim-fixed = true;
fade-delta = 2
# Window type settings
wintypes:
{
tooltip = { fade = true; shadow = true; };
};
#!/bin/bash
. $HOME/.cache/wal/colors.sh
bg_color=$background
border_color="$bg_color"
u_color="$color5"
PANEL_FIFO=$HOME/.scripts/lemonbar_fifo
while read -r line ; do
case $line in
C*)
# clock output
clock="$PADDING${line#?}$PADDING"
;;
D*)
# date output
date="$PADDING${line#?}$PADDING"
;;
W*)
# Workspaces output
workspaces="${line#?}"
;;
M*)
# MPD current song
music="${line#?}"
;;
B*)
# Battery output
battery="${line#?}"
;;
I*)
# Current network or "No Connection"
network="${line#?}"
;;
P*)
# Overall CPU non-idle percentage
cpu="${line#?}"
;;
T*)
# Window title
temptitle="${line#?}"
if [ "${#temptitle}" -ge 50 ]; then
title="${temptitle:0:50}..."
elif [ "${#temptitle}" -eq 0 ]; then
title="desktop"
else
title="${temptitle}"
fi
;;
V*)
# Volume bar
volume="${line#?}"
;;
R*)
# RAM percentage
ram="${line#?}"
;;
esac
# Final print statement and all formatting
printf "%b\n"\
"%{F$foreground}${workspaces}\
%{+u}%{U$u_color}%{F$foreground} ${title} %{-u}\
%{c}%{F$foreground}${music} \
%{r}%{+u}%{U$u_color}%{F$color5}${volume}%{-u}%{F$foreground} \
%{+u}%{U$u_color}%{F$color5}  %{F$foreground}${cpu} %{-u} \
%{+u}%{U$u_color} %{F$color5}${battery}%{F$foreground} %{-u} \
%{+u}%{U$u_color}%{F$color5}${network}%{F$foreground} %{-u} \
%{+u}%{U$u_color}%{F$color5}  %{F$foreground}${date} - %{F$foreground}${clock} %{-u}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment