2022-07-28 17:32:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
CHILD_PID=$(pgrep -P $1)
|
2023-09-17 20:50:48 +02:00
|
|
|
GRAND_CHILD_PID=$(pgrep -P $CHILD_PID)
|
|
|
|
|
|
|
|
if [ $? == 0 ]
|
|
|
|
then
|
|
|
|
PROCESS=$(ps -p $GRAND_CHILD_PID -o comm=)
|
|
|
|
COMMAND=$(ps -p $GRAND_CHILD_PID -o args --no-headers)
|
|
|
|
if [ $PROCESS == "ssh" ]
|
|
|
|
then
|
|
|
|
PORT=$(ss -tnpa | grep ssh | grep "pid=$GRAND_CHILD_PID" | awk '{ print $4 }' | grep -o '[0-9]*$')
|
2023-09-17 21:08:00 +02:00
|
|
|
alacritty -e $COMMAND -t "cd \"\$(readlink -e /proc/\$(cat /tmp/ssh_session_$PORT)/cwd)\"; zsh --login"
|
2023-09-17 20:50:48 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
2022-07-28 17:32:37 +02:00
|
|
|
|
|
|
|
pushd "/proc/$CHILD_PID/cwd"
|
|
|
|
SHELL_CWD=$(pwd -P)
|
|
|
|
popd
|
|
|
|
|
|
|
|
# Start alacritty with the working directory
|
2022-08-06 16:17:49 +02:00
|
|
|
alacritty --working-directory "$SHELL_CWD"
|