diff options
Diffstat (limited to 'modules/homeModules/attachments/hypr-scripts')
5 files changed, 222 insertions, 0 deletions
diff --git a/modules/homeModules/attachments/hypr-scripts/bitwarden-float.sh b/modules/homeModules/attachments/hypr-scripts/bitwarden-float.sh new file mode 100755 index 0000000..7edd5f2 --- /dev/null +++ b/modules/homeModules/attachments/hypr-scripts/bitwarden-float.sh @@ -0,0 +1,21 @@ +windowtitlev2() { + IFS=',' read -r -a args <<< "$1" + args[0]="${args[0]#*>>}" + + if [[ ${args[1]} =~ "Extension: (Bitwarden Password Manager)" ]]; then + hyprctl --batch "\ + dispatch setfloating address:0x${args[0]}; \ + dispatch resizewindowpixel exact 20% 50%, address:0x${args[0]}; \ + dispatch centerwindow; \ + " + fi +} + +handle() { + case $1 in + windowtitlev2\>*) windowtitlev2 "$1" ;; + esac +} + +socat -U - UNIX-CONNECT:"/$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" \ + | while read -r line; do handle "$line"; done diff --git a/modules/homeModules/attachments/hypr-scripts/hshot.sh b/modules/homeModules/attachments/hypr-scripts/hshot.sh new file mode 100755 index 0000000..0d02b9c --- /dev/null +++ b/modules/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/modules/homeModules/attachments/hypr-scripts/switch-sink.py b/modules/homeModules/attachments/hypr-scripts/switch-sink.py new file mode 100755 index 0000000..aa7eec1 --- /dev/null +++ b/modules/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[2:].strip() + 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/modules/homeModules/attachments/hypr-scripts/toggle-tg.sh b/modules/homeModules/attachments/hypr-scripts/toggle-tg.sh new file mode 100755 index 0000000..44ed52d --- /dev/null +++ b/modules/homeModules/attachments/hypr-scripts/toggle-tg.sh @@ -0,0 +1,14 @@ +#!/bin/sh +TG_CLASS=org.telegram.desktop + +tg_workspace=$(hyprctl clients -j | jq -e ".[] | select((.class | contains(\"${TG_CLASS}\"))) | .workspace.id") +if [[ -z $tg_workspace ]]; then + telegram-desktop +elif [[ $tg_workspace -eq $(hyprctl activeworkspace -j | jq -e '.id') ]]; then + hyprctl dispatch pin class:$TG_CLASS + hyprctl dispatch movetoworkspacesilent special:magic,class:$TG_CLASS +else + hyprctl dispatch movetoworkspacesilent +0,class:$TG_CLASS + hyprctl dispatch pin class:$TG_CLASS + hyprctl dispatch focuswindow +fi diff --git a/modules/homeModules/attachments/hypr-scripts/toggle-vpn.sh b/modules/homeModules/attachments/hypr-scripts/toggle-vpn.sh new file mode 100755 index 0000000..8775f39 --- /dev/null +++ b/modules/homeModules/attachments/hypr-scripts/toggle-vpn.sh @@ -0,0 +1,93 @@ +#!/bin/sh + +ROFI_CMD="rofi -dmenu -theme-str listview{enabled:false;} -p" +LOCAL_STORAGE=~/.local/share/toggle +TMP_PATH=/tmp/vpn-status +V2RAYA_URL="http://localhost:2017" + +DBUS_INTERFACE="com.vpn_status" +DBUS_MEMBER="StatusChanged" + +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 +} + +check_status() { + case $(cat $TMP_PATH) in + true) + output='{"text": ""}' + ;; + *) + output='{"text": ""}' + ;; + esac + echo $output | jq --unbuffered --compact-output +} + + +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 [[ $1 == "waybar" ]]; then + echo $STATUS > $TMP_PATH + check_status + + dbus-monitor --profile "interface='${DBUS_INTERFACE}',member='${DBUS_MEMBER}'" | + while read -r line; do + check_status + done +else + if [[ $STATUS == "true" ]]; then + NEW_STATUS=$(toggle $TOKEN DELETE) + else + NEW_STATUS=$(toggle $TOKEN POST) + fi + + if [[ $NEW_STATUS == "null" ]]; then + set_token + exit 0 + fi + + echo $NEW_STATUS > $TMP_PATH + dbus-send --type=signal / "${DBUS_INTERFACE}.${DBUS_MEMBER}" + + notify-send v2rayA "running: ${NEW_STATUS}" +fi |
