dotfiles/awesome/scripts/launch_alacritty.sh

18 lines
674 B
Bash
Raw Normal View History

#!/bin/bash
2023-09-17 21:31:30 +02:00
RUNNING_SSH=false
CHILD_PID=$(pgrep -P $1)
2023-09-17 21:31:30 +02:00
[[ $(ps -p $CHILD_PID -o comm=) == "ssh" ]] && RUNNING_SSH=true
2023-09-17 21:31:30 +02:00
GRAND_CHILD_PID=$(pgrep -P $CHILD_PID)
[[ $? == 0 ]] && [[ $(ps -p $GRAND_CHILD_PID -o comm=) == "ssh" ]] && RUNNING_SSH=true && CHILD_PID=$GRAND_CHILD_PID
2023-09-17 21:31:30 +02:00
if [ $RUNNING_SSH == true ]; then
CLIENT=$(ps -p $CHILD_PID -o args --no-headers | awk '{ print $2 }')
PORT=$(ss -tnpa | grep ssh | grep "pid=$CHILD_PID" | awk '{ print $4 }' | grep -o '[0-9]*$')
alacritty -e ssh $CLIENT -t "cd \"\$(readlink -e /proc/\$(cat /tmp/ssh_session_$PORT)/cwd)\"; zsh --login"
else
alacritty --working-directory "$(readlink -e /proc/$CHILD_PID/cwd)"
fi