2022-07-28 17:32:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-09-17 21:31:30 +02:00
|
|
|
RUNNING_SSH=false
|
2024-03-31 23:35:40 +02:00
|
|
|
RUNNING_WAYPIPE=false
|
|
|
|
SSH_CLIENT=""
|
|
|
|
CHILD_PID=$(pgrep -P "$1")
|
2023-09-17 20:50:48 +02:00
|
|
|
|
2024-03-31 23:35:40 +02:00
|
|
|
GRAND_CHILD_PID=$(pgrep -P "$CHILD_PID")
|
|
|
|
if [ "$GRAND_CHILD_PID" != 0 ]; then
|
|
|
|
GRAND_CHILD_NAME=$(ps -p "$GRAND_CHILD_PID" -o comm=)
|
|
|
|
if [ "$GRAND_CHILD_NAME" == "ssh" ]; then
|
|
|
|
RUNNING_SSH=true
|
|
|
|
CHILD_PID=$GRAND_CHILD_PID
|
|
|
|
SSH_CLIENT=$(ps -p "$CHILD_PID" -o args --no-headers | awk '{ print $2 }')
|
|
|
|
fi
|
|
|
|
if [ "$GRAND_CHILD_NAME" == "waypipe" ]; then
|
|
|
|
RUNNING_WAYPIPE=true
|
|
|
|
CHILD_PID=$(pgrep -P "$GRAND_CHILD_PID")
|
|
|
|
SSH_CLIENT=$(ps -p "$GRAND_CHILD_PID" -o args --no-headers | awk '{ print $3 }')
|
|
|
|
fi
|
|
|
|
fi
|
2022-07-28 17:32:37 +02:00
|
|
|
|
2023-12-02 00:03:50 +01:00
|
|
|
|
2024-03-31 23:35:40 +02:00
|
|
|
if [ $RUNNING_SSH == true ] || [ $RUNNING_WAYPIPE == true ]; then
|
2023-09-17 21:31:30 +02:00
|
|
|
PORT=$(ss -tnpa | grep ssh | grep "pid=$CHILD_PID" | awk '{ print $4 }' | grep -o '[0-9]*$')
|
2024-03-31 23:35:40 +02:00
|
|
|
alacritty -e ssh "$SSH_CLIENT" -t "cd \"\$(readlink -e /proc/\$(cat /tmp/ssh_session_$PORT)/cwd)\"; zsh --login"
|
2023-09-17 21:31:30 +02:00
|
|
|
else
|
2024-03-31 23:35:40 +02:00
|
|
|
if [ "$(ps -p "$1" -o comm=)" == "alacritty" ]; then
|
|
|
|
CWD=$(readlink -e /proc/"$CHILD_PID"/cwd)
|
2023-12-12 19:46:42 +01:00
|
|
|
if [ "$CWD" != "" ]; then
|
2023-12-02 00:03:50 +01:00
|
|
|
alacritty --working-directory "$CWD"
|
|
|
|
else
|
|
|
|
alacritty
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
alacritty
|
|
|
|
fi
|
2023-09-17 21:31:30 +02:00
|
|
|
fi
|