killdash9 / better-shell

Emacs shell management
GNU General Public License v3.0
40 stars 7 forks source link

Very nice! What about ssh instead of scp, and sudo shells? #2

Closed WorldsEndless closed 7 years ago

WorldsEndless commented 8 years ago

Way to catch on to a handy need in emacs; this could much streamline my heavy shell buffer usage. A couple things.

better-shell-remote-open is hard-coded to use scp, but I much prefer ssh (providing a configurable variable for this would be good; atm I just changed the with-temp-buffer line in the .el)

Also, I often use sudo shells for some of my remote hosts; before better-shell, I would get there by using tramp to find a file on the remote host with /sudo: and then open a shell from the dired buffer, which would inherit the sudo. This is somewhere better-shell might shine, if it could streamline this process.

killdash9 commented 8 years ago

I'm glad you found it useful. I've taken out the hardcoded "scp", it will now just use whatever the default tramp method is (tramp-default-method variable).

I'm curious, why do you prefer ssh over scp? I have noticed that scp is much faster at transferring large files.

As for streamlining sudo, can you tell me what you had in mind? For me, when I'm in a shell and I need sudo , I'll just run the sudo command. When I'm in a remote file and I need sudo, I run the following command, which reopens the file as sudo. If I run C-u better-shell-shell on a buffer which is already sudo'd, then I get a sudo'd shell.

((defun find-file-sudo ()
  "Find file as root if necessary."
  (interactive)
  (when buffer-file-name
    (unless (file-writable-p buffer-file-name)
      (find-alternate-file (if (file-remote-p buffer-file-name)
                               (with-parsed-tramp-file-name buffer-file-name nil
                                 (concat "/" method ":" host "|sudo:" host ":" localname))
                             (concat "/sudo:root@localhost:" buffer-file-name))))))
WorldsEndless commented 8 years ago

Thanks on fixing the default method. In the past I've just found scp less capable, but I'll take another look. In thinking more closely about my sudo needs, it's not really a shell need, so I can toss that suggestion. Your function also looks useful. Thanks!

WorldsEndless commented 8 years ago

This is a follow-up after some thought as to why I use SSH more than SCP and how sudo works for me. Example workflow:

  1. Process with ssh first (sudo)ssh to server -> locate files that need sudo editing -> C-x f <<< Opens file in emacs in sudo, as required
  2. Process with find-file first find-file "/sudo:[remote]:[file-or-directory] " -> M-x [better-shell-]shell <<< Opens dir in sudo, as desired

Note that the /sudo: in 2. is according to helm/tramp customizations here: https://github.com/emacs-helm/helm/issues/981

So basically, the reason I would prefer both a streamlined sudo process (i.e. a better-shell command to take care of the first step in 1. above) and the reason I use SSH is because of the nice integration between ssh shells and dired, so that sudo shell and sudo dired interop nicely (which, to my knowledge, doesn't seem possible with SCP).

killdash9 commented 7 years ago

I finally got around to addressing this request. I've implemented it locally and I'll push it out after a week or two of testing.

WorldsEndless commented 7 years ago

I just tried my first better-shell-sudo-here; worked like a charm! Thanks!