2025-12-01 17:56:47 +01:00
|
|
|
{
|
|
|
|
|
pkgs,
|
|
|
|
|
username,
|
|
|
|
|
config,
|
|
|
|
|
...
|
|
|
|
|
}:
|
2025-12-01 14:30:02 +01:00
|
|
|
let
|
2025-12-01 17:56:47 +01:00
|
|
|
# homeExternalIPv4 = "${pkgs.coreutils}/bin/cat ${config.sops.secrets.homeExternalIPv4.path}";
|
|
|
|
|
homeExternalIPv4 = "92.118.0.69";
|
2025-12-01 14:30:02 +01:00
|
|
|
in
|
2024-09-27 15:24:05 +02:00
|
|
|
{
|
|
|
|
|
home.file = {
|
2024-10-11 21:23:42 +02:00
|
|
|
"/home/${username}/.local/bin/waybar-yubikey" = {
|
|
|
|
|
executable = true;
|
|
|
|
|
text = ''
|
|
|
|
|
socket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/yubikey-touch-detector.socket"
|
|
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
|
touch_reasons=()
|
|
|
|
|
|
|
|
|
|
if [ ! -e "$socket" ]; then
|
|
|
|
|
printf '{"text": "Waiting for YubiKey socket"}\n'
|
|
|
|
|
while [ ! -e "$socket" ]; do sleep 1; done
|
|
|
|
|
fi
|
|
|
|
|
printf '{"text": ""}\n'
|
|
|
|
|
|
|
|
|
|
nc -U "$socket" | while read -n5 cmd; do
|
|
|
|
|
reason="''${cmd:0:3}"
|
|
|
|
|
|
|
|
|
|
if [ "''${cmd:4:1}" = "1" ]; then
|
|
|
|
|
touch_reasons+=("$reason")
|
|
|
|
|
else
|
|
|
|
|
for i in "''${!touch_reasons[@]}"; do
|
|
|
|
|
if [ "''${touch_reasons[i]}" = "$reason" ]; then
|
|
|
|
|
unset 'touch_reasons[i]'
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "''${#touch_reasons[@]}" -eq 0 ]; then
|
|
|
|
|
printf '{"text": ""}\n'
|
|
|
|
|
else
|
|
|
|
|
if [ "$1" == "0" ]; then
|
|
|
|
|
printf '{"text": ""}\n'
|
|
|
|
|
else
|
|
|
|
|
printf '{"text":"%s"}\n' "''${touch_reasons[@]}"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
done
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-09-27 15:24:05 +02:00
|
|
|
"/home/${username}/.local/bin/waybar-screenrecord" = {
|
|
|
|
|
executable = true;
|
|
|
|
|
text = ''
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
output_off="{\"text\": \"<span color='#aaaaaa'></span>\", \"tooltip\": \"Not recording\", \"alt\": \"\", \"class\": \"\" }"
|
|
|
|
|
output_rec="{\"text\": \"<span color='#e98989'></span>\", \"tooltip\": \"Recording\", \"alt\": \"\", \"class\": \"\" }"
|
2025-05-05 23:08:52 +02:00
|
|
|
|
2024-09-27 15:24:05 +02:00
|
|
|
pidof wf-recorder > /dev/null 2>&1
|
|
|
|
|
if [ $? -eq 0 ]
|
|
|
|
|
then
|
|
|
|
|
if [[ "$1" == "toggle" ]]
|
|
|
|
|
then
|
|
|
|
|
killall -s SIGINT wf-recorder > /dev/null 2>&1
|
|
|
|
|
notify-send -a screenrecorder -t 3000 'Screen recording' "Screen recording was stopped!"
|
|
|
|
|
echo -n $output_off
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
echo -n $output_rec
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
if [[ "$1" == "toggle" ]]
|
|
|
|
|
then
|
|
|
|
|
geometry=$(slurp)
|
|
|
|
|
if [ $? -eq 0 ]
|
|
|
|
|
then
|
|
|
|
|
notify-send -a screenrecorder -t 3000 'Screen recording' "Screen recording was started!"
|
|
|
|
|
sleep 3
|
|
|
|
|
wf-recorder -f "$HOME/downloads/$(date +'screenrecording_%Y-%m-%d-%H%M%S.mp4')" -g "$geometry" > /dev/null 2>&1 &
|
|
|
|
|
echo -n $output_rec
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
echo -n $output_off
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
"/home/${username}/.local/bin/waybar-bluetooth" = {
|
|
|
|
|
executable = true;
|
|
|
|
|
text = ''
|
2025-05-05 23:08:52 +02:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
|
|
|
|
|
typeset -A known=(
|
|
|
|
|
'headphones' '38:18:4C:D1:AE:48'
|
|
|
|
|
'airpods' '2C:18:09:EF:BD:11'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
function get_addr_or_fail () {
|
|
|
|
|
if [ "$known[$1]" = "" ]
|
2024-09-27 15:24:05 +02:00
|
|
|
then
|
2025-05-05 23:08:52 +02:00
|
|
|
printf 'No device specified\n'
|
|
|
|
|
exit 1
|
2024-09-27 15:24:05 +02:00
|
|
|
fi
|
2025-05-05 23:08:52 +02:00
|
|
|
printf "$known[$1]"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
|
"list")
|
|
|
|
|
for k v ("''${(@kv)known}") printf "$k\n"
|
|
|
|
|
;;
|
|
|
|
|
"toggle")
|
|
|
|
|
device=""
|
|
|
|
|
tmp="$2"
|
|
|
|
|
if [ "$tmp" = "" ]
|
|
|
|
|
then
|
|
|
|
|
tmp=$($0 list | bemenu --ignorecase)
|
|
|
|
|
fi
|
|
|
|
|
device=$(get_addr_or_fail "$tmp")
|
|
|
|
|
is_connected=$(bluetoothctl info $device | grep -i 'connected: yes')
|
|
|
|
|
if [ "$is_connected" != "" ]
|
|
|
|
|
then
|
|
|
|
|
bluetoothctl disconnect $device
|
|
|
|
|
else
|
|
|
|
|
bluetoothctl connect $device
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
"status")
|
|
|
|
|
device=$(get_addr_or_fail "$2")
|
|
|
|
|
is_connected=$(bluetoothctl info $device | grep -i 'connected: yes')
|
|
|
|
|
if [ "$is_connected" != "" ]
|
|
|
|
|
then
|
|
|
|
|
echo "{\"text\": \"Connected\", \"class\": \"custom-btdevice\", \"alt\": \"connected\" }"
|
|
|
|
|
else
|
|
|
|
|
echo "{\"text\": \"Disconnected\", \"class\": \"custom-btdevice\", \"alt\": \"disconnected\" }"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
printf "$0 list|toggle <device>|status <device>\n"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2024-09-27 15:24:05 +02:00
|
|
|
'';
|
|
|
|
|
# "/home/${username}/.local/bin/waybar-cpu" = {
|
|
|
|
|
# executable = true;
|
|
|
|
|
# text = ''
|
|
|
|
|
# '';
|
|
|
|
|
# };
|
|
|
|
|
};
|
2025-03-26 15:44:48 +01:00
|
|
|
"/home/${username}/.local/bin/waybar-minutes" = {
|
|
|
|
|
executable = true;
|
|
|
|
|
text = ''
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
echo $(( (24 - $(date +%H)) * 60 - $(date +%M) ))
|
|
|
|
|
'';
|
|
|
|
|
};
|
2025-05-05 23:08:52 +02:00
|
|
|
"/home/${username}/.local/bin/waybar-music" = {
|
|
|
|
|
executable = true;
|
|
|
|
|
text = ''
|
2025-06-03 16:14:31 +02:00
|
|
|
#!/usr/bin/env sh
|
2025-05-05 23:08:52 +02:00
|
|
|
|
2025-06-03 16:14:31 +02:00
|
|
|
META="{{ trunc(artist,17) }} - {{ trunc(title,17) }}"
|
2025-10-30 23:03:34 +01:00
|
|
|
PLAYERS="spotify ncspot mpv mpd spotify_player"
|
2025-05-05 23:08:52 +02:00
|
|
|
|
2025-06-03 16:14:31 +02:00
|
|
|
for PLAYER in $PLAYERS; do
|
|
|
|
|
# if the player is not playing, continue to the next player, until we find one that is playing
|
|
|
|
|
[ "$(playerctl --player=$PLAYER status 2>/dev/null)" != "Playing" ] && continue
|
|
|
|
|
text=$(playerctl metadata --player $PLAYER --format "$META")
|
|
|
|
|
echo -e "{\"text\":\""$text"\", \"class\":\"Playing\"}"
|
|
|
|
|
exit 0
|
|
|
|
|
done
|
2025-05-05 23:08:52 +02:00
|
|
|
|
2025-06-03 16:14:31 +02:00
|
|
|
ICON="❚❚ "
|
|
|
|
|
PAUSERS="spotify ncspot mpd"
|
|
|
|
|
for PAUSER in $PAUSERS; do
|
|
|
|
|
[ "$(playerctl --player=$PAUSER status 2>/dev/null)" == "Paused" ] || [ "$(playerctl --player=$PAUSER status 2>/dev/null)" == "Stopped" ] && text="$ICON"$(playerctl metadata --player $PAUSER --format "$META") && echo -e "{\"text\":\""$text"\", \"class\":\""paused"\"}" && exit 0
|
|
|
|
|
done
|
2025-05-05 23:08:52 +02:00
|
|
|
'';
|
|
|
|
|
};
|
2025-05-09 03:44:17 +02:00
|
|
|
"/home/${username}/.local/bin/waybar-devices" = {
|
|
|
|
|
executable = true;
|
|
|
|
|
text = ''
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2025-05-09 03:51:05 +02:00
|
|
|
if [[ "$(hostname)" == "sakura" ]]; then
|
2025-07-27 21:07:10 +02:00
|
|
|
MICROPHONE_STATE="$(sudo framework_tool --privacy | tail -n2 | head -n1)"
|
|
|
|
|
CAMERA_STATE="$(sudo framework_tool --privacy | tail -n1)"
|
2025-05-09 03:44:17 +02:00
|
|
|
|
2025-05-09 03:51:05 +02:00
|
|
|
if [[ "$(echo $MICROPHONE_STATE | grep 'Microphone: Connected')" ]]; then
|
|
|
|
|
MIC=1
|
|
|
|
|
MTEXT=" - available!"
|
|
|
|
|
else
|
|
|
|
|
MIC=0
|
|
|
|
|
MTEXT=" "
|
|
|
|
|
fi
|
2025-05-09 03:44:17 +02:00
|
|
|
|
2025-05-09 03:51:05 +02:00
|
|
|
if [[ "$(echo $CAMERA_STATE | grep 'Camera: Connected')" ]]; then
|
|
|
|
|
CAM=1
|
|
|
|
|
CTEXT=" - available!"
|
|
|
|
|
else
|
|
|
|
|
CAM=0
|
|
|
|
|
CTEXT=" "
|
|
|
|
|
fi
|
2025-05-09 03:44:17 +02:00
|
|
|
|
2025-10-03 15:24:47 +02:00
|
|
|
echo "$CTEXT $MTEXT"
|
2025-05-09 03:51:05 +02:00
|
|
|
fi
|
2025-05-09 03:44:17 +02:00
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
"/home/${username}/.local/bin/waybar-powerdraw" = {
|
|
|
|
|
executable = true;
|
|
|
|
|
text = ''
|
|
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
|
2025-05-09 03:51:05 +02:00
|
|
|
if [[ -f /sys/class/power_supply/BAT1/status && "$(cat /sys/class/power_supply/BAT1/status)" == "Discharging" ]]; then; cat /sys/class/power_supply/BAT1/current_now /sys/class/power_supply/BAT1/voltage_now | xargs | awk '{print $1*$2/1e12 " W"}'; fi
|
2025-05-09 03:44:17 +02:00
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
"/home/${username}/.local/bin/waybar-vpn" = {
|
2025-12-01 14:30:02 +01:00
|
|
|
# unused nowadays
|
2025-05-09 03:44:17 +02:00
|
|
|
executable = true;
|
|
|
|
|
text = ''
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
ip route | grep -q '10.7.0.0' \
|
|
|
|
|
&& echo '{"text":"Connected","class":"connected","percentage":100}' \
|
|
|
|
|
|| echo '{"text":"Disconnected","class":"disconnected","percentage":0}'
|
|
|
|
|
'';
|
|
|
|
|
};
|
2025-12-01 14:30:02 +01:00
|
|
|
"/home/${username}/.local/bin/waybar-mullvad" = {
|
|
|
|
|
executable = true;
|
|
|
|
|
text = ''
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
STATUS="$(mullvad status | grep -Eio 'connected|connecting|disconnected' | tr '[:upper:]' '[:lower:]')"
|
|
|
|
|
NODE="$(mullvad status | grep -Ei 'relay' | awk '{print $2}' | tr '[:upper:]' '[:lower:]')"
|
|
|
|
|
LOCATION="$(mullvad status | grep -Ei 'location' | cut -d':' -f2 | cut -d'.' -f1 | sed 's/ //g')"
|
|
|
|
|
IPV4="$(mullvad status | grep 'IPv4' | cut -d':' -f3 | sed 's/ //g')"
|
2025-12-01 17:56:47 +01:00
|
|
|
echo "$IPV4" | grep -q "${homeExternalIPv4}" && LOCATION="home"
|
2025-12-01 14:30:02 +01:00
|
|
|
|
2025-12-01 17:56:47 +01:00
|
|
|
echo "$STATUS" | grep -Eioq 'connected|connecting' && TEXT="{\"text\":\"$STATUS ($LOCATION)\",\"location\":\"$LOCATION\",\"node\":\"$NODE\"}" # || ip address show tailscale0 | grep "global tailscale0" && TEXT="{\"text\":\"tailscale ($LOCATION)\",\"location\":\"$LOCATION\",\"node\":\"$NODE\"}"
|
2025-12-01 14:30:02 +01:00
|
|
|
echo "$STATUS" | grep -Eioq 'disconnected' && TEXT="{\"text\":\"$STATUS\",\"location\":\"$LOCATION\",\"node\":\"$NODE\"}"
|
|
|
|
|
|
|
|
|
|
echo "$TEXT"
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-09-27 15:24:05 +02:00
|
|
|
};
|
|
|
|
|
home.packages = with pkgs; [
|
|
|
|
|
wf-recorder
|
|
|
|
|
bemenu
|
2025-05-06 14:41:45 +02:00
|
|
|
ncspot
|
2024-09-27 15:24:05 +02:00
|
|
|
];
|
|
|
|
|
}
|