This commit is contained in:
sankalp committed 2023-04-24 15:41:27 +05:45
1 parent 0b17aa140b
commit dde4ef218a
136 files changed
+9796

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
#!/bin/bash
cache="$HOME/.cache/eww"
night_light="$cache/night-light.eww"
do_not_disturb="$cache/do-not-disturb.eww"
airplane_mode=$(nmcli radio all | awk 'FNR == 2 {print $2}')
icon_dir="$HOME/.config/polybar/widgets/control/assets/notifications"
[ ! -d $cache ] && mkdir $cache
night_light_toggle () {
if [ ! -f $night_light ]; then
touch $night_light
redshift -P -O 4500 &
notify-send -a "Night Light" -i $icon_dir/nightlight-enable.svg "Night Night" "Blue light filter is on"
else
rm $night_light
redshift -x &
notify-send -a "Night Light" -i $icon_dir/nightlight-disable.svg "Night Night" "Blue light filter is off"
fi
}
do_not_disturb_toggle () {
if [ ! -f "$do_not_disturb" ]; then
touch "$do_not_disturb"
dunstctl set-paused true
else
rm "$do_not_disturb"
dunstctl set-paused false &
notify-send -a "Notifications" -i $icon_dir/dnd-enable.svg "Do Not Disturb" "Notifications are Unpaused" -u Normal
fi
}
airplane_mode_toggle () {
if [ $airplane_mode = enabled ]; then
nmcli radio all off &
notify-send -a "Wireless" -i $icon_dir/airplane-disable.svg "Airplane Mode" "Radios are turn off"
else
nmcli radio all on &
notify-send -a "Wireless" -i $icon_dir/airplane-enable.svg "Airplane Mode" "Radios are back on"
fi
}
bluetooth_toggle () {
if rfkill list bluetooth | grep -q 'blocked: yes'; then
rfkill unblock bluetooth &
notify-send -a "Bluetooth" -i $icon_dir/bluetooth-disable.svg "Bluetooth" "Bluetooth is back on"
else
rfkill block bluetooth &
notify-send -a "Bluetooth" -i $icon_dir/bluetooth-enable.svg "Bluetooth" "Bluetooth is turn off"
fi
}
case $1 in
nl-toggle)
night_light_toggle
;;
dnd-toggle)
do_not_disturb_toggle
;;
air-toggle)
airplane_mode_toggle
;;
blue-toggle)
bluetooth_toggle
;;
nl-check)
[[ ! -f "$night_light" ]] && echo "Off" || echo "On"
;;
air-check)
[[ $airplane_mode = enabled ]] && echo "Off" || echo "On"
;;
dnd-check)
[[ ! -f "$do_not_disturb" ]] && echo "Off" || echo "On"
;;
blue-check)
rfkill list bluetooth | grep -q 'blocked: yes' && echo "Off" || echo "On"
;;
esac
+130
View File
@@ -0,0 +1,130 @@
#!/bin/bash
cache_dir="$HOME/.cache/eww/notify-logs"
cache="$cache_dir/notifications.txt"
[ ! -d $cache_dir ] && mkdir $cache_dir
[ ! -f $cache ] && touch $cache
create_cache () {
case $DUNST_URGENCY in
LOW|NORMAL|CRITICAL)
urgency=$DUNST_URGENCY
;;
*)
urgency="OTHER"
;;
esac
TIMESTAMP=$(date +%H:%M)
[ "$DUNST_SUMMARY" = "" ] && summary="Summary unavailable." || summary="$DUNST_SUMMARY"
[ "$DUNST_BODY" = "" ] && body="Body unavailable." || body="$(printf "$DUNST_BODY" | perl -MHTML::Entities -pe 'decode_entities($_);')"
# TODO: Getting and caching web notification icons (dunstctl history won't show the icon path :()
if [[ $DUNST_ICON_PATH == "" ]]; then
APP_NAME=$(echo $DUNST_APP_NAME | awk '{print tolower($0)}')
ICON_PATH=/usr/share/icons/Papirus/128x128/apps/$APP_NAME.svg
else
FIXED_ICON_PATH=$(echo ${DUNST_ICON_PATH} | sed 's/32x32/48x48/g')
ICON_PATH=$FIXED_ICON_PATH
fi
# If you have a mpris player that send notification you can add one here just follow the layout
if [[ $DUNST_APP_NAME == "Spotify" ]]; then
ICON_PATH=$(./scripts/music cover-notification spotify)
fi
if [[ $DUNST_APP_NAME == "Music Player Daemon" ]]; then
if [[ $DUNST_BODY =~ "by" ]]; then
ICON_PATH=$(./scripts/music cover-notification mpd)
else
ICON_PATH=/usr/share/icons/Papirus/128x128/apps/mpd.svg
fi
fi
if [[ $DUNST_APP_NAME == "Screenshot" ]]; then
echo '(notification-card-screenshot :class "notification-card $notification-card-screenshot" :U "LOW" :SL "'$DUNST_ID'" :summary "'$summary'" :image "'$ICON_PATH'" :application "'$DUNST_APP_NAME'" :timestamp "'$TIMESTAMP'")' \
| cat - "$cache" \
| sponge "$cache"
elif [[ $DUNST_APP_NAME == "Volume" ]]; then
echo 'Null' # This is still a work in progress, for now this will be ignored by the notification-panel (Also you can follow the layout if you want to add ignore notifications)
elif [[ $DUNST_APP_NAME == "Brightness" ]]; then
echo 'Null'
else
echo '(notification-card :class "notification-card notification-card-'$DUNST_APP_NAME'" :U "'$DUNST_URGENCY'" :SL "'$DUNST_ID'" :body "'$body'" :summary "'$summary'" :image "'$ICON_PATH'" :application "'$DUNST_APP_NAME'" :timestamp "'$TIMESTAMP'")' \
| cat - "$cache" \
| sponge "$cache"
fi
}
make_literal () {
caches="$(tr '\n' ' ' < "$cache")"
if [[ "$caches" == "" ]]; then
echo '(box :class "notifications-empty-box" :height 550 :orientation "v" :space-evenly "false" (image :class "notifications-empty-banner" :valign "end" :vexpand true :path "assets/notifications/notifications-off.svg" :image-width 300 :image-height 200) (label :vexpand true :valign "start" :wrap true :class "notifications-empty-label" :text "No Notifications"))'
else
echo "(scroll :height 550 :vscroll true (box :orientation 'v' :class 'notification-scroll-box' :spacing 10 :space-evenly 'false' $caches))"
fi
}
clear_logs () {
killall dunst 2>/dev/null
$HOME/.config/polybar/widgets/control/scripts/notification & disown
echo > "$cache"
rm -rf $HOME/.cache/eww/music/notification-cover/*.png
}
subscribe () {
make_literal
lines=$(cat $cache | wc -l)
while sleep 0.1; do
new=$(cat $cache | wc -l)
[[ $lines -ne $new ]] && lines=$new && echo
done | read_literal
}
read_literal () {
while read -r _; do
make_literal
done
}
remove_line () {
sed -i '/SL "'$1'"/d' "$cache"
}
case $1 in
pop)
sed -i '1d' "$cache"
;;
drop)
sed -i '$d' "$cache"
;;
remove)
remove_line $2
;;
clear)
clear_logs
;;
subscribe)
subscribe
;;
criticals)
printf '%03d\n' $(cat $cache | grep CRITICAL | wc --lines)
;;
lows)
printf '%03d\n' $(cat $cache | grep LOW | wc --lines)
;;
normals)
printf '%03d\n' $(cat $cache | grep NORMAL | wc --lines)
;;
*)
create_cache
;;
esac
sed -i '/^$/d' "$cache"
+107
View File
@@ -0,0 +1,107 @@
#!/bin/bash
players="spotify,%any,firefox,chromium,brave,mpd"
player_status=$(playerctl -p $players status)
artist=$(playerctl -p $players metadata --format '{{ artist }}')
title=$(playerctl -p $players metadata --format '{{ title }}')
albumart="$(playerctl -p $players metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')"
cache="$HOME/.cache/eww/music"
[ ! -d $cache ] && mkdir $cache
status_icon () {
if [ "$player_status" = "Playing" ]; then
echo "󰏥"
elif [ "$player_status" = "Paused" ]; then
echo "󰐌"
else
echo "󰐌"
fi
}
status_value () {
player_name=$(playerctl -p $players -l | head -n 1)
[ "$player_status" = "Playing" ] && echo "Now Playing - via ${player_name^}" || echo "Music"
}
title () {
[ -z "$title" ] && echo "Nothing Playing" || echo $title
}
artist () {
if [ "$title" = "Advertisement" ]; then
echo "Spotify Free"
else
if [ -z "$artist" ]; then
echo "Unknown Artist";
else
echo "by $artist"
fi
fi
}
cover_notification () {
cover_dir="$cache/notification-cover"
[ ! -d $cover_dir ] && mkdir $cover_dir
cover="$cover_dir/$RANDOM-cover.png"
fallback="$HOME/.config/eww/images/fallback.png"
players_pass=$1
if [[ $players_pass == "mpd" ]]; then
albumart="$(playerctl -p mpd metadata mpris:artUrl)"
else
albumart="$(playerctl -p $players_pass metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')"
fi
[ $(playerctl -p $players_pass metadata mpris:artUrl) ] && curl -s "$albumart" --output $cover || cp $fallback $cover
echo $cover | tail -n 1
}
cover () {
cover="$cache/cover.png"
fallback="$HOME/.config/eww/images/fallback.png"
[ $(playerctl -p $players metadata mpris:artUrl) ] && curl -s "$albumart" --output $cover || cp $fallback $cover
echo $cover
}
position () {
position=$(playerctl -p $players position | sed 's/..\{6\}$//')
duration=$(playerctl -p $players metadata mpris:length | sed 's/.\{6\}$//')
if [[ $position -gt 0 ]]; then
printf "%0d:%02d" $((position%3600/60)) $((position%60))
printf " / "
printf "%0d:%02d" $((duration%3600/60)) $((duration%60))
fi
}
case $1 in
status)
status_value
;;
status-icon)
status_icon
;;
title)
title
;;
artist)
artist
;;
title-artist)
echo $(title) - $(artist)
;;
cover)
cover
;;
cover-notification)
cover_notification $2
;;
position)
position || echo "--:-- / --:-- "
;;
esac
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
if [[ `pidof dunst` ]]; then
pkill dunst
fi
dunst -config $HOME/.config/dunst/dunstrc
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
players="spotify,%any,firefox,chromium,brave,mpd"
player_status=$(playerctl -p $players status)
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
exit=$?
scroll () {
zscroll -l 20 \
--delay 1 \
--scroll-padding " | " \
--match-command "$script_dir/scroll scroll-music" \
--match-text "Playing" "--scroll 1" \
--match-text "Paused" "--scroll 0" \
--update-check true "$script_dir/scroll" &
wait
}
if [ $exit -eq 0 ]; then
status=$player_status
else
status="Offline"
fi
if [ "$1" == "scroll-music" ]; then
echo $status
else
if [ $status = "Stopped" ]; then
echo "Offline"
elif [ $status = "Paused" ]; then
playerctl -p $players metadata --format '{{ artist }} - {{ title }}'
elif [ $status = "Offline" ]; then
echo $status
else
playerctl -p $players metadata --format '{{ artist }} - {{ title }}'
fi
fi
case $1 in
scroll-toggle)
scroll
;;
esac
+219
View File
@@ -0,0 +1,219 @@
#!/bin/bash
brightness=$(brightnessctl i | grep -oP '\(\K[^%\)]+')
volume=$(pamixer --get-volume)
empty_battery="1"
volume_icon () {
if [ $volume -lt "35" ]; then
icon="󰖀"
elif [ $volume -lt "70" ]; then
icon="󰕾"
else
icon="󰕾"
fi
[ $(pamixer --get-mute) = "true" ] && icon="󰝟"
echo $icon
}
brightness_icon () {
if [ $brightness -lt "15" ]; then
echo "󰃞"
elif [ $brightness -lt "30" ]; then
echo "󰃞"
elif [ $brightness -lt "45" ]; then
echo "󰃟"
elif [ $brightness -lt "60" ]; then
echo "󰃟"
elif [ $brightness -lt "75" ]; then
echo "󰃟"
elif [ $brightness -lt "90" ]; then
echo "󰃠"
else
echo "󰃠"
fi
}
network_icon () {
wifi_check=$(cat /sys/class/net/w*/operstate)
ethernet_check=$(cat /sys/class/net/e*/operstate)
wifi_strength=$(nmcli dev wifi list | awk '/\*/{if (NR!=1) {print $9}}')
if [ $wifi_check = up ]; then
if [ $wifi_strength -lt "10" ]; then
echo ""
elif [ $wifi_strength -lt "25" ]; then
echo ""
elif [ $wifi_strength -lt "45" ]; then
echo ""
elif [ $wifi_strength -lt "65" ]; then
echo ""
elif [ $wifi_strength -lt "85" ]; then
echo ""
else
echo ""
fi
elif [ $ethernet_check = up ]; then
echo ""
else
echo ""
fi
}
network_speed () {
interface="$(ip link | awk '/state UP/ {print $2}' | tr -d :)"
received_1=$(cat /sys/class/net/$interface/statistics/rx_bytes)
transmitted_1=$(cat /sys/class/net/$interface/statistics/tx_bytes)
received_2=$(cat /sys/class/net/$interface/statistics/rx_bytes)
transmitted_2=$(cat /sys/class/net/$interface/statistics/tx_bytes)
bandwidth_up=`expr $transmitted_2 - $transmitted_1`
bandwidth_down=`expr $received_2 - $received_1`
upspeed=$(expr $bandwidth_up / 1024)
downspeed=$(expr $bandwidth_down / 1024)
echo "$downspeed kB/s $upspeed kB/s"
}
network_name () {
ssid=$(iwgetid -r)
[ -z $ssid ] && echo "Not Connected" || echo "Connected to $ssid"
}
battery_empty () {
if [ "$empty_battery" -gt 0 ]; then
if [ ! -f "$HOME/.cache/empty_battery_capacity" ]; then
echo $(($RANDOM % 100)) > "$HOME/.cache/empty_battery_capacity"
fi
fi
}
battery_icon () {
if [[ -d /sys/class/power_supply/ACAD ]]; then
echo ""
elif [[ -d /sys/class/power_supply/BAT ]]; then
if [[ $(cat /sys/class/power_supply/BAT/status) == "Discharging" ]]; then
echo ""
else
echo ""
fi
else
echo ""
fi
}
battery_capacity () {
if [ "$empty_battery" -gt 0 ]; then
if [ -f "$HOME/.cache/empty_battery_capacity" ]; then
echo $(cat "$HOME/.cache/empty_battery_capacity")
fi
elif [ -f /sys/class/power_supply/BAT0/capacity ]; then
echo $(cat /sys/class/power_supply/BAT0/capacity)
fi
}
cpu_value () {
preview_total=0
preview_idle=0
cache="/tmp/cpu_value.cache.eww"
if [[ -f "${cache}" ]]; then
file=$(cat "${cache}")
preview_total=$(echo "${file}" | head -n 1)
preview_idle=$(echo "${file}" | tail -n 1)
fi
cpu=(`cat /proc/stat | grep '^cpu '`)
unset cpu[0]
idle=${cpu[4]}
total=0
for value in "${cpu[@]:0:4}"; do
let "total=$total+$value"
done
if [[ "${preview_total}" != "" ]] && [[ "${preview_idle}" != "" ]]; then
let "diff_idle=$idle-$preview_idle"
let "diff_total=$total-$preview_total"
let "diff_usage=(1000*($diff_total-$diff_idle)/$diff_total+5)/10"
echo "${diff_usage}"
else
echo "0"
fi
echo "${total}" > "${cache}"
echo "${idle}" >> "${cache}"
}
temperature_value () {
IFS=')' read -ra core_temp_arr <<< $(sensors | grep '^Core\s[[:digit:]]\+:')
total_cpu_temp=0
index=0
for i in "${core_temp_arr[@]}"; do :
temp=$(echo $i | sed -n 's/°C.*//; s/.*[+-]//; p; q')
let index++
total_cpu_temp=$(echo "$total_cpu_temp + $temp" | bc)
done
avg_cpu_temp=$(echo "scale=2; $total_cpu_temp / $index" | bc)
temp_status="$avg_cpu_temp"
echo $temp_status
}
case $1 in
volume-icon)
volume_icon
;;
brightness-icon)
brightness_icon
;;
volume-value)
echo $volume
;;
brightness-value)
echo $brightness
;;
network-icon)
network_icon
;;
network-speed)
network_speed
;;
network-name)
network_name
;;
empty-battery)
battery_empty
;;
battery-icon)
battery_icon
;;
battery-capacity)
battery_capacity
;;
cpu-value)
cpu_value
;;
memory-value)
printf "%.0f\n" $(free -m | grep Mem | awk '{print ($3/$2)*100}')
;;
temperature-value)
temperature_value
;;
disk-value)
df -h / | awk '{print $5}' | tail -n1 | sed 's/%//g'
;;
esac
+164
View File
@@ -0,0 +1,164 @@
#!/bin/bash
cache="$HOME/.cache/eww/weather"
cache_status="$cache/status"
cache_temperature="$cache/temperature"
cache_gradient_1="$cache/gradient_1"
cache_gradient_2="$cache/gradient_2"
cache_icon="$cache/icon"
cache_city="$cache/city"
cache_country="$cache/country"
[ ! -d $cache ] && mkdir $cache
key="1f6e449790b8cf73a3cab8d5715483f8"
id="6941099"
unit="metric" # Available options : 'metric' or 'imperial'
data () {
weather=`curl -sf "http://api.openweathermap.org/data/2.5/weather?APPID=$key&id=$id&units=$unit"`
if [ ! -z "$weather" ]; then
temperature=$(echo "$weather" | jq ".main.temp" | cut -d "." -f 1)
city=$(echo "$weather" | jq -r ".name" | head -1)
country=$(echo "$weather" | jq -r ".sys.country" | head -1)
icon_code=$(echo "$weather" | jq -r ".weather[].icon" | head -1)
description=$(echo "$weather" | jq -r ".weather[].description" | head -1 | sed -e "s/\b\(.\)/\u\1/g")
if [ "$icon_code" == "50d" ]; then
icon="󰖐"
gradient_1="#ece3b1"
gradient_2="#c9d4ff"
elif [ "$icon_code" == "50n" ]; then
icon="󰖐"
gradient_1="#ceace8"
gradient_2="#c9d4ff"
elif [ "$icon_code" == "01d" ]; then
icon="󰖙"
gradient_1="#ece3b1"
gradient_2="#ece3b1"
elif [ "$icon_code" == "01n" ]; then
icon=""
gradient_1="#ceace8"
gradient_2="#ceace8"
elif [ "$icon_code" == "02d" ]; then
icon=""
gradient_1="#ece3b1"
gradient_2="#a3cbe7"
elif [ "$icon_code" == "02n" ]; then
icon=""
gradient_1="#ceace8"
gradient_2="#a3cbe7"
elif [ "$icon_code" == "03d" ]; then
icon=""
gradient_1="#ece3b1"
gradient_2="#a3cbe7"
elif [ "$icon_code" == "03n" ]; then
icon=""
gradient_1="#ceace8"
gradient_2="#a3cbe7"
elif [ "$icon_code" == "04d" ]; then
icon=""
gradient_1="#a3cbe7"
gradient_2="#ece3b1"
elif [ "$icon_code" == "04n" ]; then
icon=""
gradient_1="#a3cbe7"
gradient_2="#ceace8"
elif [ "$icon_code" == "09d" ]; then
icon=""
gradient_1="#b4e3ad"
gradient_2="#ece3b1"
elif [ "$icon_code" == "09n" ]; then
icon=""
gradient_1="#b4e3ad"
gradient_2="#ceace8"
elif [ "$icon_code" == "10d" ]; then
icon=""
gradient_1="#ffdede"
gradient_2="#ece3b1"
elif [ "$icon_code" == "10n" ]; then
icon=""
gradient_1="#ffdede"
gradient_2="#ceace8"
elif [ "$icon_code" == "11d" ]; then
icon=""
gradient_1="#e5a3a1"
gradient_2="#ece3b1"
elif [ "$icon_code" == "11n" ]; then
icon=""
gradient_1="#e5a3a1"
gradient_2="#ceace8"
elif [ "$icon_code" == "13d" ]; then
icon=""
gradient_1="#c9d4ff"
gradient_2="#c9d4ff"
elif [ "$icon_code" == "13n" ]; then
icon=""
gradient_1="#c9d4ff"
gradient_2="#c9d4ff"
elif [ "$icon_code" == "40d" ]; then
icon="煮"
gradient_1="#a3cbe7"
gradient_2="#a3cbe7"
elif [ "$icon_code" == "40n" ]; then
icon="煮"
gradient_1="#a3cbe7"
gradient_2="#a3cbe7"
else
icon=""
gradient_1="#b4e3ad"
gradient_2="#a3cbe7"
fi
echo "$icon" > $cache_icon
echo "$city" > $cache_city
echo "$country" > $cache_country
echo "$description" > $cache_status
echo "$temperature""°C" > $cache_temperature
echo "$gradient_1" > $cache_gradient_1
echo "$gradient_2" > $cache_gradient_2
else
echo "-" > $cache_city
echo "-" > $cache_country
echo "Weather Unavailable" > $cache_status
echo "" > $cache_icon
echo "-" > $cache_temperature
echo "#b4e3ad" > $cache_gradient_1
echo "#a3cbe7" > $cache_gradient_2
fi
}
case $1 in
data)
data
;;
icon)
data &
cat $cache_icon
;;
color-1)
data &
cat $cache_gradient_1
;;
color-2)
data &
cat $cache_gradient_2
;;
city)
data &
cat $cache_city
;;
country)
data &
cat $cache_country
;;
temperature)
data &
cat $cache_temperature
;;
status)
data &
cat $cache_status
;;
esac
+37
View File
@@ -0,0 +1,37 @@
#!/bin/bash
nicknames=(一 二 三 四 五 六 七 八 九 十)
start=0
workspaces () {
wmctrl -d | awk '{ print $1 " " $2 " " $9 }' | grep -v NSP | while read -r id active name; do
name="${name#*_}"
if [ "$active" == '*' ]; then
button_status="active"
else
button_status="inactive"
fi
if wmctrl -l | grep --regexp '.*\s\+'"$id"'\s\+.*' >/dev/null; then
button_fill="occupied"
button_name="${nicknames[$start]}"
else
button_fill="empty"
button_name="${nicknames[$start]}"
fi
load+="(button :class '$button_status-$button_fill' :onclick 'wmctrl -s $id' '$button_name')"
echo -n $load
load=""
((start=start+1))
done
}
xprop -spy -root _NET_CURRENT_DESKTOP | while read -r; do
echo '(box :orientation "h" :class "workspaces" :space-evenly true :halign "start" :vexpand true '"$(workspaces)"')'
done
# スパゲッティはもうありませんが、出力は長くなります :(