mirror of
https://github.com/hydroxycarbamide/dotfiles.git
synced 2025-05-07 21:39:07 -04:00
Add waybar
This commit is contained in:
parent
e0c17f71e2
commit
1ff2d77058
19 changed files with 1043 additions and 0 deletions
31
dot_config/waybar/modules/executable_calendar.sh
Normal file
31
dot_config/waybar/modules/executable_calendar.sh
Normal file
|
@ -0,0 +1,31 @@
|
|||
#! /bin/bash
|
||||
|
||||
send_notification() {
|
||||
TODAY=$(date '+%-d')
|
||||
HEAD=$(cal "$1" | head -n1)
|
||||
BODY=$(cal "$1" | tail -n7 | sed -z "s|$TODAY|<u><b>$TODAY</b></u>|1")
|
||||
notify-send -h string:x-canonical-private-synchronous:calendar \
|
||||
"$HEAD" "$BODY$FOOT" -u NORMAL
|
||||
}
|
||||
|
||||
handle_action() {
|
||||
echo "$DIFF" > "$TMP"
|
||||
if [ "$DIFF" -ge 0 ]; then
|
||||
send_notification "+$DIFF months"
|
||||
else
|
||||
send_notification "$((-DIFF)) months ago"
|
||||
fi
|
||||
}
|
||||
|
||||
TMP=${XDG_RUNTIME_DIR:-/tmp}/"$UID"_calendar_notification_month
|
||||
touch "$TMP"
|
||||
|
||||
DIFF=$(<"$TMP")
|
||||
|
||||
case $1 in
|
||||
"curr") DIFF=0;;
|
||||
"next") DIFF=$((DIFF+1));;
|
||||
"prev") DIFF=$((DIFF-1));;
|
||||
esac
|
||||
|
||||
handle_action
|
2
dot_config/waybar/modules/executable_datetime.sh
Normal file
2
dot_config/waybar/modules/executable_datetime.sh
Normal file
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env bash
|
||||
echo "$(date '+%A, %d/%m/%y %r') "
|
37
dot_config/waybar/modules/executable_downloads.py
Normal file
37
dot_config/waybar/modules/executable_downloads.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/python3
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup as soup
|
||||
|
||||
class OS:
|
||||
|
||||
def __init__(self, url, os):
|
||||
self.url = url
|
||||
self.os = os
|
||||
|
||||
def mk_request(self):
|
||||
try:
|
||||
with requests.get(self.url) as response:
|
||||
page = soup(response.text, 'html.parser')
|
||||
return page
|
||||
except requests.HTTPError as err:
|
||||
print(f"Error! {err}")
|
||||
|
||||
def num_downloads(self):
|
||||
page = OS(self.url, self.os).mk_request()
|
||||
|
||||
for downloads in page.find('title'):
|
||||
fmt_name = self.os.split('-')[0]
|
||||
fmt_dl = downloads.text.split(': ')[1]
|
||||
# if fmt_dl.endswith('k'):
|
||||
# return int(fmt_dl.replace('k', '000'))
|
||||
# else:
|
||||
return fmt_dl
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
base_url = "https://img.shields.io/github/downloads/"
|
||||
distros = [('xelphlinux', 'xelph-iso')]
|
||||
|
||||
for distro in distros:
|
||||
print(f" {OS(f'{base_url}{distro[0]}/{distro[1]}/total?label=downloads',distro[0].capitalize()).num_downloads()}")
|
10
dot_config/waybar/modules/executable_updates.sh
Normal file
10
dot_config/waybar/modules/executable_updates.sh
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
pkg_updates() {
|
||||
updates=$(pacman -Qu | wc -l)
|
||||
aurupdates=$(paru -Qua | wc -l)
|
||||
updates=$((updates + aurupdates))
|
||||
if [ $updates -gt 0 ]; then
|
||||
echo -n " $updates"
|
||||
fi
|
||||
}
|
||||
pkg_updates
|
10
dot_config/waybar/modules/mpris/executable_album_art.bak.sh
Normal file
10
dot_config/waybar/modules/mpris/executable_album_art.bak.sh
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
#!/bin/bash
|
||||
album_art=$(playerctl metadata mpris:artUrl)
|
||||
if [[ -z $album_art ]]
|
||||
then
|
||||
# spotify is dead, we should die to.
|
||||
exit
|
||||
fi
|
||||
curl -s "${album_art}" --output "/tmp/cover.jpeg"
|
||||
echo "/tmp/cover.jpeg"
|
41
dot_config/waybar/modules/mpris/executable_album_art.sh
Normal file
41
dot_config/waybar/modules/mpris/executable_album_art.sh
Normal file
|
@ -0,0 +1,41 @@
|
|||
|
||||
#!/bin/bash
|
||||
|
||||
write_art() {
|
||||
album_art=$(playerctl -p $1 metadata mpris:artUrl)
|
||||
status=$?
|
||||
if [[ -z $album_art || $status -eq 0 ]]
|
||||
then
|
||||
album_art=$(playerctl metadata mpris:artUrl)
|
||||
if [[ -z $album_art ]]
|
||||
then
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
curl -s "${album_art}" --output "/tmp/cover.jpeg"
|
||||
echo "/tmp/cover.jpeg"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)"
|
||||
declare -a PAUSED
|
||||
for player in "${PLAYERS[@]}"; do
|
||||
[ "$player" = "playerctld" ] && continue;
|
||||
|
||||
p_status=$(playerctl -p "$player" status 2>/dev/null)
|
||||
|
||||
# if we have one playing, we'll use it and EXIT
|
||||
if [ "$p_status" = "Playing" ]; then
|
||||
write_art "$player"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
[ "$p_status" = "Paused" ] && PAUSED+=("$player")
|
||||
done
|
||||
|
||||
if [ -n "${PAUSED[0]}" ]; then
|
||||
write_art "${PAUSED[0]}"
|
||||
fi
|
76
dot_config/waybar/modules/mpris/executable_get_status.sh
Normal file
76
dot_config/waybar/modules/mpris/executable_get_status.sh
Normal file
|
@ -0,0 +1,76 @@
|
|||
#!/bin/bash
|
||||
|
||||
# The name of polybar bar which houses the main spotify module and the control modules.
|
||||
PARENT_BAR="${1:-music}"
|
||||
PARENT_BAR_PID=$(pgrep -a "polybar" | grep "$PARENT_BAR" | cut -d" " -f1)
|
||||
|
||||
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
|
||||
|
||||
send_hook() {
|
||||
[ -z "$1" ] && echo "send_hook: missing arg" && exit 1
|
||||
polybar-msg -p "$PARENT_BAR_PID" hook mpris-play-pause "$1" 1>/dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
extract_meta() {
|
||||
grep "$1\W" <<< "$meta" | awk '{$1=$2=""; print $0}' | sed 's/^ *//; s/; */;/g' | paste -s -d/ -
|
||||
}
|
||||
|
||||
# if "icon" given, determine icon. otherwise, print metadata
|
||||
get_info() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: get_info PLAYER [icon]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
meta=$(playerctl -p "$1" metadata)
|
||||
|
||||
# get title
|
||||
title=$(extract_meta title)
|
||||
# if no title, try url e.g. vlc
|
||||
if [ -z "$title" ]; then
|
||||
title=$(extract_meta url)
|
||||
title=$(urldecode "${title##*/}")
|
||||
fi
|
||||
|
||||
# if not "icon", display information and return
|
||||
artist=$(extract_meta artist)
|
||||
[ -z "$artist" ] && artist=$(extract_meta albumArtist)
|
||||
|
||||
if [ -n "$artist" ]; then
|
||||
album=$(extract_meta album)
|
||||
[ -n "$album" ] && echo -n " $album "
|
||||
|
||||
echo -n " $artist "
|
||||
fi
|
||||
|
||||
echo "$title"
|
||||
return 0
|
||||
}
|
||||
|
||||
# manually go through players
|
||||
read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)"
|
||||
declare -a PAUSED
|
||||
for player in "${PLAYERS[@]}"; do
|
||||
[ "$player" = "playerctld" ] && continue;
|
||||
|
||||
p_status=$(playerctl -p "$player" status 2>/dev/null)
|
||||
|
||||
# if we have one playing, we'll use it and EXIT
|
||||
if [ "$p_status" = "Playing" ]; then
|
||||
send_hook 1
|
||||
get_info "$player" "$2"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
[ "$p_status" = "Paused" ] && PAUSED+=("$player")
|
||||
done
|
||||
|
||||
# if we have a paused, show it otherwise assume there are no players or have all stopped
|
||||
if [ -n "${PAUSED[0]}" ]; then
|
||||
send_hook 2
|
||||
get_info "${PAUSED[0]}" "$2"
|
||||
else
|
||||
[ "$2" = icon ] && echo "none" || echo " no players "
|
||||
fi
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
# manually go through players
|
||||
read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)"
|
||||
declare -a PAUSED
|
||||
for player in "${PLAYERS[@]}"; do
|
||||
[ "$player" = "playerctld" ] && continue;
|
||||
|
||||
p_status=$(playerctl -p "$player" status 2>/dev/null)
|
||||
|
||||
# if we have one playing, we'll use it and EXIT
|
||||
if [ "$p_status" = "Playing" ]; then
|
||||
echo "Playing"
|
||||
exit 0;
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Paused"
|
15
dot_config/waybar/modules/mpris/executable_scroll_status.sh
Normal file
15
dot_config/waybar/modules/mpris/executable_scroll_status.sh
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
cmd="${0%/*}/get_status.sh $1"
|
||||
|
||||
zscroll -l 30 \
|
||||
--scroll-padding "$(printf ' %.0s' {1..8})" \
|
||||
-d 0.5 \
|
||||
-M "${0%/*}/get_status_paused.sh $1" \
|
||||
-m "Playing" "--scroll 1" \
|
||||
-m "Paused" "--scroll 0" \
|
||||
-m "Stopped" "--scroll 0" \
|
||||
-U 5 -u true "$cmd" &
|
||||
|
||||
wait
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue