Live data from Hacker News

Show HN: ssh and cd get married

github.com

21–30 of 51 posts

Re: Show HN: ssh and cd get married

#22
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.

I am thankful you didn't.

Congratulations on getting the *NIX philosophy right.

Re: Show HN: ssh and cd get married

#23
Even better: make the script work with local paths as well.

Then you can put

    alias cd='sshcd'
in your .bashrc, and you won't have to distinguish between local and remote paths ever again.

Re: Show HN: ssh and cd get married

#24

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

Absolutely! I'm really only using this for SCP-like syntax when SSHing into unfamiliar boxes.

WARNING: SHAMELESS SELF-PROMOTION BELOW

Unless, you know, you used something like homes(h)ick...

https://github.com/technicalpickles/homesick

Re: Show HN: ssh and cd get married

#25
post #23

Even better: make the script work with local paths as well. Then you can put alias cd='sshcd' in your .bashrc, and you won't have to distinguish between local and remote paths ever again.

I was thinking about aliasing cd like that and instead having psuedo-directories that you can cd into to SSH into another box. The biggest problem though would be moving around in the box, as `cd ..` wouldn't take you back to your local machine.

What do you think?

Re: Show HN: ssh and cd get married

#26

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 use screen and it works well. The first thought when I saw this post was of screen and tmux. Anyone spending any kind of serious time in remote server through ssh should use screen/tmux.

I totally agree, a lot more of my work life is spent on our Linux platform. tmux is a godsend due to my sometimes flaky VPN connection.

Re: Show HN: ssh and cd get married

#30

It would be much more useful if you can make an scp with autocomplete by pressing tab in the terminal. scp root@host:/long(tab)_file_name .

Funny you mention it, I actually have this working! (http://i.imgur.com/8VBYDd4.png)

You can check out my dotfiles (https://github.com/christianbundy/dotfiles), but I'm pretty sure that the functionality came standard with one of my Zsh submodules, Prezto (https://github.com/sorin-ionescu/prezto).

Post reply on HN