Live data from Hacker News

Show HN: ssh and cd get married

github.com

31–40 of 51 posts

Re: Show HN: ssh and cd get married

#31

Alternatively, you could keep a tmux session open on the server and just attach it on connect. That way you can have everything arranged just the way you left it on disconnect. Same applications running, multiple windows, splits, etc. And you don't even need to start a new shell on connect. ssh user@host -t tmux attach You can add an alias for it. alias backtowork='ssh -t user@host tmux attach -t worksession' The las…

Awesome, I hadn't though of that. My terminal automatically logs into my server via SSH and I just use my tmux aliases from there (minus the SSH, of course), but that would be a great way to do it if I developed locally. Thanks for the tip!

Hm, why only for developing locally?

The benefit of tmux/screen is that you can run it remotely, and reconnect to your session-in-progress at any time.

Re: Show HN: ssh and cd get married

#32

Earlier quoted context omitted.

This is by far is the best option, its still user based so it will take me where I want.

Absolutely – I'd definitely recommend that this is used in favor of my utility if you're always going to the same directory. I originally wrote a util that outputs your current username, hostname, and path ( https://github.com/christianbundy/whereami ) so that you can either share or save it somewhere, but since SSH doesn't handle file paths by default I made a utility that does. :)

I think you've done an excellent job of pointing out that ssh should just be capable of doing this by default. Like many such things, it's obvious with hindsight. But somehow I never thought of it before.

Re: Show HN: ssh and cd get married

#34

Alternatively, you could keep a tmux session open on the server and just attach it on connect. That way you can have everything arranged just the way you left it on disconnect. Same applications running, multiple windows, splits, etc. And you don't even need to start a new shell on connect. ssh user@host -t tmux attach You can add an alias for it. alias backtowork='ssh -t user@host tmux attach -t worksession' The las…

I do something similar. Instead of passing the tmux attach command to ssh, I attach (or create) a tmux session if the shell is a) a login shell and b) started in a SSH session. [0]

[0] https://github.com/martinp/dotfiles/blob/master/dot.zlogin

Re: Show HN: ssh and cd get married

#36

Earlier quoted context omitted.

Literally. We both know that it would've been easier to write this in Python, Ruby, Javascript, etc., but at the cost of using an "uncool" language I was able to solve the problem in three lines with only bash as a dependency. Pull requests welcome.

I am thankful you didn't. Congratulations on getting the *NIX philosophy right.

If that's the ★nix philosophy I don't want to be a ★nix person any more. Seriously, even my VMS machines have python installed, and a script I can read is a lot better than one I can't, even if the one I can read has an extra dependency.

Re: Show HN: ssh and cd get married

#37
For what it's worth, this is broken when the target directory contains spaces/wildcard characters, etc. I would suggest you consider using something like the following to generate the command line you pass to ssh:

  printf -v cmd 'cd %q && $SHELL -l' "$target_dir"
Also, dropping the ':' and just having an additional argument would make your life a bit simpler. What's with the array assignment just to invoke the command? Seems a bit unnecessary. The microoptimizer in me tells me you should use 'exec' as well :).

Re: Show HN: ssh and cd get married

#38
post #36

Earlier quoted context omitted.

I am thankful you didn't. Congratulations on getting the *NIX philosophy right.

If that's the ★nix philosophy I don't want to be a ★nix person any more. Seriously, even my VMS machines have python installed, and a script I can read is a lot better than one I can't, even if the one I can read has an extra dependency.

Python isn't too bad (unless you're calling the script in a lot of separate instances), but python is fairly neat compared to ruby/javascript/whatever trendy language of the week as it doesn't need a huge pile of worthless dependencies itself.

Re: Show HN: ssh and cd get married

#39

Earlier quoted context omitted.

Literally. We both know that it would've been easier to write this in Python, Ruby, Javascript, etc., but at the cost of using an "uncool" language I was able to solve the problem in three lines with only bash as a dependency. Pull requests welcome.

I am thankful you didn't. Congratulations on getting the *NIX philosophy right.

http://en.wikipedia.org/wiki/Unix_philosophy

"The Unix philosophy emphasizes building short, simple, clear, modular, and extendable code that can be easily maintained and repurposed by developers other than its creators. The philosophy is based on composable (rather than contextual) design."

Re: Show HN: ssh and cd get married

#40

I hate little extensions like this because if I make them part of my workflow, I am completely hindered when I find myself on a machine that doesn't have this. (Every other machine in the world.)

In this particular instance, the command is saving you a total of two keystrokes. "You could probably get by in a pinch."
Post reply on HN