Last active
December 8, 2020 23:52
-
-
Save seandlg/2b194cd422f8c037d7f58292d5fd561e to your computer and use it in GitHub Desktop.
Spawn Alacritty instance with the same cwd as the currently focused Alacritty instance (if there is one). Built for swaywm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Check that jq and swaymsg are installed | |
if ! command -v jq &> /dev/null || ! command -v swaymsg &> /dev/null; then | |
echo "jq and swaymsg are required for this script to work!" | |
exit 1 | |
fi | |
# Get the app_id of the currently focused window | |
APP=$(swaymsg -t get_tree | jq -r '.. | select(.focused == true)? | .app_id') | |
# Spawn alacritty with the correct cwd if it is currently focused, else spawn it at $HOME | |
if [[ $APP == Alacritty ]]; then | |
PID=$(swaymsg -t get_tree | jq -r '.. | select(.focused == true)? | .pid') | |
CWD=$(readlink -e /proc/$(ps -ef | awk -v pid="$PID" '$3==pid && $8=="/bin/zsh" {print $2}')/cwd) | |
alacritty --working-directory=$CWD | |
else | |
alacritty | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment