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

Command arguments are not saved/restored #43

Closed
hoschi opened this issue Sep 13, 2014 · 10 comments
Closed

Command arguments are not saved/restored #43

hoschi opened this issue Sep 13, 2014 · 10 comments
Labels

Comments

@hoschi
Copy link

hoschi commented Sep 13, 2014

As stated in #32 this should work. I run commands with arguments, but they not saved properly it seems. Test case: I ran tail -f README.md in the session "test", this is what was saved in 'last':

pane    0   0   :zsh    1   :*  0   :/home/hoschi   1   zsh :
pane    project-context-manager_second  0   :grunt  0   :-  0   :/home/hoschi/repos/sweetp-code/services/project-context-manager    1   zsh :
pane    project-context-manager_second  1   :zsh    1   :*  0   :/home/hoschi/repos/sweetp-code/services/project-context-manager    1   zsh :
pane    project-context-manager_vim 0   :vim    1   :*  0   :/home/hoschi/repos/sweetp-code/services/project-context-manager    1   vim :vim
pane    project-context-manager_vim 1   :git    0   :-  0   :/home/hoschi/repos/sweetp-code/services/project-context-manager    1   zsh :
pane    project-context-manager_vim 2   :vim    0   :   0   :/home/hoschi/repos/sweetp-code/services/password-manager   1   vim :vim
pane    project-context-manager_vim 3   :vim    0   :   0   :/home/hoschi/repos/sweetp-code/services/base-nodejs/lib    1   vim :vim
pane    project-context-manager_vim 4   :vim    0   :   0   :/home/hoschi/repos/sweetp-code/services/github-issues  1   vim :vim
pane    serien  0   :desktop    1   :*  0   :/home/hoschi   1   zsh :
pane    serien  0   :desktop    1   :*  1   :/home/hoschi   0   zsh :
pane    test    0   :git    1   :*  0   :/home/hoschi/repos/chrome-app-samples  1   tail    :tail
pane    tmux-conf   0   :vim    1   :*  0   :/home/hoschi   1   vim :vim
pane    tmux-conf   1   :vim    0   :-  0   :/home/hoschi   1   vim :vim
pane    tmux-conf   2   :man    0   :   0   :/usr/share/man 1   zsh :
pane    tmux-conf   3   :zsh    0   :   0   :/home/hoschi   1   zsh :
window  0   0   1   :*  d23d,151x78,0,0,0
window  project-context-manager_second  0   0   :-  d23e,151x78,0,0,1
window  project-context-manager_second  1   1   :*  d23f,151x78,0,0,2
window  project-context-manager_vim 0   1   :*  d240,151x78,0,0,3
window  project-context-manager_vim 1   0   :-  d241,151x78,0,0,4
window  project-context-manager_vim 2   0   :   d242,151x78,0,0,5
window  project-context-manager_vim 3   0   :   d243,151x78,0,0,6
window  project-context-manager_vim 4   0   :   d244,151x78,0,0,7
window  serien  0   1   :*  f619,151x78,0,0[151x48,0,0,8,151x29,0,49,9]
window  test    0   1   :*  694f,151x78,0,0,10
window  tmux-conf   0   1   :*  6950,151x78,0,0,11
window  tmux-conf   1   0   :-  6951,151x78,0,0,12
window  tmux-conf   2   0   :   6952,151x78,0,0,13
window  tmux-conf   3   0   :   6953,151x78,0,0,14
state   test    test

Only tail got saved, not the arguments:

pane    test    0   :git    1   :*  0   :/home/hoschi/repos/chrome-app-samples  1   tail    :tail

Here is my config:

# Activity monitoring
#setw -g monitor-activity on
#set -g visual-activity on

# Highlight active window
#set-window-option -g window-status-current-bg red

set -g default-terminal "screen-256color"

# utf8 is on
set -g utf8 on
set -g status-utf8 on

# address vim mode switching delay (http://superuser.com/a/252717/65504)
set -s escape-time 0

# tmux messages are displayed for 4 seconds
#set -g display-time 4000

# refresh 'status-left' and 'status-right' more often
#set -g status-interval 5

# Highlight active pane
#set-option -g pane-active-border-style bold
set-option -g pane-active-border-bg blue

# use powerline as status line
source '/home/hoschi/src/powerline/powerline/bindings/tmux/powerline.conf'

# create splits by | and -
unbind %
bind | split-window -h
bind - split-window -v

unbind p
# -n is for 'now prefix' !
bind-key -n F7 previous-window
bind-key a previous-window
bind-key -n F8 next-window
bind-key e next-window
bind-key C-b last-window

# renumber window so they have always continuing numbers
set -g renumber-windows on

# use vim motion keys while in copy mode
setw -g mode-keys vi

# use mouse!
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on

# scroll with mouse wheel in pane, not in terminals scrollbuffer
set -g terminal-overrides 'xterm*:smcup@:rmcup@'

# set history size
set -g history-limit 10000

##CLIPBOARD selection integration
##Requires prefix key before the command key
#Copy tmux paste buffer to CLIPBOARD
#
#
# attention: install xclip!
bind C-c run "tmux show-buffer | xclip -i -selection clipboard"
#Copy CLIPBOARD to tmux paste buffer and paste tmux paste buffer
bind C-v run "tmux set-buffer -- \"$(xclip -o -selection clipboard)\"; tmux paste-buffer"



# List of plugins
# Supports `github_username/repo` or full git URLs
#
# https://github.com/tmux-plugins/tmux-resurrect
# https://github.com/tmux-plugins/tmux-sessionist
set -g @tpm_plugins "              \
  tmux-plugins/tpm                 \
  tmux-plugins/tmux-resurrect   \
  tmux-plugins/tmux-sessionist     \
"
# Other examples:
# github_username/plugin_name    \
# git@github.com/user/plugin     \
# git@bitbucket.com/user/plugin  \

# initializes TMUX plugin manager
run-shell ~/.tmux/plugins/tpm/tpm

# https://github.com/tmux-plugins/tmux-resurrect
set -g @resurrect-processes 'ssh "git log" grunt-wrapper tail'

I'm on Arch Linux, tmux version is 1.9a

@bruno-
Copy link
Member

bruno- commented Sep 13, 2014

Hm.. you are right, tail arguments really don't get saved in your .tmux/resurrect/last.
I checked your .tmux.conf and just to confirm - everything looks good.

I suppose arguments aren't saved for any of the commands? In the other issue you reported git log also isn't restored properly for you.

Unfortunately I don't know how to move forward on this. I don't have easy access to Arch Linux so I'll have to ask you for the help.
Here's the explanation how program saving feature works in tmux-resurrect, and hopefully you can help with debugging.

  1. Get tmux pane PID

    In the pane where you will run tail program, execute this command: tmux list-panes -F "#{pane_pid}". This should output the PID of the pane process.
  2. Run tail -f some_foo_file in the pane where you got the PID

    Just execute tail -f some_foo_file in the same pane.
  3. Try to get process command from another pane
    In another pane run the command pgrep -lf -P <PID> where <PID> is the number you got in step 1.

I created a quick video how to execute the above steps so it's more clear:
https://dl.dropboxusercontent.com/u/1624364/iWTLmmaV9v8.mp4

The above manual steps are what tmux-resurrect does when saving tmux environment. You can check the source here.

Step 3. will probably return just tail for you. I don't know how good with shell are you, but finding a way to get full process name from the parent process PID would solve our problem here.

The above process works fine for me on OS X.
I'll investigate other ways to make this work. If you can debug this and make it work on your machine, that would be great too.

Edit: updated video link

@hoschi
Copy link
Author

hoschi commented Sep 15, 2014

I suppose arguments aren't saved for any of the commands? In the other issue you reported git log also isn't restored properly for you.

no

Step 3. will probably return just tail for you. I don't know how good with shell are you, but finding a way to get full process name from the parent process PID would solve our problem here.

I use zsh. I'll test the commands and check if its only me or a general zsh/linux problem.

I'll investigate other ways to make this work.

As mentioned in #32 ps --pid $pane_pid -o cmd could be a way, but I didn't tested it with OS X.

@bruno-
Copy link
Member

bruno- commented Sep 19, 2014

Hi, unfortunately ps --pid $pane_pid -o cmd does not work on OS X.

I've been investigating this and found the command: ps -o ppid,command - it could be used to fetch the process running inside a pane.

When you have time testing this on Arch would help:

  • run tail -f README.md
  • then run ps -o ppid,command | grep 'tail'

If the tail -f README.md is visible in the grep output - bingo, we could solve this issue and remove the dependency on pgrep.
So let me know the result!

@hoschi
Copy link
Author

hoschi commented Sep 19, 2014

Great you found another way which works on Mac! Here are my findings:

Does ps -o list all processes? I get only the processes of the terminal/shell it seems:

~ > ps -o ppid,command
 PPID COMMAND
 7442 -zsh
21805 ps -o ppid,command

If have to add "e" so get all processes, but this works:

~ > ps -eo ppid,command | grep 'tail'
12213 tail -f /var/log/httpd/error_log
21805 grep tail

I think you can safely ignore the last line, because the processes are sorted by pid and the grep process should always be the last started process.

@bruno-
Copy link
Member

bruno- commented Sep 19, 2014

Okay, great ps -eo ppid,command works for me too!

Let me just confirm this is a portable command. If yes, I'll implement it

@hoschi
Copy link
Author

hoschi commented Sep 19, 2014

yay!
fingers crossed I hope it is :)

@bruno- bruno- closed this as completed in 1d09f07 Sep 20, 2014
@bruno-
Copy link
Member

bruno- commented Sep 20, 2014

Hi, this has been implemented. The exact command that is used is ps -eo "ppid command" and apparently that's in the posix standard http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html#tag_20_96_04

I've tested this but I'd really appreciate your feedback, so can you please update the plugin and see if it's all right?

@hoschi
Copy link
Author

hoschi commented Sep 21, 2014

'Save' looks good, here are the first lines of my 'last' file:

pane    issues_vim  0   :vim    0   :Z  0   :/home/hoschi/repos/sweetp-code/services/github-issues  1   vim :vim
pane    issues_vim  0   :vim    0   :Z  1   :/home/hoschi/repos/sweetp-code/services/github-issues  0   zsh :
pane    issues_vim  1   :sh 0   :-  0   :/home/hoschi/repos/sweetp-code/services/github-issues  1   sh  :/bin/sh /home/hoschi/bin/grunt-wrapper watch:test
pane    issues_vim  2   :tail   0   :   0   :/home/hoschi/repos/sweetp-code/services/github-issues  1   tail    :tail -f README.md
pane    issues_vim  3   :zsh    1   :*  0   :/home/hoschi/repos/sweetp-code/services/github-issues  1   zsh :

"Restore" doesn't work reliable. tail gets restored with all arguments, this is fine. I also tested vim and man which all work. /bin/sh /home/hoschi/bin/grunt-wrapper watch:test doesn't get restored. I also tried only "watch" without the colon with the same not working result. When I execute the line by hand, it works. Here is the content of the wrapper skript:

#! /bin/bash

grunt $*

You can switch grunt to tail for testing, and run e.g. grunt-wrapper -f README.md which leads to the same result.

@bruno-
Copy link
Member

bruno- commented Sep 21, 2014

Good to hear processes are now saved properly.

About the restoration, do you still have this setting: set -g @resurrect-processes 'ssh "git log" grunt-wrapper tail'?
Try prefixing grunt-wrapper with a tilde, like this "~grunt-wrapper".

@hoschi
Copy link
Author

hoschi commented Sep 21, 2014

This works! Thank you.

@hoschi hoschi closed this as completed Sep 21, 2014
nerevar added a commit to nerevar/tmux-resurrect that referenced this issue Sep 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants