Compare commits

..

No commits in common. "8272e55b1af9797638c775f2f369ca1ec16d5585" and "1094608c76ce7efe36b3537d6786111a9704b4f4" have entirely different histories.

1 changed files with 17 additions and 11 deletions

View File

@ -1,17 +1,23 @@
#!/bin/bash
RUNNING_SSH=false
CHILD_PID=$(pgrep -P $1)
[[ $(ps -p $CHILD_PID -o comm=) == "ssh" ]] && RUNNING_SSH=true
GRAND_CHILD_PID=$(pgrep -P $CHILD_PID)
[[ $? == 0 ]] && [[ $(ps -p $GRAND_CHILD_PID -o comm=) == "ssh" ]] && RUNNING_SSH=true && CHILD_PID=$GRAND_CHILD_PID
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)"
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"