Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support tmux split-pane when restoring processes with ps strategy #518

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions save_command_strategies/ps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,29 @@ exit_safely_if_empty_ppid() {
fi
}

default_command() {
tmux_command=$(tmux show-option default-command)
tmux_shell=$(tmux show-option default-shell)
echo "${tmux_command:-${tmux_shell:-${SHELL:-/bin/sh}}}"
}

full_command() {
ps -ao "ppid,args" |
sed "s/^ *//" |
grep "^${PANE_PID}" |
cut -d' ' -f2-
# get the absolute path and args of the running process
parent=$(ps -p "${PANE_PID}" -o args | tail -n +2)
if echo "$parent" | grep --quiet -E -- "-?$(basename "$(default_command)")"; then
# normally the PID is a shell. return the child that has an associated controlling terminal.
child=$(ps -ao "ppid,args" |
sed "s/^ *//" |
grep "^${PANE_PID}" |
cut -d' ' -f2-)
if [ "$child" ]; then
printf %s "$child"
return
fi
fi
# if this command was spawned with `tmux split-pane`, it has no parent shell.
# just return the args for the PID itself.
ps -p "${PANE_PID}" -o args | tail -n +2
}

main() {
Expand Down