From 6607c0c568db759aecc679d5678d0615d19abc3b Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Mon, 12 Feb 2024 11:58:21 +0100 Subject: [PATCH] feat: session/desktop detection --- README.md | 1 + hyprfreeze | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60c248b..8aec8f3 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Hyprfreeze is available in [AUR](https://aur.archlinux.org/packages/hyprfreeze-g - a compatible window manager (`hyprland` or `sway`) to get the PID of the active window - `jq` to parse json - `psmisc` contains 'pstree' which is required to list child processes +- Systemd for the `loginctl` utility ### Optional - [`hyprprop`](https://github.com/vilari-mickopf/hyprprop) to get the pid of a window by selecting it with your mouse ### Highly Recommended diff --git a/hyprfreeze b/hyprfreeze index 3858dc9..7d05a3e 100755 --- a/hyprfreeze +++ b/hyprfreeze @@ -101,8 +101,23 @@ function getPidByProp() { debugPrint "PID by prop: $PID" } +function detectEnvironment() { + local Type + local Desktop + eval "$(loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Type -p Desktop)" + [ -z "$Type" ] && echo "Could not determine session type via \`loginctl\`." && exit 1 + [ -z "$Desktop" ] && echo "Could not determine desktop environment via \`loginctl\`." && exit 1 + SESSION=$Type + DESKTOP=$Desktop +} + function printInfo() { - debugPrint "Printing process info...\n" + debugPrint "Printing environment info..." + echo -e "$(tput bold)Session type:$(tput sgr0) $SESSION" + echo -e "$(tput bold)Desktop:$(tput sgr0) $DESKTOP" + echo "" + + debugPrint "Printing process info..." echo -e "$(tput bold)Process tree:$(tput sgr0)" ps -p "$PID" 2>/dev/null && pstree -p "$PID" @@ -226,4 +241,6 @@ DEBUG=0 args "$@" +detectEnvironment + main