24 lines
630 B
Bash
Executable File
24 lines
630 B
Bash
Executable File
#!/bin/bash
|
|
|
|
CHILD_PID=$(pgrep -P $1)
|
|
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]*$')
|
|
alacritty -e $COMMAND -t "cd \"\$(readlink -e /proc/\$(cat /tmp/ssh_session_$PORT)/cwd)\"; zsh --login"
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
pushd "/proc/$CHILD_PID/cwd"
|
|
SHELL_CWD=$(pwd -P)
|
|
popd
|
|
|
|
# Start alacritty with the working directory
|
|
alacritty --working-directory "$SHELL_CWD"
|