diff options
| Commit | dce4fccf08255afaaa218e2e21e53e45e7e1c582 (patch) | |
|---|---|---|
| Author | 2025-03-28 19:44:31 +0200 | |
| Committer | 2025-03-28 19:44:31 +0200 | |
| Files | 8514b9290d3c44b728b287f574b64116a111b1ca | |
| .files-dce4fccf08255afaaa218e2e21e53e45e7e1c582.tar .files-dce4fccf08255afaaa218e2e21e53e45e7e1c582.tar.gz .files-dce4fccf08255afaaa218e2e21e53e45e7e1c582.zip | ||
| Parent | 6b71263670e0924294610b537f0ac17292ce2f19 (diff) | |
feat: Add scripts
13 files changed, 324 insertions, 12 deletions
| -rw-r--r-- | .config/jgmenu/append.csv | 8 | ||||
| -rw-r--r-- | .config/openbox/autostart | 2 | ||||
| -rw-r--r-- | .config/openbox/rc.xml | 8 | ||||
| -rw-r--r-- | .config/tint2/tint2rc | 2 | ||||
| -rwxr-xr-x | .scripts/autostart | 36 | ||||
| -rwxr-xr-x | .scripts/battery-status | 65 | ||||
| -rwxr-xr-x | .scripts/brightness-control | 28 | ||||
| -rwxr-xr-x | .scripts/dunst-toggler-applet | 27 | ||||
| -rwxr-xr-x | .scripts/lock | 50 | ||||
| -rwxr-xr-x | .scripts/on-logout | 18 | ||||
| -rwxr-xr-x | .scripts/plumb | 81 | ||||
| -rwxr-xr-x | .scripts/toggle-desktop | 7 | ||||
| -rw-r--r-- | .sxhkdrc | 4 |
diff --git a/.config/jgmenu/append.csv b/.config/jgmenu/append.csv index 2bbcf64..d33d0ea 100644 --- a/.config/jgmenu/append.csv +++ b/.config/jgmenu/append.csv @@ -1,7 +1,7 @@ ^sep() -Log Out,~/.a/sys/on-wm-logout.sh && loginctl terminate-user $USER,system-log-out -Lock Now,~/.a/sys/lock.sh now,system-lock-screen +Log Out,~/.scripts/on-logout && loginctl terminate-user $USER,system-log-out +Lock Now,~/.scripts/lock now,system-lock-screen ^sep() Suspend,systemctl suspend,system-suspend -Reboot,~/.a/sys/on-wm-logout.sh && systemctl reboot,system-reboot -Shutdown,~/.a/sys/on-wm-logout.sh && systemctl poweroff,system-shutdown +Reboot,~/.scripts/on-logout && systemctl reboot,system-reboot +Shutdown,~/.scripts/on-logout && systemctl poweroff,system-shutdown diff --git a/.config/openbox/autostart b/.config/openbox/autostart index 14ec8dc..eb863cf 100644 --- a/.config/openbox/autostart +++ b/.config/openbox/autostart @@ -2,4 +2,4 @@ # These commands are ran when an Openbox X Session is started. # -~/.a/sys/on-wm-session.sh +~/.scripts/autostart diff --git a/.config/openbox/rc.xml b/.config/openbox/rc.xml index 97d8a43..9bb5907 100644 --- a/.config/openbox/rc.xml +++ b/.config/openbox/rc.xml @@ -222,7 +222,7 @@ <enabled>false</enabled> <name>Brightness up</name> </startupnotify> - <command>~/.a/brightness-control.sh +</command> + <command>~/.scripts/brightness-control +</command> </action> </keybind> <keybind key="XF86MonBrightnessDown"> @@ -231,7 +231,7 @@ <enabled>false</enabled> <name>Brightness down</name> </startupnotify> - <command>~/.a/brightness-control.sh -</command> + <command>~/.scripts/brightness-control -</command> </action> </keybind> <keybind key="W-d"> @@ -240,7 +240,7 @@ <enabled>false</enabled> <name>Toggle desktop</name> </startupnotify> - <command>~/.a/toggle-desktop.sh</command> + <command>~/.scripts/toggle-desktop</command> </action> </keybind> <keybind key="W-L"> @@ -249,7 +249,7 @@ <enabled>false</enabled> <name>Lock screen</name> </startupnotify> - <command>~/.a/sys/lock.sh now</command> + <command>~/.scripts/lock now</command> </action> </keybind> <keybind key="Print"> diff --git a/.config/tint2/tint2rc b/.config/tint2/tint2rc index 2efc229..13e2ecd 100644 --- a/.config/tint2/tint2rc +++ b/.config/tint2/tint2rc @@ -255,7 +255,7 @@ execp_icon_h = 0 #------------------------------------- # Executor 2 execp = new -execp_command = /home/kamen/.a/battery-status.sh +execp_command = /home/kamen/.scripts/battery-status execp_interval = 10 execp_has_icon = 0 execp_cache_icon = 1 diff --git a/.scripts/autostart b/.scripts/autostart new file mode 100755 index 0000000..df2513c --- /dev/null +++ b/.scripts/autostart @@ -0,0 +1,36 @@ +#!/bin/bash + +device="desktop" + +#[ $device = "desktop" ] && xrandr --output HDMI-A-0 --mode 1920x1080 --rate 100 --primary + +xhost +local: +~/.fehbg & # wallpaper +# lead & # hot corners, this is MageJohn's fork: https://github.com/MageJohn/lead +xcape -e 'Super_L=Super_L|P' & # used for the "windows" menu +rm -rf ~/.tmp/* + +tint2 & # taskbar +picom & # compositor + +if [[ $device == "desktop" ]]; then + xset m 1 1 # disable mouse acceleration (not a very proper way to do it, I know) +fi + +if [[ $device == "laptop" ]]; then + # while :; do if grep -Fq "closed" /proc/acpi/button/lid/LID0/state; then ~/.a/sys/lock.sh suspend && sleep 3; fi; sleep 0.5; done & # lock screen on lid closing; you'll also need to uncomment the HandleLidSwitch variable and assign to it "lock" (HandleLidSwitch=lock) inside /etc/systemd/logind.conf + libinput-gestures-setup start & # start gestures + blueberry & # bluetooth app +fi + +pnmixer & # volume applet +nm-applet & # network applet +~/.scripts/dunst-toggler-applet & # notification toggler + +flameshot & # screenshot utility +redshift-gtk & # screen color temperature changer +copyq & # clipboard manager +barrier & # share mouse and keyboard between devices +nextcloud & # cloud/source control + +firefox-bin & diff --git a/.scripts/battery-status b/.scripts/battery-status new file mode 100755 index 0000000..6e51bcb --- /dev/null +++ b/.scripts/battery-status @@ -0,0 +1,65 @@ +#!/bin/bash +exit + +# Check for dependencies +for comm in upower awk; do + command -v upower >/dev/null 2>&1 || (echo "Error, missing command dependencies: $comm" && exit) +done + +# Prepare battery informatoin +for bat in BAT0 BAT1; do + upower -i "/org/freedesktop/UPower/devices/battery_$bat" > "/tmp/$bat" + [ "$(awk '/native-path/{print $2}' "/tmp/$bat")" = '(null)' ] && continue + + bat_state="$(awk '/state/{print substr($2, 1, 1)}' "/tmp/$bat")" + if [ $bat_state = 'c' ]; then bat_power_ind='' + elif [ $bat_state = 'd' ]; then bat_power_ind='' + else bat_power_ind='' + fi + + bat_per="$(awk '/percentage/{print strtonum($2)}' "/tmp/$bat")" + # bat_per=$((bat_per * 5 / 4 - 25)) # compensation for failing battery + + [ $bat_state = 'd' ] \ + && bat_time="$(awk '/time to empty/{print $4 substr($5, 1, 1)}' "/tmp/$bat")" \ + || bat_time="$(awk '/time to full/ {print $4 substr($5, 1, 1)}' "/tmp/$bat")" + + echo -n " $bat_power_ind ${bat_per}% $bat_time" + + # + # Notifications + # + + command -v notify-send >/dev/null 2>&1 || exit + [ ! -e "/tmp/bat_notif$bat" ] && touch "/tmp/bat_notif$bat" + bat_notif="$(cat "/tmp/bat_notif$bat")" + + + # Notify when battery is charged to 80% + if [ $bat_state = 'c' ]; then + if [ "$bat_notif" != 80 ] && [ $bat_per -ge 80 ]; then + notify-send -u normal -i battery-charging -t 999999 "$bat at 80%" + echo 80 > "/tmp/bat_notif$bat" + fi + + # Notify when battery discharges to 5%, 10%, 15% and 20% + elif [ $bat_state = 'd' ]; then + for per in 5 10 15 20; do + if [ "$bat_notif" = $per ]; then + break + elif [ $bat_per -le $per ]; then + notify-send -u critical -i battery-low -t 999999 "$bat at ${per}%" + echo $per > "/tmp/bat_notif$bat" + break + fi + done + + # Notify when battery is full + else + if [ "$bat_notif" != 100 ]; then + notify-send -u normal -i battery-full -t 999999 "$bat fully charged!" + echo 100 > "/tmp/bat_notif$bat" + fi + fi +done +echo diff --git a/.scripts/brightness-control b/.scripts/brightness-control new file mode 100755 index 0000000..3aa2139 --- /dev/null +++ b/.scripts/brightness-control @@ -0,0 +1,28 @@ +#!/bin/bash + +if [ -z "$@" ] || ([ "$1" != "+" ] && [ "$1" != "-" ]); then + echo "Expected + or - as argument!" + exit 1 +fi + +# Percentage change depending on brightness +info=$(brightnessctl -m i | cut -d , -f 4) +info=${info::-1} + +change=5 +if [ "$info" -ge 70 ]; then + change=10 +fi + +# Brightness change +if [ "$1" == "+" ]; then + brightnessctl -q set "+${change}%" +elif [ "$info" -gt 5 ]; then # don't allow brightness to decrease to 0% + brightnessctl -q set "${change}%-" +fi + +# Notification for brightness +info=$(brightnessctl -m i) +perbright=$(echo $info | cut -d , -f 4) +notify-send "$(echo $info | cut -d , -f 1) +Brightness: $perbright" -t 1000 -h int:value:$perbright -h string:x-canonical-private-synchronous:anything -h string:x-canonical-private-synchronous:anything diff --git a/.scripts/dunst-toggler-applet b/.scripts/dunst-toggler-applet new file mode 100755 index 0000000..a4061a9 --- /dev/null +++ b/.scripts/dunst-toggler-applet @@ -0,0 +1,27 @@ +#!/bin/bash + +function update { + prev_status="" + while :; do + curr_status="$(dunstctl is-paused)" + + if [ "$curr_status" != "$prev_status" ]; then + prev_status=$curr_status + + if [ "$curr_status" == "true" ]; then + echo icon:/usr/share/icons/tabler-icon-bell-off.png + echo tooltip:Notifications OFF + else + echo icon:/usr/share/icons/tabler-icon-bell.png + echo tooltip:Notifications ON + fi + fi + + sleep 0.2 + done +} + +update | \ +yad --notification \ + --listen \ + --command="dunstctl set-paused toggle" diff --git a/.scripts/lock b/.scripts/lock new file mode 100755 index 0000000..f2e1699 --- /dev/null +++ b/.scripts/lock @@ -0,0 +1,50 @@ +#!/bin/bash +# Suspend is managed by elogind +# Refer to ~/.b/etc/elogind/logind.conf +# ~/.b/etc/elogind/system-sleep/run-lock.sh + +# ++=================================++ +# || Actions before and after unlock || +# ++=================================++ + +before_locking () { + # Disables dunst, my notification daemon, so I don't see notification on lock screen + # https://github.com/dunst-project/dunst/issues/697 + # https://wiki.archlinux.org/title/Dunst#Disable_dunst_temporarily + dunstctl set-paused true + + touch ~/.tmp/locksh-locked +} + +before_suspend () { + # Keep track of time when machine is suspended, as well as how long it has been up for + uptime >> ~/.scripts/suspend-history +} + +when_unlocked () { + dunstctl set-paused false # Enables my notification daemon + + # Resets programs, in case resolution changes + ~/.fehbg # wallpaper + + rm ~/.tmp/locksh-locked +} + +# ++============================++ +# || Lock if not locked already || +# ++============================++ + +if [ ! -f ~/.tmp/locksh-locked ]; then + # The first line of i3lock arguments uses standard arguments, while the rest of the lines are i3lock-color ones + # If you want to use i3lock, remove those lines (and the \ at the end) + # But I highly advise you to use i3lock-color, it's amazing: https://github.com/Raymo111/i3lock-color + before_locking && \ + i3lock -f -c d49408 -i ~/.scripts/lockscreen.png -n \ + -k --indicator --keylayout 1 --radius 95 --pass-volume-keys \ + --date-str='%d.%m.%Y' --verif-text='Verifying…' --wrong-text='Wrong!' --noinput-text='No Input!' \ + --insidever-color d47408cc --ringver-color d47408 --insidewrong-color c35b5bcc --ringwrong-color c35b5b \ + --layout-color ffeede --time-color ffeede --date-color ffeede --greeter-color ffeede --verif-color ffeede --wrong-color ffeede \ + ; when_unlocked +else + echo "Not locking, lockfile exists!" +fi diff --git a/.scripts/on-logout b/.scripts/on-logout new file mode 100755 index 0000000..8be0a81 --- /dev/null +++ b/.scripts/on-logout @@ -0,0 +1,18 @@ +#!/bin/bash + +# Gracefully close certain programs +grace=() +gui=(brave firefox-bin) + +for app in $grace; do + timeout 5 pkill -TERM $app +done + +for app in $gui; do + wmctrl -c $app + while [ -n "$(pidof $app)" ]; do + sleep 1 + done +done + +exit 0 diff --git a/.scripts/plumb b/.scripts/plumb new file mode 100755 index 0000000..6f42d7c --- /dev/null +++ b/.scripts/plumb @@ -0,0 +1,81 @@ +#/bin/bash + + +# +# Get selection text and go to window directory +# + +selection="$(xclip -o)" + +# Copied from https://odysee.com/@Luke:7/plumbing-in-linux-la-plan-9-from-bell:e +pid=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3) +pid1=$(pstree -lpA "$pid" | tail -n 1 | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g') +cd "$(readlink /proc/"$pid1"/cwd)" + +wname="$(cat /proc/"$pid"/comm)" +if [ $wname == "terminator" ]; then + xdotool key Control+Alt+Page_Up + sleep 0.1 + cd "$(cat /tmp/plumb-cwd)" +fi + +# +# Create jgmenu menu +# + +menu="" +if [ -z "$1" ]; then + function matches() { + echo "$selection" | grep "$1" >/dev/null 2>&1 + } + + # Settings, 1 for include in menu, 0 for don't include + plan9=0 + runInTerminal=1 + + # -= Plan 9 functions =- + [ $plan9 -eq 1 ] && menu+="Send,echo 2\nResize,echo 3\nMove,echo 4\n" + + # -= Run =- + if [ $runInTerminal -eq 1 ]; then + [ $wname == "terminator" ] && [ $plan9 -ne 1 ] && menu+="Send,echo 2\n" + [ $wname == "terminator" ] && menu+="Exec,echo 5\n" \ + || menu+="Exec,echo 6\n" + fi + #matches "[[:alnum:]]*" && menu+="Run,echo 2\n" + #matches ".*\.cpp" && menu+="Build and run,echo 2\n" +fi + +# +# Execution menu option +# + +if [ -z "$1" ]; then + action=$(echo -ne "$menu" | jgmenu --at-pointer --simple --config-file="$HOME/.config/jgmenu/jgmenusimplerc") +else + action="1" +fi + +case "$action" in + 1) xdg-open "$selection" + ;; + 2) xdotool type --delay 0 "$selection" + ;; + 3) xdotool keydown Alt + xdotool mousedown 3 + xdotool keyup Alt + ;; + 4) xdotool keydown Alt + xdotool mousedown 1 + xdotool keyup Alt + ;; + 5) terminator --new-tab --command="zsh $selection" & + disown + ;; + 6) terminator --command="$selection" & + disown + ;; + *) + notify-send "Bad action!" + ;; +esac diff --git a/.scripts/toggle-desktop b/.scripts/toggle-desktop new file mode 100755 index 0000000..b5906bc --- /dev/null +++ b/.scripts/toggle-desktop @@ -0,0 +1,7 @@ +#!/bin/bash + +if xprop -root _NET_SHOWING_DESKTOP | egrep '= 1' > /dev/null; then + wmctrl -k off +else + wmctrl -k on +fi @@ -1,10 +1,10 @@ # Hyper_L + Middle mouse button mod4 + button2 - $HOME/.a/plumb.sh 1 + $HOME/.scripts/plumb 1 # Hyper_L + Right mouse button mod4 + button3 - $HOME/.a/plumb.sh + $HOME/.scripts/plumb mod4 + button1 find-cursor -s 90 -d 6 -l 1 -w 200 -f -o 1 |
