diff --git a/README.md b/README.md index 1cda50e2b..1069e49d0 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,18 @@ # kelen's dotfiles -**Warning**: Don’t blindly use my settings unless you know what that entails. Use at your own risk! - -I'm working with Arch Linux and Debian. +***Warning***: I'm working with **Arch Linux** and **Debian.** Don’t blindly use my settings unless you know what that entails. Use at your own risk! +--- ## Styles **"Keep it simple stupid."** ![image](./assets/desktop.png) ![image](./assets/windows.png) +> ri • cing /ry-sing/ +> +> - Making visual improvements and customization to your desktop and/or phone that can simplify your desktop environment but (generally) are completely pointless. +> - Wasting time because aesthetic. + ## Installing ```console @@ -35,7 +39,6 @@ A concise guide to archlinux in Chinese https://arch.icekylin.online/ - btop - conky - dust -- eww - fastfetch - fcitx5 with rime-ice - gBar @@ -58,7 +61,7 @@ A concise guide to archlinux in Chinese https://arch.icekylin.online/ ### PKGBUILDs Research packages that are maintained by me or archived for geophysics. - cuda-multiversion -- intel-oneapi-hpckit (include oneapi-basekit) +- intel-oneapi-hpckit (with oneapi-basekit) - madagascar - mathematica - matlab @@ -79,6 +82,7 @@ You can find a list of the geophysical codes that I am currently utilizing for m - logout - maintenace - pytorch cuda test +- screenrecord - screenshot - volume control - wayland session lock @@ -87,9 +91,9 @@ You can find a list of the geophysical codes that I am currently utilizing for m Please check in [dotfile/wallpaper](./wallpaper/). ### Window manager -- Awesomewm -- dwm -- Hyprland +- dwm (Xorg) +- GNOME (DE on workstation) +- Hyprland (Wayland) ## License The code is available under the [MIT license][license]. diff --git a/config/btop/btop.conf b/config/btop/btop.conf index 7bef0a30e..e88353468 100644 --- a/config/btop/btop.conf +++ b/config/btop/btop.conf @@ -50,7 +50,7 @@ graph_symbol_net = "default" graph_symbol_proc = "default" #* Manually set which boxes to show. Available values are "cpu mem net proc" and "gpu0" through "gpu5", separate values with whitespace. -shown_boxes = "cpu mem net proc gpu0" +shown_boxes = "cpu mem net proc" #* Update time in milliseconds, recommended 2000 ms or above for better sample times for graphs. update_ms = 300 diff --git a/config/hypr/configs/animation.conf b/config/hypr/configs/animation.conf index 4ff64c85a..9cb02e3db 100644 --- a/config/hypr/configs/animation.conf +++ b/config/hypr/configs/animation.conf @@ -17,6 +17,9 @@ animations { bezier = gnome, 0, 0.85, 0.3, 1 bezier = funky, 0.46, 0.35, -0.2, 1.2 bezier = ease, 0.165, 0.84, 0.44, 1 + bezier = winIn, 0.1, 1.1, 0.1, 1.1 + bezier = winOut, 0.3, -0.3, 0, 1 + bezier = liner, 1, 1, 1, 1 # animation=NAME,ONOFF,SPEED,CURVE,STYLE @@ -36,15 +39,15 @@ animations { # ↳ workspaces - styles: slide, slidevert, fade, slidefade, slidefadevert # ↳ specialWorkspace - styles: same as workspaces - animation = windows, 1, 5, md3_standard - animation = windowsIn, 1, 7, default, popin 80% - animation = windowsOut, 1, 7, default, popin 80% - animation = windowsMove, 1, 7, default, popin 80% + animation = windows, 1, 5, md3_standard, slide + animation = windowsIn, 1, 7, winIn, slide + animation = windowsOut, 1, 7, winOut, slide + animation = windowsMove, 1, 7, ease, slide - animation = fade, 1, 3, default + animation = fade, 1, 10, default - animation = border, 1, 10, default - animation = borderangle, 1, 8, default + animation = border, 1, 3, liner + animation = borderangle, 1, 15, liner, loop animation = workspaces, 1, 6, ease, slidefadevert 20% animation = specialWorkspace, 1, 6, overshot, slide diff --git a/config/hypr/configs/env.conf b/config/hypr/configs/env.conf index 9316107b7..0c38beeed 100644 --- a/config/hypr/configs/env.conf +++ b/config/hypr/configs/env.conf @@ -1,6 +1,7 @@ ## Display Environment ## Some default env vars. env = GTK_THEME, +env = GDK_SCALE,1 env = XCURSOR_THEME, env = XCURSOR_SIZE,24 env = WLR_DRM_DEVICES,/dev/dri/card1:/dev/dri/card0 @@ -21,5 +22,5 @@ env = QT_AUTO_SCREEN_SCALE_FACTOR,1 # QT根据显示器的像素密度 env = QT_QPA_PLATFORM,wayland:xcb # QT 应用程序使用 Wayland 后端 env = QT_WAYLAND_DISABLE_WINDOWDECORATION,1 #禁用QT应用程序上的窗户装饰 env = QT_QPA_PLATFORMTHEME,qt5ct #基于 QT 的应用程序从 qt5ct 中选择主题 - +env = QT_AUTO_SCREEN_SCALE_FACTOR,1 diff --git a/config/hypr/configs/input.conf b/config/hypr/configs/input.conf index abb003c83..b67a8a615 100644 --- a/config/hypr/configs/input.conf +++ b/config/hypr/configs/input.conf @@ -37,5 +37,6 @@ device:epic-mouse-v1 { ## 手势 gestures { # See https://wiki.hyprland.org/Configuring/Variables/ for more - workspace_swipe = off + workspace_swipe = true + workspace_swipe_fingers = 3 } diff --git a/config/hypr/configs/keybinds.conf b/config/hypr/configs/keybinds.conf index e07ff1e72..20b79b6d2 100644 --- a/config/hypr/configs/keybinds.conf +++ b/config/hypr/configs/keybinds.conf @@ -5,14 +5,14 @@ $terminal = kitty $filemanager = pcmanfm # Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more -bind = $mainMod, Q, killactive, -bind = $mainMod, C, killactive, +bind = $mainMod, Q, ~/.config/hypr/scripts/hyprkill, +bind = $mainMod, C, ~/.config/hypr/scripts/hyprkill, bind = SUPERSHIFT, Q, exit, bind = $mainMod, F, fullscreen,0 bind = SUPERSHIFT, F, fullscreen, 1 bind = $mainMod, SPACE, togglefloating, -bind = $mainMod, P, pseudo, # dwindle -bind = $mainMod, J, togglesplit, # dwindle +# bind = $mainMod, P, pseudo, # dwindle +# bind = $mainMod, J, togglesplit, # dwindle bind = SUPERSHIFT, R, exec, hyprctl reload, @@ -28,18 +28,23 @@ bind = $mainMod, V, exec, cliphist list | rofi -dmenu | cliphist decod bind = SUPERSHIFT, RETURN, layoutmsg, swapwithmaster,master bind = SUPERSHIFT, C, exec, sh ~/.config/scripts/hyprPicker.sh bind = CTRLALT, K, exec, sh ~/.config/rofi/powermenu/type-4/powermenu.sh +bind = SUPERALT, G, exec, ~/.config/hypr/scripts/gamemode.sh # disable hypr effects for gamemode bind = CTRLALT, L, exec, ~/.config/scripts/wayland_session_lock bind = CTRLALT, A, exec, ~/.config/scripts/screenshot area bind = $mainMod, O, exec, ~/.config/scripts/killprocess bind = $mainMod, N, exec, ~/.config/scripts/wallpaper.sh -bind = , XF86PowerOff, exec, ~/.config/scripts/power-menu/powermenu.sh -bind = , XF86AudioMute, exec, ~/.config/hypr/scripts/volume mute -bind = , XF86AudioLowerVolume, exec, ~/.config/hypr/scripts/volume down -bind = , XF86AudioRaiseVolume, exec, ~/.config/hypr/scripts/volume up -bind = , XF86AudioMicMute, exec, pactl set-source-mute @DEFAULT_SOURCE@ toggle -bindle = , XF86MonBrightnessUp, exec, ~/.config/hypr/scripts/brightness up # increase screen brightness -bindle = , XF86MonBrightnessDown, exec, ~/.config/hypr/scripts/brightness down # decrease screen brightnes +bind = , XF86PowerOff, exec, ~/.config/scripts/power-menu/powermenu.sh +bind = , XF86AudioMute, exec, ~/.config/hypr/scripts/volume mute +bind = , XF86AudioLowerVolume, exec, ~/.config/hypr/scripts/volume down +bind = , XF86AudioRaiseVolume, exec, ~/.config/hypr/scripts/volume up +bind = , XF86AudioMicMute, exec, pactl set-source-mute @DEFAULT_SOURCE@ toggle +bindle = , XF86MonBrightnessUp, exec, ~/.config/hypr/scripts/brightness up # increase screen brightness +bindle = , XF86MonBrightnessDown, exec, ~/.config/hypr/scripts/brightness down # decrease screen brightnes +bindl = , XF86AudioPlay, exec, playerctl play-pause +bindl = , XF86AudioPause, exec, playerctl play-pause +bindl = , XF86AudioNext, exec, playerctl next +bindl = , XF86AudioPrev, exec, playerctl previous ## MPC controls. Requires mpc and mpd to be installed. bind = SHIFTALT, right, exec, mpc next @@ -126,3 +131,9 @@ bind = $mainMod, mouse_up, workspace, e-1 # Move/resize windows with mainMod + LMB/RMB and dragging bindm = $mainMod, mouse:272, movewindow bindm = $mainMod, mouse:273, resizewindow + +# Create an empty “passthrough” submap then hyprland will ignore your keybinds and passes them on to the vm. +bind = CTRL Alt_L, V, submap, passthrough +submap = passthrough +bind = CTRL Alt_L, V, submap, reset +submap = reset \ No newline at end of file diff --git a/config/hypr/configs/winrules.conf b/config/hypr/configs/winrules.conf index 91242ae82..953271a9e 100644 --- a/config/hypr/configs/winrules.conf +++ b/config/hypr/configs/winrules.conf @@ -14,18 +14,7 @@ # windowrule = opacity 1.0 override 0.5 override,^(kitty)$ # set opacity to 1.0 active and 0.5 inactive for kitty # windowrule = rounding 10,^(kitty)$ # set rounding to 10 for kitty -# Float Necessary Windows -windowrule=float, Rofi -windowrule=float,avucontrol -windowrulev2 = float,class:^()$,title:^(Picture in picture)$ -windowrulev2 = float,class:^(brave)$,title:^(Save File)$ -windowrulev2 = float,class:^(brave)$,title:^(Open File)$ -windowrulev2 = float,class:^(LibreWolf)$,title:^(Picture-in-Picture)$ -windowrulev2 = float,class:^(blueman-manager)$ -windowrulev2 = float,class:^(org.twosheds.iwgtk)$ -windowrulev2 = float,class:^(blueberry.py)$ -windowrulev2 = float,class:^(xdg-desktop-portal-gtk)$ -windowrulev2 = float,class:^(geeqie)$ + # Increase the opacity windowrule=opacity 0.92,Thunar @@ -79,6 +68,8 @@ windowrulev2 = opacity 0.80 0.80,class:^(steam)$ windowrulev2 = opacity 0.80 0.80,class:^(steamwebhelper)$ windowrulev2 = opacity 0.80 0.80,class:^(Spotify)$ windowrulev2 = opacity 0.80 0.80,class:^(Code)$ +windowrulev2 = opacity 0.80 0.80,class:^(code-url-handler)$ +windowrulev2 = opacity 0.80 0.80,class:^(kitty)$ windowrulev2 = opacity 0.80 0.80,class:^(thunar)$ windowrulev2 = opacity 0.80 0.80,class:^(file-roller)$ windowrulev2 = opacity 0.80 0.80,class:^(nwg-look)$ @@ -87,8 +78,15 @@ windowrulev2 = opacity 0.80 0.80,class:^(discord)$ #Discord-Electron windowrulev2 = opacity 0.80 0.80,class:^(WebCord)$ #WebCord-Electron windowrulev2 = opacity 0.80 0.70,class:^(pavucontrol)$ windowrulev2 = opacity 0.80 0.70,class:^(org.kde.polkit-kde-authentication-agent-1)$ +windowrulev2 = opacity 0.80 0.70,class:^(polkit-gnome-authentication-agent-1)$ windowrulev2 = opacity 0.80 0.80,class:^(org.telegram.desktop)$ +windowrulev2 = opacity 0.80 0.70,class:^(blueman-manager)$ +windowrulev2 = opacity 0.80 0.70,class:^(nm-applet)$ +windowrulev2 = opacity 0.80 0.70,class:^(nm-connection-editor)$ +# Float Necessary Windows +windowrule=float, Rofi +windowrule=float,avucontrol # Position windowrulev2 = float,class:^(org.kde.polkit-kde-authentication-agent-1)$ windowrulev2 = float,class:^(pavucontrol)$ @@ -108,6 +106,29 @@ windowrulev2 = float,title:^(Open File)$ windowrulev2 = float,title:^(branchdialog)$ windowrulev2 = float,title:^(Confirm to replace files) windowrulev2 = float,title:^(File Operation Progress) +windowrulev2 = float,class:^()$,title:^(Picture in picture)$ +windowrulev2 = float,class:^(brave)$,title:^(Save File)$ +windowrulev2 = float,class:^(brave)$,title:^(Open File)$ +windowrulev2 = float,class:^(LibreWolf)$,title:^(Picture-in-Picture)$ +windowrulev2 = float,class:^(blueman-manager)$ +windowrulev2 = float,class:^(org.twosheds.iwgtk)$ +windowrulev2 = float,class:^(blueberry.py)$ +windowrulev2 = float,class:^(xdg-desktop-portal-gtk)$ +windowrulev2 = float,class:^(geeqie)$ +windowrulev2 = float,class:^(qt5ct)$ +windowrulev2 = float,class:^(nwg-look)$ +windowrulev2 = float,class:^(org.kde.ark)$ +windowrulev2 = float,class:^(Signal)$ #Signal-Gtk +windowrulev2 = float,class:^(com.github.rafostar.Clapper)$ #Clapper-Gtk +windowrulev2 = float,class:^(app.drey.Warp)$ #Warp-Gtk +windowrulev2 = float,class:^(net.davidotek.pupgui2)$ #ProtonUp-Qt +windowrulev2 = float,class:^(yad)$ #Protontricks-Gtk +windowrulev2 = float,class:^(eog)$ #Imageviewer-Gtk +windowrulev2 = float,class:^(io.gitlab.theevilskeleton.Upscaler)$ #Upscaler-Gtk +windowrulev2 = float,class:^(nm-applet)$ +windowrulev2 = float,class:^(nm-connection-editor)$ +windowrulev2 = float,class:^(org.kde.polkit-kde-authentication-agent-1)$ + windowrulev2 = move 75 44%,title:^(Volume Control)$ diff --git a/config/hypr/scripts/gamemode.sh b/config/hypr/scripts/gamemode.sh new file mode 100755 index 000000000..f519399bf --- /dev/null +++ b/config/hypr/scripts/gamemode.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh +HYPRGAMEMODE=$(hyprctl getoption animations:enabled | sed -n '2p' | awk '{print $2}') +if [ $HYPRGAMEMODE = 1 ] ; then + hyprctl --batch "\ + keyword animations:enabled 0;\ + keyword decoration:drop_shadow 0;\ + keyword decoration:blur:enabled 0;\ + keyword general:gaps_in 0;\ + keyword general:gaps_out 0;\ + keyword general:border_size 1;\ + keyword decoration:rounding 0" + exit +fi +hyprctl reload \ No newline at end of file diff --git a/config/hypr/scripts/hyprkill b/config/hypr/scripts/hyprkill new file mode 100755 index 000000000..62a79872c --- /dev/null +++ b/config/hypr/scripts/hyprkill @@ -0,0 +1,5 @@ +if [ "$(hyprctl activewindow -j | jq -r ".class")" = "Steam" ]; then + xdotool getactivewindow windowunmap +else + hyprctl dispatch killactive "" +fi diff --git a/config/scripts/batterynofify.sh b/config/scripts/batterynofify.sh new file mode 100755 index 000000000..fdf4cd350 --- /dev/null +++ b/config/scripts/batterynofify.sh @@ -0,0 +1,270 @@ +#!/bin/bash + +ConfDir="${XDG_CONFIG_HOME:-$HOME/.config}" +batterynotify_conf=$ConfDir/hypr/hyprdots-ctl/batterynotify.conf +config_info() { +cat << EOF + +Edit $batterynotify_conf for options. + + STATUS THRESHOLD INTERVAL + Full $battery_full_threshold $notify Minutes + Critical $battery_critical_threshold $timer Seconds then '$execute_critical' + Low $battery_low_threshold $interval Percent then '$execute_low' + Unplug $unplug_charger_threshold $interval Percent then '$execute_unplug' + + Charging: $execute_charging + Discharging: $execute_discharging +EOF +} + +is_laptop() { # Check if the system is a laptop + if grep -q "Battery" /sys/class/power_supply/BAT*/type; then + return 0 # It's a laptop + else + echo "Cannot Detect a Battery. If this seems an error please report an issue to https://github.com/prasanthrangan/hyprdots." + exit 0 # It's not a laptop + fi +} +fn_verbose () { +if $verbose; then +cat << VERBOSE +============================================= + Battery Status: $battery_status + Battery Percentage: $battery_percentage +============================================= +VERBOSE +fi +} +fn_notify () { # Send notification + + notify-send -a "Power" $1 -u $2 "$3" "$4" -p # Call the notify-send command with the provided arguments \$1 is the flags \$2 is the urgency \$3 is the title \$4 is the message +} +fn_percentage () { + if [[ "$battery_percentage" -ge "$unplug_charger_threshold" ]] && [[ "$battery_status" != "Discharging" ]] && [[ "$battery_status" != "Full" ]] && (( (battery_percentage - last_notified_percentage) >= $interval )); then if $verbose; then echo "Prompt:UNPLUG: $battery_unplug_threshold $battery_status $battery_percentage" ; fi + fn_notify "-t 5000 " "CRITICAL" "Battery Charged" "Battery is at $battery_percentage%. You can unplug the charger!" + last_notified_percentage=$battery_percentage + elif [[ "$battery_percentage" -le "$battery_critical_threshold" ]]; then + count=$(( timer > $mnt ? timer : $mnt )) # reset count + while [ $count -gt 0 ] && [[ $battery_status == "Discharging"* ]]; do + for battery in /sys/class/power_supply/BAT*; do battery_status=$(< "$battery/status") ; done + if [[ $battery_status != "Discharging" ]] ; then break ; fi + fn_notify "-t 5000 -r 69 " "CRITICAL" "Battery Critically Low" "$battery_percentage% is critically low. Device will execute $execute_critical in $((count/60)):$((count%60)) ." + count=$((count-1)) + sleep 1 + done + [ $count -eq 0 ] && fn_action + elif [[ "$battery_percentage" -le "$battery_low_threshold" ]] && [[ "$battery_status" == "Discharging" ]] && (( (last_notified_percentage - battery_percentage) >= $interval )); then if $verbose; then echo "Prompt:LOW: $battery_low_threshold $battery_status $battery_percentage" ; fi + fn_notify "-t 5000 " "CRITICAL" "Battery Low" "Battery is at $battery_percentage%. Connect the charger." + last_notified_percentage=$battery_percentage + fi +} +fn_action () { #handles the $execute_critical command #? This is special as it will try to execute always + count=$(( timer > $mnt ? timer : $mnt )) # reset count + nohup $execute_critical +} + +fn_status () { +if [[ $battery_percentage -ge $battery_full_threshold ]] && [[ "$battery_status" != *"Discharging"* ]]; then echo "Full and $battery_status" + battery_status="Full" ;fi +case "$battery_status" in # Handle the power supply status + "Discharging") if $verbose; then echo "Case:$battery_status Level: $battery_percentage" ;fi + if [[ "$prev_status" != "Discharging" ]] || [[ "$prev_status" == "Full" ]] ; then + prev_status=$battery_status + urgency=$([[ $battery_percentage -le "$battery_low_threshold" ]] && echo "CRITICAL" || echo "NORMAL") + fn_notify "-t 5000 -r 54321 " "$urgency" "Charger Plug OUT" "Battery is at $battery_percentage%." + $execute_discharging + fi + fn_percentage + ;; + "Not"*|"Charging") if $verbose; then echo "Case:$battery_status Level: $battery_percentage" ;fi + if [[ "$prev_status" == "Discharging" ]] || [[ "$prev_status" == "Not"* ]] ; then + prev_status=$battery_status + count=$(( timer > $mnt ? timer : $mnt )) # reset count + urgency=$([[ "$battery_percentage" -ge $unplug_charger_threshold ]] && echo "CRITICAL" || echo "NORMAL") + fn_notify "-t 5000 -r 54321 " "$urgency" "Charger Plug In" "Battery is at $battery_percentage%." + $execute_charging + fi + fn_percentage + ;; + "Full") if $verbose; then echo "Case:$battery_status Level: $battery_percentage" ;fi + if [[ $battery_status != "Discharging" ]]; then + now=$(date +%s) + if [[ "$prev_status" == *"harging"* ]] || ((now - lt >= $((notify*60)) )); then + fn_notify "-t 5000 -r 54321" "CRITICAL" "Battery Full" "Please unplug your Charger" + prev_status=$battery_status lt=$now + $execute_charging + fi + fi + ;; + *) + if [[ ! -f "/tmp/hyprdots.batterynotify.status.fallback.$battery_status-$$" ]]; then + echo "Status: '==>> "$battery_status" <<==' Script on Fallback mode,Unknown power supply status.Please copy this line and raise an issue to the Github Repo.Also run 'ls /tmp/hyprdots.batterynotify' to see the list of lock files.*" + touch "/tmp/hyprdots.batterynotify.status.fallback.$battery_status-$$" + fi + fn_percentage + ;; + esac +} + +get_battery_info() { #? Might change this if we can get an effective way to parse dbus. + total_percentage=0 battery_count=0 + for battery in /sys/class/power_supply/BAT*; do + battery_status=$(<"$battery/status") battery_percentage=$(<"$battery/capacity") + total_percentage=$((total_percentage + battery_percentage)) + battery_count=$((battery_count + 1)) + done + battery_percentage=$((total_percentage / battery_count)) #? For Multiple Battery +} + +fn_status_change () { # Handle when status changes +get_battery_info + # Add these two lines at the beginning of the function + local executed_low=false + local executed_unplug=false + + + if [ "$battery_status" != "$last_battery_status" ] || [ "$battery_percentage" != "$last_battery_percentage" ]; then + last_battery_status=$battery_status + last_battery_percentage=$battery_percentage # Check if battery status or percentage has changed + fn_verbose + fn_percentage + + if [[ "$battery_percentage" -le "$battery_low_threshold" ]] && ! $executed_low; then $execute_low + executed_low=true executed_unplug=false + fi + if [[ "$battery_percentage" -ge "$unplug_charger_threshold" ]] && ! $executed_unplug; then $execute_unplug + executed_unplug=true executed_low=false + fi + + if $undock; then fn_status echo yes ; fi + fi +} + +resume_processes() { for pid in $pids ; do if [ "$pid" -ne "$current_pid" ] ; then kill -CONT $pid ; notify-send -a "Battery Notify" -t 2000 -r 9889 -u "CRITICAL" "Debugging ENDED, Resuming Regular Process" ; fi ; done } + +main() { # Main function + if is_laptop; then +rm -fr /tmp/hyprdots.batterynotify* # Cleaning the lock file +battery_full_threshold=${battery_full_threshold:-100} +battery_critical_threshold=${battery_critical_threshold:-5} +unplug_charger_threshold=${unplug_charger_threshold:-80} +battery_low_threshold=${battery_low_threshold:-20} +timer=${timer:-120} +notify=${notify:-1140} +interval=${interval:-5} +execute_critical=${execute_critical:-"systemctl suspend"} +execute_low=${execute_low:-} +execute_unplug=${execute_unplug:-} + +config_info +if $verbose; then for line in "Verbose Mode is ON..." "" "" "" "" ; do echo $line ; done; +current_pid=$$ +pids=$(pgrep -f "/bin/bash $HOME/.config/hypr/scripts/batterynotify.sh" ) +for pid in $pids ; do if [ "$pid" -ne $current_pid ] ;then kill -STOP "$pid" ;notify-send -a "Battery Notify" -t 2000 -r 9889 -u "CRITICAL" "Debugging STARTED, Pausing Regular Process" ;fi ; done ; trap resume_processes SIGINT ; fi + get_battery_info # initiate the function + last_notified_percentage=$battery_percentage + prev_status=$battery_status + +dbus-monitor --system "type='signal',interface='org.freedesktop.DBus.Properties',path='$(upower -e | grep battery)'" 2> /dev/null | while read -r battery_status_change; do fn_status_change ; done + fi +} + +verbose=false undock=false +if [ ! -f "$batterynotify_conf" ]; then + mkdir -p "$(dirname "$batterynotify_conf")" + touch "$batterynotify_conf" + echo "[CREATED] $batterynotify_conf" + echo " + #? Full battery threshold (default: 100%) +battery_full_threshold=100 + #? Critical battery threshold (default: 10%) +battery_critical_threshold=10 + #? Low battery threshold (default: 20%) +battery_low_threshold=20 + #? Unplug charger threshold (default: 80%) +unplug_charger_threshold=80 + #? Countdown timer before executing execute_critical (default: 120 seconds) +timer=120 + #? Notify interval for Battery Full Status (default: 1140 mins/ 1 day) +notify=1140 + #? Notify interval on LOW and UNPLUG Status (default: 5%) +interval=5 + #? Shows Battery Plug In/Out/Full Notification +undock=false + #? Command/script to execute at minimum unplug_charger_threshold +execute_unplug=\"\" + #? Command/script to execute at maximum battery_low_threshold +execute_low=\"\" + #? Command/script to execute if battery on critical threshold (default: systemctl suspend) +execute_critical=\"systemctl suspend\" + #? Command/script to execute when battery is discharging, Required undock=true +execute_discharging=\"\" + #? Command/script to execute when battery is charging, Required undock=true +execute_charging=\"\" +" > "$batterynotify_conf" +fi + +source "$batterynotify_conf" + case "$1" in + --modify) + EDITOR="${EDITOR:-code}" #* Use VS Code as the default editor + echo -e "[Editor]: $EDITOR \n To change editor, run 'export EDITOR=prefered-editor' \n[Modifying]: $batterynotify_conf \nPress Any Key if done editing" + #kitty -o allow_remote_control=yes -o listen_on=unix:/tmp/mykitty $(which $EDITOR) "$batterynotify_conf" > /dev/null 2>&1 & + kitty "$(which $EDITOR)" "$batterynotify_conf" > /dev/null 2>&1 & + LAST_MD5SUM=$(md5sum "$batterynotify_conf") + while true; do CURRENT_MD5SUM=$(md5sum "$batterynotify_conf") + if [ "$CURRENT_MD5SUM" != "$LAST_MD5SUM" ]; then + notify-send "Config Changed: Needs reboot or restart $0" + LAST_MD5SUM="$CURRENT_MD5SUM" + fi ; read -t 2 -n 1 > /dev/null && break #? loop every 2 seconds + done + exit 0 + ;; + --info) + config_info + exit 0 + ;; + --reset) + rm -r "$batterynotify_conf" + echo "[RESET] Batterynotify configuration" + exit 0 + ;; + --verbose) + verbose=true + ;; + -h|--help) + cat << HELP +Usage: $0 [options] + +[--modify] Modify configuration file +[--info] Display configuration information +[--reset] Reset configuration +[--verbose] Debugging mode +[-h|--help] This Message +HELP + exit 0 + ;; + esac + +mnc=2 mxc=50 mnl=10 mxl=80 mnu=50 mxu=100 mnt=60 mxt=1000 mnf=80 mxf=100 mnn=1 mxn=1140 mni=1 mxi=10 #Defaults Ranges +check_range() { + local var=$1 min=$2 max=$3 error_message=$4 + if [[ $var =~ ^[0-9]+$ ]] && (( var >= min && var <= max )); then + var=$var ; shift 2 + else + echo "$1 ERROR: $error_message must be $min - $max." >&2 ; exit 1 + fi +} + +check_range "$battery_full_threshold" $mnf $mxf "Full Threshold" +check_range "$battery_critical_threshold" $mnc $mxc "Critical Threshold" +check_range "$battery_low_threshold" $mnl $mxl "Low Threshold" +check_range "$unplug_charger_threshold" $mnu $mxu "Unplug Threshold" +check_range "$timer" $mnt $mxt "Timer" +check_range "$notify" $mnn $mxn "Notify" +check_range "$interval" $mni $mxi "Interval" + + trap resume_processes SIGINT + +main \ No newline at end of file diff --git a/install.sh b/install.sh index 617ff8a06..345f6fba8 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/usr/bin/env bash # Define a function which rename a `target` file to `target.backup` if the file # exists and if it's a 'real' file, ie not a symlink