Live data from Hacker News

Show HN: ssh and cd get married

github.com

11–20 of 51 posts

Re: Show HN: ssh and cd get married

#11

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.

Re: Show HN: ssh and cd get married

#13
post #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)

Enabling ido-mode makes it a lot more easier to use. Also, you can open local files as sudo in a similar way.

/sudo:localhost:/etc/hosts

Re: Show HN: ssh and cd get married

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

Can you explain this code?

Definitely. Here's a gist, feel free to comment with any questions!

https://gist.github.com/christianbundy/8954786

Re: Show HN: ssh and cd get married

#17
I like to take advantage of temporal locality. My zshrc is configured to take me to the most recent place that I have been whenever I open a new shell:

  autoload -U add-zsh-hook
  record_pwd() { pwd > ~/.cwd }
  add-zsh-hook chpwd record_pwd
  touch ~/.cwd
  cd `cat ~/.cwd`

Re: Show HN: ssh and cd get married

#18
I'm trying really hard to see the utility in this, as somebody who almost obsessively aliases commands to save keystrokes. But it's almost the same number of keys, at the expense of having to mix them together.

This feels less like a marriage and more like trying to tie two very different animals together.

I'd much prefer if this was some kind of host-alias based magic, where "ssh my_server_web" took my to "my_server:/srv/http/my_site", "ssh my_server_db" took me to my_server and opened mysql, etc.

Re: Show HN: ssh and cd get married

#19
There are two things I find odd about this solution.

You still have to type the path you want to cd to. See previous discussion at https://news.ycombinator.com/item?id=6229001 for possible solutions.

The github example specifies the username to ssh to. Assuming you ssh to the host more than once see man ssh_config and the User parameter.

And screen/tmux, obviously.

Post reply on HN