in my hyprland.conf, i previously had the line:
bind = $mainMod, T, exec, $terminal
this is almost identical to the default configuration.
the only issue with this is that whenever you launch a terminal, which in my case is alacritty, your working directory gets set to your home directory. this can become quite annoying when you're working in a specific directory and want to quickly launch another terminal in that same directory.
i am somewhat ashamed to admit that i'd put up with this for so long, but at some point one comes to the conclusion that enough is enough.
using a bash script that was definitely not vibe-coded (wink, wink), we can fix this problem:
#!/bin/bash WIN_ID=$(hyprctl activewindow -j | jq -r '.pid') PID=$(pgrep -P "$WIN_ID" -a | grep -E 'bash' | awk '{print $1}' | head -n1) if [ -z "$PID" ]; then PID="$WIN_ID" fi CWD=$(readlink "/proc/$PID/cwd" 2>/dev/null) if [ -n "$CWD" ] && [ -d "$CWD" ]; then alacritty --working-directory "$CWD" else alacritty fi
this script takes the current active window into consideration when launching a terminal. if the current active window is an alacritty instance, then it launches a new alacritty instance with working directory set to the pwd of the previous. otherwise, it simply defaults to launching an alacritty instance with the default working directory.
as with any other random snippets of code you stumble across on the internet, use this at your own risk.
it's not super portable (i.e. for zsh or some non-alacritty terminal), but it's somewhat trivial to modify for own your use case.
now, we simply substitute our previous hyprland.conf line with
bind = $mainMod, T, exec, path/to/alac_lnchr.sh
and blissfully throw our previous frustrations into the wind.