tmux-plugins / tmux-resurrect

Persists tmux environment across system restarts.
MIT License
11.22k stars 418 forks source link

Save / Restore processes broken in Cygwin #198

Open christarazi opened 7 years ago

christarazi commented 7 years ago

After looking into it, seems the issue is because save_command_strategies/ps.sh uses the ps command, which is different under Cygwin. I decided to install procps from Cygwin setup which gives access to a more advanced pgrep command. To use it, save_command_strategies/pgrep.sh needs to be modified because Cygwin's version of pgrep has different flags, than the standard pgrep. Here's the diff of my working setup:

diff --git a/save_command_strategies/pgrep.sh b/save_command_strategies/pgrep.sh
index 15d98b3..363ac53 100755
--- a/save_command_strategies/pgrep.sh
+++ b/save_command_strategies/pgrep.sh
@@ -4,6 +4,13 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

 PANE_PID="$1"

+pgrep_command_flags() {
+   case $(uname -s) in
+       *CYGWIN*) echo "-af" ;;
+       *) echo "-lf" ;;
+   esac
+}
+
 exit_safely_if_empty_ppid() {
    if [ -z "$PANE_PID" ]; then
        exit 0
@@ -11,7 +18,7 @@ exit_safely_if_empty_ppid() {
 }

 full_command() {
-   \pgrep -lf -P "$PANE_PID" |
+   pgrep "$(pgrep_command_flags)" -P "$PANE_PID" |
        cut -d' ' -f2-
 }

Here's some relevant lines from my .tmux.conf:

# Cygwin: fixes directory issues
set-environment -g CHERE_INVOKING 1

set -g @resurrect-save-command-strategy 'pgrep'
set -g @resurrect-processes '/usr/bin/vim'
lefth commented 7 years ago

I experienced the same problem, and this patch fixes it. On a related note, Cygwin should use the 'pgrep' strategy by default, since Cygwin's 'ps' prints too little information to be useful.

karakays commented 4 years ago

I confirm the patch solves the problem