refactor(repo): most of these scripts are outdated, refactored desec
All checks were successful
/ test (push) Successful in 23s
All checks were successful
/ test (push) Successful in 23s
This commit is contained in:
parent
5b03adaaa9
commit
6682679493
18 changed files with 154 additions and 133 deletions
BIN
archived/daemons/battery-daemon
Executable file
BIN
archived/daemons/battery-daemon
Executable file
Binary file not shown.
207
archived/daemons/battery-daemon.cpp
Normal file
207
archived/daemons/battery-daemon.cpp
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sched.h> // pid_t data type
|
||||
#include <string>
|
||||
#include <sys/select.h>
|
||||
#include <thread>
|
||||
#include <unistd.h> // For fork();
|
||||
|
||||
using namespace std;
|
||||
|
||||
// atomic type => ensure that variable can be safely accessed and modified.
|
||||
// // 1 = Suddenly at 0%, 0 = Not at 0%
|
||||
atomic<int> BAT_EMPTY(0);
|
||||
|
||||
// If another instance of this program is running...
|
||||
const char *lockFilePath = "/tmp/bat-daemon-run";
|
||||
|
||||
// Checks if the file exists. (Another instance is running)
|
||||
bool isRunning() {
|
||||
ifstream lockFile(lockFilePath);
|
||||
return lockFile.good();
|
||||
}
|
||||
|
||||
// Creates file w/ PID
|
||||
void createLockFile() {
|
||||
ofstream lockFile(lockFilePath);
|
||||
lockFile << getpid();
|
||||
}
|
||||
|
||||
// Removes file.
|
||||
void removeLockFile() { remove(lockFilePath); }
|
||||
|
||||
void send_notifs_empty() {
|
||||
|
||||
while (true) {
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 100000;
|
||||
|
||||
ifstream BAT_PERCENT_FILE("/sys/class/power_supply/BAT0/capacity");
|
||||
int BAT_PERCENT;
|
||||
|
||||
BAT_PERCENT_FILE >> BAT_PERCENT;
|
||||
|
||||
string command =
|
||||
"notify-send 'Low Battery' '<b>ALERT!</b> " + to_string(BAT_PERCENT) +
|
||||
"% Battery Remaining.' -u critical -i 'battery-caution' -t 5000";
|
||||
|
||||
// If battery is empty...
|
||||
if (BAT_EMPTY.load() == 1) {
|
||||
system(command.c_str());
|
||||
this_thread::sleep_for(chrono::seconds(5));
|
||||
} else {
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void send_notifs_warn(const int &percent) {
|
||||
// Formulate command
|
||||
string command =
|
||||
"notify-send 'Low Battery' '" + to_string(percent) +
|
||||
"% of battery remaining.' -u critical -i 'battery-caution' -t 5000";
|
||||
|
||||
// Execute command as a C-String (same contents, but compatible with C++ code)
|
||||
// "Returns a pointer to an array that contains the contents of the variable"
|
||||
system(command.c_str());
|
||||
}
|
||||
|
||||
void send_notifs_charge(const int &percent, const int status) {
|
||||
string command;
|
||||
|
||||
switch (status) {
|
||||
case 1:
|
||||
command = "notify-send 'Charging' 'Charging battery at " +
|
||||
to_string(percent) +
|
||||
"%' -u low -i 'battery-level-50-charging-symbolic' -t 5000";
|
||||
break;
|
||||
|
||||
case 0:
|
||||
command = "notify-send 'Discharging' '" + to_string(percent) +
|
||||
"% remaining' -u low -i 'battery-level-70-symbolic' -t 5000";
|
||||
break;
|
||||
}
|
||||
|
||||
system(command.c_str());
|
||||
}
|
||||
|
||||
void send_notifs_full() {
|
||||
string command = "notify-send 'Battery Full' 'Battery is fully charged!' -i "
|
||||
"'battery-full-charged' -t 5000";
|
||||
system(command.c_str());
|
||||
}
|
||||
|
||||
// Checks battery info. (Charging, Discharging, etc.)
|
||||
void battery() {
|
||||
int OLD_BAT_PERCENT = 100; // Maxing out to prevent bugs
|
||||
int CHARGE = 0; // 1 = Charging, 0 = Discharging
|
||||
int BAT_FULL = 0; // 1 = Full, 0 = Not Full
|
||||
|
||||
while (true) {
|
||||
int BAT_WARN = 35;
|
||||
// Read and Grab File Info:
|
||||
|
||||
// ifstream (input file stream) class: operates on files (I/O)
|
||||
ifstream BAT_STATUS_FILE("/sys/class/power_supply/BAT0/status");
|
||||
string BAT_STATUS;
|
||||
|
||||
ifstream BAT_PERCENT_FILE("/sys/class/power_supply/BAT0/capacity");
|
||||
int BAT_PERCENT;
|
||||
|
||||
// If it can't extract info, exit.
|
||||
if (!(BAT_PERCENT_FILE >> BAT_PERCENT) ||
|
||||
!(BAT_STATUS_FILE >> BAT_STATUS)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Timing:
|
||||
// timeval = Time Value accurate from microseconds to years.
|
||||
struct timeval tv;
|
||||
|
||||
// Set intervals: 0sec + 100 milsec.
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 100000;
|
||||
|
||||
// If the actual battery is charging, update all values
|
||||
if (BAT_STATUS == "Charging") {
|
||||
if (BAT_PERCENT < 99 && CHARGE == 0) {
|
||||
CHARGE = 1;
|
||||
OLD_BAT_PERCENT = BAT_PERCENT;
|
||||
BAT_FULL = 0;
|
||||
send_notifs_charge(BAT_PERCENT, CHARGE);
|
||||
|
||||
} else if (BAT_PERCENT >= 99 && BAT_FULL == 0) {
|
||||
BAT_FULL = 1;
|
||||
CHARGE = 1;
|
||||
send_notifs_full();
|
||||
|
||||
} else if (BAT_PERCENT > OLD_BAT_PERCENT) {
|
||||
OLD_BAT_PERCENT = BAT_PERCENT;
|
||||
}
|
||||
|
||||
if (BAT_EMPTY.load() == 1) {
|
||||
BAT_EMPTY.store(0);
|
||||
}
|
||||
}
|
||||
|
||||
// If the actual battery is discharging, update all values
|
||||
if (BAT_STATUS == "Discharging") {
|
||||
if (CHARGE == 1) {
|
||||
CHARGE = 0;
|
||||
send_notifs_charge(BAT_PERCENT, CHARGE);
|
||||
|
||||
} else if (BAT_PERCENT < 99 && BAT_FULL == 1) {
|
||||
BAT_FULL = 0;
|
||||
|
||||
} else if (BAT_PERCENT <= BAT_WARN && BAT_PERCENT < OLD_BAT_PERCENT) {
|
||||
OLD_BAT_PERCENT = BAT_PERCENT;
|
||||
send_notifs_warn(BAT_PERCENT);
|
||||
}
|
||||
|
||||
// Change value of BAT_EMPTY (alert notification)
|
||||
if (BAT_PERCENT < 10 && BAT_EMPTY.load() == 0) {
|
||||
BAT_EMPTY.store(1);
|
||||
}
|
||||
}
|
||||
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
}
|
||||
}
|
||||
|
||||
// Initializer
|
||||
int main() {
|
||||
// Change directory to root
|
||||
chdir("/");
|
||||
|
||||
// Redirects all streams to /dev/null
|
||||
// freopen("/dev/null", "r", stdin);
|
||||
// freopen("/dev/null", "w", stdout);
|
||||
// freopen("/dev/null", "w", stderr);
|
||||
|
||||
if (isRunning()) {
|
||||
ifstream lockFile(lockFilePath);
|
||||
int pid;
|
||||
|
||||
lockFile >> pid;
|
||||
|
||||
removeLockFile();
|
||||
|
||||
kill(pid, 1);
|
||||
}
|
||||
|
||||
createLockFile();
|
||||
|
||||
thread bg(send_notifs_empty);
|
||||
bg.detach();
|
||||
|
||||
battery();
|
||||
|
||||
return 0;
|
||||
}
|
||||
11
archived/notifs/battery-status
Executable file
11
archived/notifs/battery-status
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
BATTERY=$(acpi | grep -vwE "(unavailable)" | grep -o '[0-9]' | head -n 1)
|
||||
BAT_PERCENT=$(acpi -b | grep "Battery $BATTERY" | grep -P -o "[0-9]+(?=%)")
|
||||
DISCHARGING_COUNT=$(acpi -b | grep "Battery $BATTERY" | grep -E "until|remaining" | grep -c "Discharging")
|
||||
NOTCHARGING_COUNT=$(acpi -b | grep "Battery $BATTERY" | grep -c "Not Charging")
|
||||
|
||||
if [[ $DISCHARGING_COUNT -eq 0 ]] || [[ $NOTCHARGING_COUNT -eq 1 ]]; then
|
||||
dunstify "Battery Status" "Battery is currently charging at ${BAT_PERCENT}%" -i "battery-level-50-charging-symbolic" -r 9991 -t 5000
|
||||
else
|
||||
dunstify "Battery Status" "Battery is currently discharging at ${BAT_PERCENT}%" -i "battery-level-50-symbolic" -r 9991 -t 5000
|
||||
fi
|
||||
33
archived/notifs/brightness
Executable file
33
archived/notifs/brightness
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
CURRENT_BRIGHTNESS=$(xbacklight -get)
|
||||
|
||||
bright_inc() {
|
||||
dunstify "Increasing Brightness" "Current Brightness: ${CURRENT_BRIGHTNESS}%" -i "display-brightness-medium-symbolic" -t 5000 -r 9991
|
||||
}
|
||||
|
||||
bright_dec() {
|
||||
dunstify "Decreasing Brightness" "Current Brightness: ${CURRENT_BRIGHTNESS}%" -i "display-brightness-low-symbolic" -t 5000 -r 9991
|
||||
|
||||
}
|
||||
|
||||
keybind-func() {
|
||||
echo "$CURRENT_BRIGHTNESS"
|
||||
}
|
||||
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
inc)
|
||||
bright_inc && exit 0
|
||||
;;
|
||||
|
||||
dec)
|
||||
bright_dec && exit 0
|
||||
;;
|
||||
|
||||
keybind)
|
||||
keybind-func && exit 0
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
15
archived/notifs/info
Executable file
15
archived/notifs/info
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Enter scripts directory
|
||||
cd ~/.scripts/notifs || exit
|
||||
|
||||
# Constants
|
||||
CURRENT_VOL=$(./volume keybind | grep -o '^[^ ]*')
|
||||
CURRENT_MIC_VOL=$(./volume keybind | awk '{ print $2 }')
|
||||
BRIGHTNESS=$(./brightness keybind)
|
||||
|
||||
# Variables for display, basically multiplies floats to integers
|
||||
DISPLAY_VOL=$(awk '{ print $1 * $2 }' <<<"${CURRENT_VOL} 100")
|
||||
DISPLAY_MIC_VOL=$(awk '{ print $1 * $2 }' <<<"${CURRENT_MIC_VOL} 100")
|
||||
|
||||
dunstify "All other info:" "Brightness: $BRIGHTNESS%\nCurrent Volume: $DISPLAY_VOL%\nCurrent Mic. Volume: $DISPLAY_MIC_VOL%"
|
||||
4
archived/notifs/time
Executable file
4
archived/notifs/time
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
CURRENT_TIME=$(date)
|
||||
|
||||
notify-send "Date / Time Info:" "${CURRENT_TIME}" -t 5000 -r 9991
|
||||
130
archived/notifs/volume
Executable file
130
archived/notifs/volume
Executable file
|
|
@ -0,0 +1,130 @@
|
|||
#!/bin/bash
|
||||
|
||||
CURRENT_VOL=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{ print $2 }')
|
||||
VOL_PRESENT=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{ print $2 }' | cut -c 3,4)
|
||||
|
||||
CURRENT_MIC_VOL=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | awk '{ print $2 }')
|
||||
MIC_PRESENT=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | awk '{ print $2 }' | cut -c 3,4)
|
||||
|
||||
CURRENT_MUTE=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{ print $3 }' | tr -d '[]')
|
||||
CURRENT_MIC_MUTE=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | awk '{ print $3 }' | tr -d '[]')
|
||||
|
||||
vol_inc() {
|
||||
if [[ "$CURRENT_VOL" == "0.0"* ]]; then
|
||||
dunstify "Increasing Volume" "Current Volume: $(echo "$VOL_PRESENT" | cut -c 2)%" -i "audio-volume-high" -t 5000 -r 9991
|
||||
elif [[ "$CURRENT_VOL" == "1.00" ]]; then
|
||||
dunstify "Increasing Volume" "Current Volume: 100%" -i "audio-volume-high" -t 5000 -r 9991
|
||||
else
|
||||
dunstify "Increasing Volume" "Current Volume: ${VOL_PRESENT}%" -i "audio-volume-high" -t 5000 -r 9991
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
vol_dec() {
|
||||
if [[ "$CURRENT_VOL" == "0.0"* ]]; then
|
||||
dunstify "Decreasing Volume" "Current Volume: $(echo "$VOL_PRESENT" | cut -c 2)%" -i "audio-volume-medium" -t 5000 -r 9991
|
||||
elif [[ "$CURRENT_VOL" == "1.00" ]]; then
|
||||
dunstify "Decreasing Volume" "Current Volume: 100%" -i "audio-volume-medium" -t 5000 -r 9991
|
||||
else
|
||||
dunstify "Decreasing Volume" "Current Volume: ${VOL_PRESENT}%" -i "audio-volume-medium" -t 5000 -r 9991
|
||||
fi
|
||||
}
|
||||
|
||||
vol_mute_toggle() {
|
||||
# If "MUTED" doesn't exist, then send notification and toggle mute, otherwise (if "MUTED" DOES exist, send notif and unmute
|
||||
if [ "$CURRENT_MUTE" == "MUTED" ]; then
|
||||
if [[ "$CURRENT_VOL" == "0.0"* ]]; then
|
||||
dunstify "Currently Muting" "Current Volume: $(echo "$VOL_PRESENT" | cut -c 2)%" -i "audio-volume-muted" -t 5000 -r 9991
|
||||
elif [[ "$CURRENT_VOL" == "1.00" ]]; then
|
||||
dunstify "Currently Muting" "Current Volume: 100%" -i "audio-volume-muted" -t 5000 -r 9991
|
||||
else
|
||||
dunstify "Currently Muting" "Current Volume: ${VOL_PRESENT}%" -i "audio-volume-muted" -t 5000 -r 9991
|
||||
fi
|
||||
else
|
||||
if [[ "$CURRENT_VOL" == "0.0"* ]]; then
|
||||
dunstify "Currently Unmuting" "Current Volume: $(echo "$VOL_PRESENT" | cut -c 2)%" -i "audio-volume-medium" -t 5000 -r 9991
|
||||
elif [[ "$CURRENT_VOL" == "1.00" ]]; then
|
||||
dunstify "Currently Unmuting" "Current Volume: 100%" -i "audio-volume-medium" -t 5000 -r 9991
|
||||
else
|
||||
dunstify "Currently Unmuting" "Current Volume: ${VOL_PRESENT}%" -i "audio-volume-medium" -t 5000 -r 9991
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
micInc() {
|
||||
if [[ "$CURRENT_MIC_VOL" == "0.0"* ]]; then
|
||||
dunstify "Increasing Microphone Volume" "Current Volume: $(echo "$MIC_PRESENT" | cut -c 2)%" -i "audio-input-microphone-high" -t 5000 -r 9991
|
||||
elif [[ "$CURRENT_MIC_VOL" == "1.00" ]]; then
|
||||
dunstify "Increasing Microphone Volume" "Current Volume: 100%" -i "audio-input-microphone-high" -t 5000 -r 9991
|
||||
else
|
||||
dunstify "Increasing Microphone Volume" "Current Volume: ${MIC_PRESENT}%" -i "audio-input-microphone-high" -t 5000 -r 9991
|
||||
fi
|
||||
}
|
||||
|
||||
micDec() {
|
||||
if [[ "$CURRENT_MIC_VOL" == "0.0"* ]]; then
|
||||
dunstify "Decreasing Microphone Volume" "Current Volume: $(echo "$MIC_PRESENT" | cut -c 2)%" -i "audio-input-microphone-low" -t 5000 -r 9991
|
||||
elif [[ "$CURRENT_MIC_VOL" == "1.00" ]]; then
|
||||
dunstify "Decreasing Microphone Volume" "Current Volume: 100%" -i "audio-input-microphone-low" -t 5000 -r 9991
|
||||
else
|
||||
dunstify "Decreasing Microphone Volume" "Current Volume: ${MIC_PRESENT}%" -i "audio-input-microphone-low" -t 5000 -r 9991
|
||||
fi
|
||||
}
|
||||
|
||||
mic_mute_toggle() {
|
||||
# If "MUTED" doesn't exist, then send notification and toggle mute, otherwise (if "MUTED" DOES exist, send notif and unmute
|
||||
if [ "$CURRENT_MIC_MUTE" == "MUTED" ]; then
|
||||
if [[ "$CURRENT_MIC_VOL" == "0.0"* ]]; then
|
||||
dunstify "Currently Muting Microphone" "Current Volume: $(echo "$VOL_PRESENT" | cut -c 2)%" -i "audio-input-microphone-muted" -t 5000 -r 9991
|
||||
elif [[ "$CURRENT_MIC_VOL" == "1.00" ]]; then
|
||||
dunstify "Currently Muting Microphone" "Current Volume: 100%" -i "audio-input-microphone-muted" -t 5000 -r 9991
|
||||
else
|
||||
dunstify "Currently Muting Microphone" "Current Volume: ${VOL_PRESENT}%" -i "audio-input-microphone-muted" -t 5000 -r 9991
|
||||
fi
|
||||
else
|
||||
if [[ "$CURRENT_MIC_VOL" == "0.0"* ]]; then
|
||||
dunstify "Currently Unmuting Microphone" "Current Volume: $(echo "$VOL_PRESENT" | cut -c 2)%" -i "audio-input-microphone-high" -t 5000 -r 9991
|
||||
elif [[ "$CURRENT_MIC_VOL" == "1.00" ]]; then
|
||||
dunstify "Currently Unmuting Microphone" "Current Volume: 100%" -i "audio-input-microphone-high" -t 5000 -r 9991
|
||||
else
|
||||
dunstify "Currently Unmuting Microphone" "Current Volume: ${VOL_PRESENT}%" -i "audio-input-microphone-high" -t 5000 -r 9991
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
keybind-func() {
|
||||
echo "$CURRENT_VOL" "$CURRENT_MIC_VOL"
|
||||
}
|
||||
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
inc)
|
||||
vol_inc && exit 0
|
||||
;;
|
||||
|
||||
dec)
|
||||
vol_dec && exit 0
|
||||
;;
|
||||
|
||||
mute-toggle)
|
||||
vol_mute_toggle && exit 0
|
||||
;;
|
||||
|
||||
micInc)
|
||||
micInc && exit 0
|
||||
;;
|
||||
|
||||
micDec)
|
||||
micDec && exit 0
|
||||
;;
|
||||
|
||||
micMute)
|
||||
mic_mute_toggle && exit 0
|
||||
;;
|
||||
|
||||
keybind)
|
||||
keybind-func && exit 0
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
3
archived/notifs/window
Executable file
3
archived/notifs/window
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
dunstify "Switching Window" "Current Window: $1" -t 1000 -r 5000
|
||||
swaymsg workspace number "$1"
|
||||
41
archived/screenshot
Executable file
41
archived/screenshot
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/bin/bash
|
||||
|
||||
## Variables
|
||||
declare -r time=$(date --iso-8601=seconds)
|
||||
|
||||
while (($# > 0)); do
|
||||
case $1 in
|
||||
-s)
|
||||
REGION=yes
|
||||
shift
|
||||
;;
|
||||
|
||||
-c)
|
||||
CURSOR=yes
|
||||
shift
|
||||
;;
|
||||
|
||||
*)
|
||||
if [ -z "$FILENAME" ]; then
|
||||
FILENAME="$1/$time.png"
|
||||
shift
|
||||
else
|
||||
echo "wrong format"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
OPTS=()
|
||||
if [ -n "$REGION" ]; then
|
||||
OPTS+=("-g $(slurp)")
|
||||
|
||||
if [ -n "$CURSOR" ]; then
|
||||
OPTS+=("-c")
|
||||
fi
|
||||
fi
|
||||
|
||||
grim "${OPTS[@]}" "$FILENAME"
|
||||
# https://github.com/bugaevc/wl-clipboard/issues/198 lifesaver
|
||||
wl-copy --type image/png <"$FILENAME"
|
||||
14
archived/sunset
Executable file
14
archived/sunset
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
# Build and Install 'redshift' for wayland: https://github.com/minus7/redshift
|
||||
# You can also use gammastep
|
||||
|
||||
#cd $HOME/.local/bin
|
||||
# killing gammastep if it already exists
|
||||
if [[ $(pgrep gammastep) =~ ^[0-9]+$ ]]
|
||||
then
|
||||
kill $(pgrep gammastep)
|
||||
|
||||
else
|
||||
gammastep -PO 2900
|
||||
fi
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue