riscy / shx-for-emacs

An Emacs shell-mode (and comint-mode) extension that enables displaying small plots and graphics and lets users write shell commands in Emacs Lisp.
GNU General Public License v3.0
218 stars 10 forks source link

request: change the behavior of :ssh #11

Closed neeasade closed 5 years ago

neeasade commented 5 years ago

I'd like if the :ssh shx function would takeover the current buffer and inherit it's name rather than becoming a new buffer named *shx* -- do you think that is too opinionated?

riscy commented 5 years ago

I like this idea! It's nice to be able to keep context. This definitely looks feasible.

neeasade commented 5 years ago

here is a racey hack I'm using in the meantime:

(defun shx-cmd-ssh (host)
  "Open a shell on HOST using tramp.
\nThis way you benefit from the remote host's completions, and
commands like :pwd and :edit will work correctly.
\nExample:\n
  :ssh username@hostname:port"
  (if (equal host "")
    (shx-insert 'error "ssh host\n")
    (shx-insert "Connecting to " 'font-lock-doc-face host 'default "\n")
    (let* ((host (replace-regexp-in-string ":" "#" host))
            (default-directory
              (if (eq tramp-syntax 'default)
                (concat "/ssh:" host ":~")
                (concat "/" host ":~")))
            (bufname (buffer-name (current-buffer))))

      (shx--asynch-funcall #'shx (list nil default-directory))
      (shx--asynch-funcall
        (lambda (bufname)
          (when (get-buffer bufname)
            (kill-buffer bufname)
            (with-current-buffer "*shx*"
              (rename-buffer bufname))))
        (list bufname)
        0.6)
      )))
riscy commented 5 years ago

This is great. Feel free to PR this against the develop branch if you want to show up on the list of contributors in GitHub :) and I'll test it out this weekend. I think this is the right way to go with the :ssh command -- thanks.

riscy commented 5 years ago

Something like this is merged into master. I think this behavior is definitely an improvement -- take a look and tell me if it works for you.

neeasade commented 5 years ago

Yes, it works very nicely, thank you.