Live data from Hacker News

Show HN: ssh and cd get married

github.com

1–10 of 51 posts

Re: Show HN: ssh and cd get married

#4
If you are an Emacs user, Tramp does this, e.g. you can open a file like:

/user@example.com:/some/remote/path/file.dat

Directory navigation (dired) works too, you can also open a shell in the remote directory (M-x shell)

Re: Show HN: ssh and cd get married

#5
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 last argument allows you to attach a chosen session if you have more than one running.

Re: Show HN: ssh and cd get married

#7
post #2

TL;DR: a 3 line exercise in bash argument munging. t="${!#}" c=("ssh" "-t" "${@:1:$(($#-1))}" "${t%:*}" "cd ${t##*:}; \$SHELL -l") "${c[@]}" That's literally the whole repo.

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.

Re: Show HN: ssh and cd get married

#8

echo "cd /your/favorite/folder" >> ~/.bashrc

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. :)

Re: Show HN: ssh and cd get married

#10

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!

Post reply on HN