tmux-plugins / tmux-resurrect

Persists tmux environment across system restarts.
MIT License
11.39k stars 423 forks source link

some command line arguments are not being saved #45

Closed duckunix closed 9 years ago

duckunix commented 10 years ago

It all depends on how the new pane is started. I know that there has been changes made via #43 but, given the way I then to launch ssh/mosh connections, it fails.

I have functions set up to launch a new pane with either ssh or mosh like so:

function smosh () {
  tmux neww -n $1 "/usr/bin/mosh  $*"
}

function ss () {
  tmux neww -n $1 "/usr/bin/ssh  $*"
}

Now with the new update, the base command gets saved, it just mosh-client or ssh. If I create a new pane via tmux new-window and then start the same commands as above, saving the full command plus arguments work. My last file looks like:

pane    TeSt    1       :bash   0       :       0       :/home/don      1       bash    :
pane    TeSt    2       :loki   0       :       0       :/home/don      1       mosh-client     :
pane    TeSt    3       :loki   0       :       0       :/home/don      1       mosh-client     :mosh-client loki | 192.168.1.10 60004
pane    TeSt    4       :loki   0       :-      0       :/home/don      1       ssh     :
pane    TeSt    5       :bash   1       :*      0       :/home/don      1       ssh     :ssh loki
window  TeSt    1       0       :       6b22,273x88,0,0,13
window  TeSt    2       0       :       6b23,273x88,0,0,14
window  TeSt    3       0       :       6b24,273x88,0,0,15
window  TeSt    4       0       :-      6b25,273x88,0,0,16
window  TeSt    5       1       :*      6b26,273x88,0,0,17
state   TeSt

Where panes 2 & 4 are using my bash functions above, and panes 3 & 5 are using the new-window and then start the command method.

I have tracked the issue to the way the PID is passed to _$HOME/.tmux/plugins/tmux-resurrect/save_commandstrategies/ps.sh, but I am not sure where to go look to get it the correct PID of the pane.

Please let me know what other I can provide, or where I can go look to help fix this issue. This is a major road-block on my adoption of this fine plugin full time.

Thanks!

d

bruno- commented 10 years ago

Hi, I can reproduce this issue too.

Was this working for you previously? From what I can see, it is not related to changes in #43...

bruno- commented 10 years ago

Here's a suggestion how to update the functions so they work nicely with tmux-resurrect:

function smosh () {
  # create a new empty window and get its `pane_id`
  local pane_id=$(tmux new-window -d -n "$1" -P -F "#{pane_id}")

  # use `tmux send-keys` to start a desired command in new window
  tmux send-keys -t "$pane_id" "/usr/bin/mosh $*" "C-m"
}

I just tested this locally and it worked fine. Does that solve the problem?

duckunix commented 10 years ago

That does work for my use case. However, I think I have figured out a more generic way by updating save_command_strategies/ps.sh (forgive the lack of pull request):

diff --git a/save_command_strategies/ps.sh b/save_command_strategies/ps.sh
index 8544add..ea0ec1f 100755
--- a/save_command_strategies/ps.sh
+++ b/save_command_strategies/ps.sh
@@ -11,10 +11,16 @@ exit_safely_if_empty_ppid() {
 }

 full_command() {
-       ps -eo "ppid command" |
-               sed "s/^ *//" |
-               grep "^${PANE_PID}" |
-               cut -d' ' -f2-
+       if !  ps -eo "ppid command" | grep -q "^${PANE_PID}"
+       then
+               ps -o command -p "${PANE_PID}" |
+                       grep -v COMMAND
+       else
+               ps -eo "ppid command" |
+                       sed "s/^ *//" |
+                       grep "^${PANE_PID}" |
+                       cut -d' ' -f2-
+       fi
 }

I tend to have a few things which do the tmux neww -n "command", and so this is a cleaner way, I think.

duckunix commented 10 years ago

And, ps on FreeBSD 10-RELEASE does not like the -e flag...it lists the environment, not everything.

New patch to get it working on FreeBSD:

diff --git a/save_command_strategies/ps.sh b/save_command_strategies/ps.sh
index 8544add..60417c6 100755
--- a/save_command_strategies/ps.sh
+++ b/save_command_strategies/ps.sh
@@ -3,6 +3,10 @@
 CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

 PANE_PID="$1"
+case $(uname -s) in 
+       FreeBSD) PS_ARG="-a" ;;
+             *) PS_ARG="-e" ;;
+esac

 exit_safely_if_empty_ppid() {
        if [ -z "$PANE_PID" ]; then
@@ -11,10 +15,16 @@ exit_safely_if_empty_ppid() {
 }

 full_command() {
-       ps -eo "ppid command" |
-               sed "s/^ *//" |
-               grep "^${PANE_PID}" |
-               cut -d' ' -f2-
+       if !  ps "${PS_ARG}" -o "ppid command" | grep -q "^${PANE_PID}" 
+       then
+               ps -o command -p "${PANE_PID}" |
+                       grep -v COMMAND
+       else
+               ps "${PS_ARG}" -o "ppid command" |
+                       sed "s/^ *//" |
+                       grep "^${PANE_PID}" |
+                       cut -d' ' -f2-
+       fi
 }

 main() {
bruno- commented 10 years ago

Hi @duck thanks for all the effort around this. I just added a patch for FreeBSD ps command arguments in 8fd3858.

bruno- commented 10 years ago

I was playing with your first patch and it seems to work.

Unfortunately it also detects bash (in my case the default shell) for all the panes with no commands running. That means, if this patch was added to the plugin, we would also have to make some kind of filter for bash commands (or user default shells) because that should not be restored.

On the other hand, legit bash command should be restored, example bash -c "sleep 1000".

I'm sorry to say I think this increasing complexity is definitely not worth it.

duckunix commented 9 years ago

Your project....your call...I am okay with that.