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

How to run commands without starting shell #34

Open
jby opened this issue Apr 10, 2014 · 11 comments
Open

How to run commands without starting shell #34

jby opened this issue Apr 10, 2014 · 11 comments

Comments

@jby
Copy link

jby commented Apr 10, 2014

Is there a way to send commands to tmux without having to start the shell and sending the command there?

In my old script (used before finding tmuxifier) I have:

tmux new-window -d -n "host" "ssh host"

which makes tmux name the window after the remote host and execute ssh directly, without first executing my login shell.

How do I achieve the same result from a tmuxifier config?

@jimeh
Copy link
Owner

jimeh commented Apr 10, 2014

Tmuxifier doesn't currently allow passing custom arguments to the new-window command: https://github.com/jimeh/tmuxifier/blob/master/lib/layout-helpers.sh#L20-L27

I am planning to add support for it though, just haven't gotten there yet. In the meantime what you can do is instead of calling the new_window helper in your window/session layout file, call this:

tmuxifier-tmux new-window -t "$session:" -d -n "host" "ssh host"

@jby
Copy link
Author

jby commented Apr 10, 2014

Thanks 👍

@jby
Copy link
Author

jby commented Apr 10, 2014

Is it pure sh syntax? Could I write a sh for loop and cycle through?

@jimeh
Copy link
Owner

jimeh commented Apr 10, 2014

Yepp, the layouts files are just pure bash scripts with some helper functions made available by Tmuxifier :)

@jimeh
Copy link
Owner

jimeh commented Apr 10, 2014

The layout files are literally just sourced with source in the middle of some variable/environment setup for the specific layout file: https://github.com/jimeh/tmuxifier/blob/master/lib/layout-helpers.sh#L167

@jby
Copy link
Author

jby commented Apr 10, 2014

Great, thanks again!

@jby
Copy link
Author

jby commented Apr 11, 2014

Hmm interesting.

If I use this at the end of my window-file:

tmuxifier-tmux new-window -t "$session:" -d -n "host1" "ssh host1"
tmuxifier-tmux new-window -t "$session:" -d -n "host2" "ssh host2"
tmuxifier-tmux new-window -t "$session:" -d -n "host3" "ssh host3"
tmuxifier-tmux new-window -t "$session:" -d -n "host4" "ssh host4"
tmuxifier-tmux new-window -t "$session:" -d -n "host5" "ssh host5"
tmuxifier-tmux new-window -t "$session:" -d -n "host6" "ssh host6"
tmuxifier-tmux new-window -t "$session:" -d -n "host7" "ssh host7"
tmuxifier-tmux new-window -t "$session:" -d -n "host8" "ssh host8"
tmuxifier-tmux new-window -t "$session:" -d -n "host9" "ssh host9"

I get what I expect - the nine windows, each ssh:ed into it's respective host.

However, if I instead use a loop:

for f in host1 host2 host3 host4 host5 host6 host7 host8 host9
do
    tmuxifier-tmux new-window -t "$session:" -d -n "${f}" "ssh ${f}"
done

I get this:

create window failed: index in use: 1

and it seems that it creates the session and the first window (localhost), defined by the default

new_window "[window name]"

earlier in the file

Could you perhaps shed som light on this? Is it a timing issue? The loop is too quick?

@jby
Copy link
Author

jby commented Apr 11, 2014

Hmm, tested to rename the session to have a different name than the window-layout - no more error...

@jby
Copy link
Author

jby commented Apr 11, 2014

Apparently it's not enough with a different name - it needs a dash '-' in the name to not give the error.

Strange.

@jimeh
Copy link
Owner

jimeh commented Apr 11, 2014

I think it could be due to $session not be correctly set. In theory it should be regardless of what you're doing, but you could try this:

tmuxifier-tmux new-window -t "${session-$(tmuxifier current-session)}:" -d -n "host1" "ssh host1"

Basically if $session is not set, get the current session name from Tmuxifier.

@jby
Copy link
Author

jby commented Apr 11, 2014

👍

Thanks, that did the trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants