From ba1f63c6c5137dc9a7c8550ff2f1f052377a0091 Mon Sep 17 00:00:00 2001 From: spl3g Date: Tue, 15 Apr 2025 22:44:04 +0300 Subject: feat(hyprland): cleanup scripts --- .../attachments/hypr-scripts/battery-level.sh | 22 -------- .../homeModules/attachments/hypr-scripts/hshot | 45 ---------------- .../homeModules/attachments/hypr-scripts/hshot.sh | 45 ++++++++++++++++ .../homeModules/attachments/hypr-scripts/kill | 7 --- .../attachments/hypr-scripts/rofi-modes | 20 ------- .../attachments/hypr-scripts/switch-sink.py | 49 +++++++++++++++++ .../attachments/hypr-scripts/switch_sink.py | 41 --------------- .../attachments/hypr-scripts/toggle-vpn.sh | 61 ++++++++++++++++++++++ .../attachments/hypr-scripts/toggle_vpn.sh | 61 ---------------------- 9 files changed, 155 insertions(+), 196 deletions(-) delete mode 100755 home-manager/homeModules/attachments/hypr-scripts/battery-level.sh delete mode 100755 home-manager/homeModules/attachments/hypr-scripts/hshot create mode 100755 home-manager/homeModules/attachments/hypr-scripts/hshot.sh delete mode 100755 home-manager/homeModules/attachments/hypr-scripts/kill delete mode 100755 home-manager/homeModules/attachments/hypr-scripts/rofi-modes create mode 100755 home-manager/homeModules/attachments/hypr-scripts/switch-sink.py delete mode 100755 home-manager/homeModules/attachments/hypr-scripts/switch_sink.py create mode 100755 home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh delete mode 100755 home-manager/homeModules/attachments/hypr-scripts/toggle_vpn.sh diff --git a/home-manager/homeModules/attachments/hypr-scripts/battery-level.sh b/home-manager/homeModules/attachments/hypr-scripts/battery-level.sh deleted file mode 100755 index cc2d5cd..0000000 --- a/home-manager/homeModules/attachments/hypr-scripts/battery-level.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -while true; do - # Check the battery level and charging status - battery_info=$(acpi -b) - - # Extract the battery level from the output of `acpi` - battery_level=$(echo $battery_info | grep -o "[0-9]*%" | sed "s/%//") - - # Check if the laptop is charging - if [[ $battery_info == *"Charging"* ]]; then - # If the laptop is charging, do nothing - : - else - # If the battery level is less than 15%, send a notification - if [ "$battery_level" -lt 15 ]; then - notify-send "Battery Low" "Battery level is at $battery_level%. Charge your laptop." - fi - fi - - # Sleep for 5 minutes before checking the battery level again - sleep 300 -done diff --git a/home-manager/homeModules/attachments/hypr-scripts/hshot b/home-manager/homeModules/attachments/hypr-scripts/hshot deleted file mode 100755 index 0d02b9c..0000000 --- a/home-manager/homeModules/attachments/hypr-scripts/hshot +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - -declare -a cmd - -usage() { - echo -e "-m | monitor\n-s | slurp\n-w | active window\n-c | add copy" -} - -monitor() { - cmd=("grim -o \"\$(hyprctl -j monitors | jq -r '.[] | select(.focused) | .name')\"") -} - -slurp() { - cmd=("grim -g \"\$(slurp)\"") -} - -window() { - cmd=("grim -g \"\$(hyprctl activewindow -j | jq -j '\"\(.at | .[0]),\(.at | .[1]) \(.size | .[0])x\(.size | .[1])\"')\"") -} - -copy() { - if [[ -n ${cmd[0]} ]]; then - cmd+=("- | wl-copy") - else - usage - fi -} - -while getopts ":mswc" opt; do - case ${opt} in - m) monitor;; - s) slurp;; - w) window;; - c) copy;; - *) usage - exit 1;; - esac -done - -if [[ -z $1 ]]; then - usage - exit 1 -fi - -bash -c "${cmd[*]}" diff --git a/home-manager/homeModules/attachments/hypr-scripts/hshot.sh b/home-manager/homeModules/attachments/hypr-scripts/hshot.sh new file mode 100755 index 0000000..0d02b9c --- /dev/null +++ b/home-manager/homeModules/attachments/hypr-scripts/hshot.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +declare -a cmd + +usage() { + echo -e "-m | monitor\n-s | slurp\n-w | active window\n-c | add copy" +} + +monitor() { + cmd=("grim -o \"\$(hyprctl -j monitors | jq -r '.[] | select(.focused) | .name')\"") +} + +slurp() { + cmd=("grim -g \"\$(slurp)\"") +} + +window() { + cmd=("grim -g \"\$(hyprctl activewindow -j | jq -j '\"\(.at | .[0]),\(.at | .[1]) \(.size | .[0])x\(.size | .[1])\"')\"") +} + +copy() { + if [[ -n ${cmd[0]} ]]; then + cmd+=("- | wl-copy") + else + usage + fi +} + +while getopts ":mswc" opt; do + case ${opt} in + m) monitor;; + s) slurp;; + w) window;; + c) copy;; + *) usage + exit 1;; + esac +done + +if [[ -z $1 ]]; then + usage + exit 1 +fi + +bash -c "${cmd[*]}" diff --git a/home-manager/homeModules/attachments/hypr-scripts/kill b/home-manager/homeModules/attachments/hypr-scripts/kill deleted file mode 100755 index 40ab4a9..0000000 --- a/home-manager/homeModules/attachments/hypr-scripts/kill +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -if [[ $(hyprctl activewindow -j | jq -r '.class') =~ (kitty) ]]; then - kill $(hyprctl activewindow -j | jq '.pid') -s 9 -else - hyprctl dispatch killactive -fi diff --git a/home-manager/homeModules/attachments/hypr-scripts/rofi-modes b/home-manager/homeModules/attachments/hypr-scripts/rofi-modes deleted file mode 100755 index 2d52802..0000000 --- a/home-manager/homeModules/attachments/hypr-scripts/rofi-modes +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -case $(echo -e "clipboard\nemoji\ncalc" | rofi -dmenu) in - emoji) arg=emoji;; - calc) arg=calc;; - clipboard) cliphist list | rofi -dmenu -display-columns 2 | cliphist decode | wl-copy - exit;; - bitwarden) if [[ $XDG_BACKEND == "wayland" ]]; then - typer=wtype - clip=wl-copy - else - typer=xdotool - clip=xclip - fi - rofi-rbw --typer $typer --clip $clip - exit;; - *)exit;; -esac - -rofi -modi $arg -show $arg diff --git a/home-manager/homeModules/attachments/hypr-scripts/switch-sink.py b/home-manager/homeModules/attachments/hypr-scripts/switch-sink.py new file mode 100755 index 0000000..a043238 --- /dev/null +++ b/home-manager/homeModules/attachments/hypr-scripts/switch-sink.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import subprocess + +status = subprocess.run(["wpctl", "status"], stdout=subprocess.PIPE).stdout.decode('utf-8') +status_lines = status.split('\n') +sink_line = 0 +sinks = [] +sink_names = [] + +# Get sink line +for i in range(len(status_lines) - 1): + if 'Sinks:' in status_lines[i]: + sink_line = i + 1 + break + +# Find unused sinks +for line in status_lines[sink_line:]: + if line == ' │ ': + break + line = line.split('.') + nums = line[0] + name = line[1] + end_name = line[1].index('[') + sink = nums[8:] + if nums[4] == '*': + continue + + sinks.append(sink) + sink_names.append(name[:end_name].strip()) + +if (len(sinks) == 0): + subprocess.run(["notify-send", "Pipewire sink", "No sinks to switch to"]) + exit(0) + +selected_sink = subprocess.run(["rofi", "-dmenu"], input="\n".join(sink_names), capture_output=True, text=True).stdout[:-1] + +if len(selected_sink) == 0: + exit(0) + +try: + next_sink = sink_names.index(selected_sink) +except Exception: + subprocess.run(["notify-send", "Pipewire sink", "Sink not found"]) + exit(1) + +subprocess.run(["wpctl", "set-default", sinks[next_sink]]) + +subprocess.run(["notify-send", "Pipewire sink", "Selected " + selected_sink]) diff --git a/home-manager/homeModules/attachments/hypr-scripts/switch_sink.py b/home-manager/homeModules/attachments/hypr-scripts/switch_sink.py deleted file mode 100755 index ff554ae..0000000 --- a/home-manager/homeModules/attachments/hypr-scripts/switch_sink.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python3 - -import subprocess - -status = subprocess.run(["wpctl", "status"], stdout=subprocess.PIPE).stdout.decode('utf-8') -status_lines = status.split('\n') -sink_line = 0 -selected_sink = 0 -sinks = [] -sink_names = [] - -# Get sink line -for i in range(len(status_lines) - 1): - if 'Sinks:' in status_lines[i]: - sink_line = i + 1 - break - -# Find unused sinks -for line in status_lines[sink_line:]: - if line == ' │ ': - break - line = line.split('.') - nums = line[0] - name = line[1] - end_name = line[1].index('[') - sink = nums[8:] - if nums[4] == '*': - selected_sink = sink - - sinks.append(sink) - sink_names.append(name[:end_name].strip()) - -next_sink = sinks.index(selected_sink) + 1 -if next_sink == len(sinks): - next_sink = 0 - -next_sink_name = sink_names[next_sink] -subprocess.run(["wpctl", "set-default", sinks[next_sink]]) - -subprocess.run(["notify-send", "Pipewire sink", "Selected " + next_sink_name]) - diff --git a/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh b/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh new file mode 100755 index 0000000..a712a1e --- /dev/null +++ b/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +ROFI_CMD="rofi -dmenu -theme-str listview{enabled:false;} -p" +LOCAL_STORAGE=~/.local/share/toggle +V2RAYA_URL="http://localhost:2017" + +set_token() { + login=$(echo "" | $ROFI_CMD "Enter login > ") + password=$(echo "" | $ROFI_CMD "Enter password > " -theme-str 'entry {enabled: false;}') + response=$(curl -s -X POST \ + "${V2RAYA_URL}/api/login" \ + -d "{\"username\": \"${login}\", \"password\": \"${password}\"}") + + code=$(echo $response | jq -r ".code") + echo "${response}" | jq ".data.token" -r > "${LOCAL_STORAGE}/token" +} + +get_status() { + token=$1 + response=$(curl -s -X GET \ + "${V2RAYA_URL}/api/touch" \ + -H "Authorization: ${token}") + echo $response | jq ".data.running" -r +} + +toggle() { + token=$1 + method=$2 + response=$(curl -s -X ${method} \ + "${V2RAYA_URL}/api/v2ray" \ + -H "Authorization: ${token}") + code=$(echo $response | jq ".code" -r) + echo $response | jq ".data.running" -r +} + +if [[ ! -d "${LOCAL_STORAGE}" ]]; then + mkdir "${LOCAL_STORAGE}" +fi + +if [[ ! -e "${LOCAL_STORAGE}/token" ]]; then + touch "${LOCAL_STORAGE}/token" +fi + +TOKEN=$(cat "${LOCAL_STORAGE}/token") +if [[ -z "${TOKEN}" ]]; then + set_token + TOKEN=$(cat "${LOCAL_STORAGE}/token") +fi + +STATUS=$(get_status $TOKEN) +if [[ $STATUS == "true" ]]; then + NEW_STATUS=$(toggle $TOKEN DELETE) +else + NEW_STATUS=$(toggle $TOKEN POST) +fi + +if [[ $NEW_STATUS == "null" ]]; then + set_token +fi + +notify-send v2rayA "running: ${NEW_STATUS}" diff --git a/home-manager/homeModules/attachments/hypr-scripts/toggle_vpn.sh b/home-manager/homeModules/attachments/hypr-scripts/toggle_vpn.sh deleted file mode 100755 index a712a1e..0000000 --- a/home-manager/homeModules/attachments/hypr-scripts/toggle_vpn.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/sh - -ROFI_CMD="rofi -dmenu -theme-str listview{enabled:false;} -p" -LOCAL_STORAGE=~/.local/share/toggle -V2RAYA_URL="http://localhost:2017" - -set_token() { - login=$(echo "" | $ROFI_CMD "Enter login > ") - password=$(echo "" | $ROFI_CMD "Enter password > " -theme-str 'entry {enabled: false;}') - response=$(curl -s -X POST \ - "${V2RAYA_URL}/api/login" \ - -d "{\"username\": \"${login}\", \"password\": \"${password}\"}") - - code=$(echo $response | jq -r ".code") - echo "${response}" | jq ".data.token" -r > "${LOCAL_STORAGE}/token" -} - -get_status() { - token=$1 - response=$(curl -s -X GET \ - "${V2RAYA_URL}/api/touch" \ - -H "Authorization: ${token}") - echo $response | jq ".data.running" -r -} - -toggle() { - token=$1 - method=$2 - response=$(curl -s -X ${method} \ - "${V2RAYA_URL}/api/v2ray" \ - -H "Authorization: ${token}") - code=$(echo $response | jq ".code" -r) - echo $response | jq ".data.running" -r -} - -if [[ ! -d "${LOCAL_STORAGE}" ]]; then - mkdir "${LOCAL_STORAGE}" -fi - -if [[ ! -e "${LOCAL_STORAGE}/token" ]]; then - touch "${LOCAL_STORAGE}/token" -fi - -TOKEN=$(cat "${LOCAL_STORAGE}/token") -if [[ -z "${TOKEN}" ]]; then - set_token - TOKEN=$(cat "${LOCAL_STORAGE}/token") -fi - -STATUS=$(get_status $TOKEN) -if [[ $STATUS == "true" ]]; then - NEW_STATUS=$(toggle $TOKEN DELETE) -else - NEW_STATUS=$(toggle $TOKEN POST) -fi - -if [[ $NEW_STATUS == "null" ]]; then - set_token -fi - -notify-send v2rayA "running: ${NEW_STATUS}" -- cgit v1.2.3