add scripts, mostly taken from LARBS
This commit is contained in:
11
.local/bin/cron/README.md
Executable file
11
.local/bin/cron/README.md
Executable file
@@ -0,0 +1,11 @@
|
||||
# Important Note
|
||||
|
||||
These cronjobs have components that require information about your current display to display notifications correctly.
|
||||
|
||||
When you add them as cronjobs, I recommend you precede the command with commands as those below:
|
||||
|
||||
```
|
||||
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $USER)/bus; export DISPLAY=:0; . $HOME/.zprofile; then_command_goes_here
|
||||
```
|
||||
|
||||
This ensures that notifications will display, xdotool commands will function and environmental variables will work as well.
|
||||
46
.local/bin/cron/batterynotify
Executable file
46
.local/bin/cron/batterynotify
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
#export DISPLAY=:0
|
||||
export $(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u "$USER" -o startx)/environ | xargs -0)
|
||||
|
||||
# Battery percentage at which to notify
|
||||
WARNING_LEVEL=30
|
||||
CRITICAL_LEVEL=10
|
||||
|
||||
#BATTERY_LEVEL=$(<"/sys/class/power_supply/BAT0/capacity")
|
||||
#BATTERY_DISCHARGING=$([[ $(<"/sys/class/power_supply/BAT0/status") == "Discharging" ]] && echo 1 || echo 0)
|
||||
# Using acpi
|
||||
BATTERY_DISCHARGING=$(acpi -b | grep "Battery 0" | grep -c "Discharging")
|
||||
BATTERY_LEVEL=$(acpi -b | grep "Battery 0" | grep -P -o '[0-9]+(?=%)')
|
||||
|
||||
# Use temporary files to store whether a notification has already been shown (to prevent multiple notifications)
|
||||
CRIT_FILE=/tmp/battery_crit
|
||||
WARN_FILE=/tmp/battery_warn
|
||||
FULL_FILE=/tmp/battery_full
|
||||
|
||||
# Reset notifications if the battery is charging/discharging
|
||||
if [ "$BATTERY_DISCHARGING" -eq 1 ] && [ -f $FULL_FILE ]; then
|
||||
rm $FULL_FILE
|
||||
elif [ "$BATTERY_DISCHARGING" -eq 0 ]; then
|
||||
if [ -f $WARN_FILE ]; then
|
||||
rm $WARN_FILE
|
||||
fi
|
||||
if [ -f $CRIT_FILE ]; then
|
||||
rm $CRIT_FILE
|
||||
fi
|
||||
fi
|
||||
|
||||
# If the battery is charging and is full (and has not shown notification yet)
|
||||
if [ "$BATTERY_LEVEL" -gt 95 ] && [ "$BATTERY_DISCHARGING" -eq 0 ] && [ ! -f $FULL_FILE ]; then
|
||||
notify-send "Battery Full" "Battery is fully charged." -t 1500
|
||||
touch $FULL_FILE
|
||||
# If the battery is low and is not charging (and has not shown notification yet)
|
||||
elif [ "$BATTERY_LEVEL" -le $CRITICAL_LEVEL ] && [ "$BATTERY_DISCHARGING" -eq 1 ] && [ ! -f $CRIT_FILE ]; then
|
||||
notify-send "⚠️ Critical Battery Level" "${BATTERY_LEVEL}% of battery remaining." -u critical -r 9991 -t 5000
|
||||
# uncomment the line below if you want to get notified at most once
|
||||
#touch $WARN_FILE
|
||||
elif [ "$BATTERY_LEVEL" -le $WARNING_LEVEL ] && [ "$BATTERY_DISCHARGING" -eq 1 ] && [ ! -f $WARN_FILE ]; then
|
||||
notify-send "Low Battery" "${BATTERY_LEVEL}% of battery remaining." -u critical -r 9991 -t 1500
|
||||
# uncomment the line below if you want to get notified at most once
|
||||
#touch $WARN_FILE
|
||||
fi
|
||||
6
.local/bin/cron/crontog
Executable file
6
.local/bin/cron/crontog
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Toggles all cronjobs off/on.
|
||||
# Stores disabled crontabs in ~/.consaved until restored.
|
||||
|
||||
([ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved ] && crontab - < "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && rm "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && notify-send "🕓 Cronjobs re-enabled.") || ( crontab -l > "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && crontab -r && notify-send "🕓 Cronjobs saved and disabled.")
|
||||
17
.local/bin/cron/newsup
Executable file
17
.local/bin/cron/newsup
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Set as a cron job to check for new RSS entries for newsboat.
|
||||
# If newsboat is open, sends it an "R" key to refresh.
|
||||
|
||||
ping -q -c 1 example.org > /dev/null || exit
|
||||
|
||||
/usr/bin/notify-send "📰 Updating RSS feeds..."
|
||||
|
||||
pgrep -f newsboat$ && /usr/bin/xdotool key --window "$(/usr/bin/xdotool search --name newsboat)" R && exit
|
||||
|
||||
echo 🔃 > /tmp/newsupdate
|
||||
pkill -RTMIN+6 "${STATUSBAR:-dwmblocks}"
|
||||
/usr/bin/newsboat -x reload
|
||||
rm -f /tmp/newsupdate
|
||||
pkill -RTMIN+6 "${STATUSBAR:-dwmblocks}"
|
||||
/usr/bin/notify-send "📰 RSS feed update complete."
|
||||
Reference in New Issue
Block a user