Show HN: ssh and cd get married
github.com
github.com
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.[0] https://github.com/martinp/dotfiles/blob/master/dot.zlogin
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!
The benefit of tmux/screen is that you can run it remotely, and reconnect to your session-in-progress at any time.
The next is all the handy notifications in the bottom bar; a bit like conky, if you use that. So it lists the server mem/cpu/network load, number of packages that need updating, RAID status, AWS estimated cost (if relevant), no. logged in users, etc...
It originally started out with a Screen backend, then switched over to Tmux which has a lot of the same multiplexing functionality. So that's probably why you're not seeing a huge added benefit. But the added extras are enough to make me always want Byobu installed - particularly the easy session attachment.
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.
Congratulations on getting the *NIX philosophy right.
"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."
WARNING: SHAMELESS SELF-PROMOTION BELOW
Unless, you know, you used something like homes(h)ick...
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.
autoload -U add-zsh-hook
record_pwd() { pwd > ~/.cwd }
add-zsh-hook chpwd record_pwd
touch ~/.cwd
cd `cat ~/.cwd`/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)
/sudo:localhost:/etc/hosts
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.
ssh -t yourserver.com 'cd /some/dir/;exec /bin/sh'I didn't develop this because the keystrokes were difficult, I just know that both git and SCP support this syntax and couldn't think of any good reason why SSH shouldn't.
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 :).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. :)
Then you can put
alias cd='sshcd'
in your .bashrc, and you won't have to distinguish between local and remote paths ever again.What do you think?
scp root@host:/long(tab)_file_name .
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).
t=${@[$#]}
c=("ssh" "-t" "${@:1:$(( $# -1 ))}" "${t%:}" "cd ${t##:}; \$SHELL -l")
"${c[@]}"