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

Preexec before SSH command #31

Closed
vroumvroum opened this issue Nov 24, 2016 · 3 comments
Closed

Preexec before SSH command #31

vroumvroum opened this issue Nov 24, 2016 · 3 comments
Labels

Comments

@vroumvroum
Copy link

Hello,

I'm trying to change my tmux window name on the fly when i'm connecting to another server through SSH.
I tried the following :

preexec() { if [ "$1" == "ssh" ]; then tmux rename-window $3@$1; else tmux rename-window $(whoami)@$(hostname); fi }

After trying ssh myhost -l myuser
Preexec does not seem to be executed ...

Am i missing something ?

Thank you, regards, Greg.

@rcaloras rcaloras added the bug label Nov 26, 2016
@rcaloras
Copy link
Owner

rcaloras commented Nov 27, 2016

Hey @vroumvroum,

I'm unable to recreate. Could you try using a simpler preexec command to confirm it's getting executed? e.g.

preexec() { echo "«$1»"; }

For example:

$ preexec() { echo "«$1»"; }
$ ssh rcaloras@bashhub.com
«ssh rcaloras@bashhub.com»

@vroumvroum
Copy link
Author

vroumvroum commented Nov 28, 2016

Hey @rcaloras,

Thank you so much for answering.
It's working now. I didn't understand that command line arguments were all aggregated into "$1".

So I needed to cut "$1" or make a regex search on it. Here is what I did

preexec() { cmd=$(echo $1 | cut -d " " -f1); if [ "$cmd" == "ssh" ]; then tmux rename-window "$1"; fi }
precmd() { tmux rename-window "vroumvroum VDI"; }

Regards, Greg.

@rcaloras
Copy link
Owner

Great. Glad to hear everything is good. Thanks for using bash-preexec!

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