refactor(mouse-actions): use absolute paths

This commit is contained in:
toast 2025-11-09 21:26:22 +09:00
parent 1c99f9d063
commit e9f087deed
6 changed files with 42 additions and 72 deletions

View file

@ -1,9 +1,9 @@
{ pkgs, ... }:
let
script = pkgs.writeShellScriptBin "autoclick-action" ''
{
package = pkgs.writeShellScriptBin "autoclick-action" ''
if ! command -v ydotool >/dev/null 2>&1; then
notify-send -r 120000 "Autoclicker" "This tool requires ydotool to be installed on your system."
${pkgs.libnotify}/bin/notify-send -r 120000 "Autoclicker" "This tool requires ydotool to be installed on your system."
fi
AUTOCLICK_FILE="/run/user/$(id -u)/autoclick"
@ -15,11 +15,11 @@ let
current=$(cat "$AUTOCLICK_FILE")
if [ "$current" = "0" ]; then
echo "1" > "$AUTOCLICK_FILE"
notify-send -r 120000 "Autoclicker" "Stopped"
${pkgs.libnotify}/bin/notify-send -r 120000 "Autoclicker" "Stopped"
exit 0
else
echo "0" > "$AUTOCLICK_FILE"
notify-send -r 120000 "Autoclicker" "Started"
${pkgs.libnotify}/bin/notify-send -r 120000 "Autoclicker" "Started"
fi
while :; do
@ -31,10 +31,4 @@ let
fi
done
'';
in
{
package = pkgs.symlinkJoin {
name = "autoclick-action";
paths = [ script pkgs.libnotify ];
};
}

View file

@ -1,13 +1,7 @@
{ pkgs, ... }:
let
script = pkgs.writeShellScriptBin "deafen-action" ''
hyprctl dispatch sendshortcut CTRL+SHIFT, D, 'class:^(vesktop)$'
'';
in
{
package = pkgs.symlinkJoin {
name = "deafen-action";
paths = [ script pkgs.hyprland ];
};
package = pkgs.writeShellScriptBin "deafen-action" ''
${pkgs.hyprland}/bin/hyprctl dispatch sendshortcut CTRL+SHIFT, D, 'class:^(vesktop)$'
'';
}

View file

@ -1,18 +1,12 @@
{ pkgs, ... }:
let
script = pkgs.writeShellScriptBin "flick-action" ''
{
package = pkgs.writeShellScriptBin "flick-action" ''
if ! command -v ydotool >/dev/null 2>&1; then
notify-send -r 120000 "Flick" "This tool requires ydotool to be installed on your system."
${pkgs.libnotify}/bin/notify-send -r 120000 "Flick" "This tool requires ydotool to be installed on your system."
fi
ydotool mousemove -- 800 0
sleep 0.03
ydotool mousemove -- -800 0
'';
in
{
package = pkgs.symlinkJoin {
name = "autoclick-action";
paths = [ script pkgs.libnotify ];
};
}

View file

@ -1,27 +1,27 @@
{ pkgs, ... }:
let
script = pkgs.writeShellScriptBin "sober-lag-action" ''
roblox_pid=$(ps aux | grep "[s]ober --" | sort -k3 -nr | head -n 1 | awk '{print $2}')
if [ -z "$roblox_pid" ]; then
notify-send "sober-lag.sh" "Sober is not running."
exit 1
fi
pgid=$(ps -o pgid= -p "$roblox_pid" | xargs)
if [ -z "$pgid" ]; then
notify-send "sober-lag.sh" "Could not find PGID for PID $roblox_pid."
exit 1
fi
kill -STOP -- "-$pgid"
sleep 0.2
kill -CONT -- "-$pgid"
'';
in
{
package = pkgs.symlinkJoin {
name = "sober-lag-action";
paths = [ script pkgs.procps pkgs.gawk pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.libnotify ];
};
package = pkgs.writeShellScriptBin "sober-lag-action" ''
roblox_pid=$(${pkgs.procps}/bin/ps aux \
| ${pkgs.gnugrep}/bin/grep "[s]ober --" \
| ${pkgs.coreutils}/bin/sort -k3 -nr \
| ${pkgs.coreutils}/bin/head -n 1 \
| ${pkgs.gawk}/bin/awk '{print $2}')
if [ -z "$roblox_pid" ]; then
${pkgs.libnotify}/bin/notify-send "sober-lag.sh" "Sober is not running."
exit 1
fi
pgid=$(${pkgs.procps}/bin/ps -o pgid= -p "$roblox_pid" | ${pkgs.coreutils}/bin/xargs)
if [ -z "$pgid" ]; then
${pkgs.libnotify}/bin/notify-send "sober-lag.sh" "Could not find PGID for PID $roblox_pid."
exit 1
fi
${pkgs.coreutils}/bin/kill -STOP -- "-$pgid"
${pkgs.coreutils}/bin/sleep 0.2
${pkgs.coreutils}/bin/kill -CONT -- "-$pgid"
'';
}

View file

@ -1,7 +1,7 @@
{ pkgs }:
let
script = pkgs.writeShellScriptBin "cycle-mouse-action" ''
{
package = pkgs.writeShellScriptBin "cycle-mouse-action" ''
STATE_FILE="$HOME/.config/mouse-actions/state"
mkdir -p "$(dirname "$STATE_FILE")"
@ -21,10 +21,4 @@ let
echo "$NEW_ACTION" > "$STATE_FILE.tmp"
mv "$STATE_FILE.tmp" "$STATE_FILE"
'';
in
{
package = pkgs.symlinkJoin {
name = "cycle-mouse-action";
paths = [ script pkgs.libnotify ];
};
}

View file

@ -1,7 +1,7 @@
{ pkgs, actions }:
let
script = pkgs.writeShellScriptBin "run-mouse-action" ''
{
package = pkgs.writeShellScriptBin "run-mouse-action" ''
STATE_FILE="$HOME/.config/mouse-actions/state"
if [ ! -f "$STATE_FILE" ]; then
@ -12,23 +12,17 @@ let
case "$ACTION_NAME" in
"deafen")
systemd-run --user ${actions.deafen.package}/bin/deafen-action
${pkgs.systemd}/bin/systemd-run --user ${actions.deafen.package}/bin/deafen-action
;;
"sober-lag")
systemd-run --user ${actions.sober-lag.package}/bin/sober-lag-action
${pkgs.systemd}/bin/systemd-run --user ${actions.sober-lag.package}/bin/sober-lag-action
;;
"autoclick")
systemd-run --user ${actions.autoclick.package}/bin/autoclick-action
${pkgs.systemd}/bin/systemd-run --user ${actions.autoclick.package}/bin/autoclick-action
;;
"flick")
systemd-run --user ${actions.flick.package}/bin/flick-action
${pkgs.systemd}/bin/systemd-run --user ${actions.flick.package}/bin/flick-action
;;
esac
'';
in
{
package = pkgs.symlinkJoin {
name = "run-mouse-action";
paths = [ script pkgs.systemd ];
};
}