Show HN: ssh and cd get married
github.com
Show HN: ssh and cd get married
1–10 of 51 posts
Re: Show HN: ssh and cd get married
#2 t="${!#}"
c=("ssh" "-t" "${@:1:$(($#-1))}" "${t%:*}" "cd ${t##*:}; \$SHELL -l")
"${c[@]}"
That's literally the whole repo.Re: Show HN: ssh and cd get married
#3Re: Show HN: ssh and cd get married
#4/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 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
#6echo "cd /your/favorite/folder" >> ~/.bashrc
Re: Show HN: ssh and cd get married
#7TL;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.
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
#8echo "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.
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
#9Re: Show HN: ssh and cd get married
#10Alternatively, 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…
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!