Function: ghostel--start-process

ghostel--start-process is a natively compiled function defined in ghostel.el.

Signature

(ghostel--start-process)

Documentation

Start the configured shell with a PTY.

Local buffers use the native PTY path when ghostel-use-native-pty is non-nil. Remote TRAMP buffers spawn through Emacs so TRAMP can run the shell on the remote host.

Source Code

;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel.el
(defun ghostel--start-process ()
  "Start the configured shell with a PTY.
Local buffers use the native PTY path when `ghostel-use-native-pty'
is non-nil.  Remote TRAMP buffers spawn through Emacs so TRAMP can
run the shell on the remote host."
  (let* ((remote-p (file-remote-p default-directory))
         (shell-spec (ghostel--resolve-shell-spec))
         (shell (car shell-spec))
         (extra-shell-args (cdr shell-spec))
         (ghostel-dir (ghostel--resource-root))
         ;; Detect shell type when integration is enabled.
         ;; For remote, also check ghostel-tramp-shell-integration.
         (shell-type (and ghostel-shell-integration
                          (or (not remote-p)
                              (let ((st (ghostel--detect-shell shell)))
                                (and st
                                     (or (eq ghostel-tramp-shell-integration t)
                                         (and (listp ghostel-tramp-shell-integration)
                                              (memq st ghostel-tramp-shell-integration)))
                                     st)))
                          (ghostel--detect-shell shell)))
         (integration
          (when shell-type
            (if remote-p
                (ghostel--setup-remote-integration shell-type)
              (ghostel--setup-local-integration shell-type ghostel-dir))))
         ;; Start recognized remote shells login+interactive so they (and the
         ;; user's rc/profile) load.  When integration is active the default
         ;; adapts per shell (bash drops `-l' to keep `--rcfile').  Explicit
         ;; per-method args from `ghostel-tramp-shells' override the default.
         (shell-args (append
                      (plist-get integration :args)
                      (or extra-shell-args
                          (and remote-p
                               (ghostel--default-remote-shell-args
                                shell integration)))))
         (extra-env (append
                     (unless remote-p
                       (list (format "EMACS_GHOSTEL_PATH=%s" ghostel-dir)))
                     (plist-get integration :env)))
         ;; On macOS, wrap with `/usr/bin/login' so the shell starts as a login shell.
         ;; See `ghostel-macos-login-shell' for the rationale.
         ;; Skipped for remote spawns - login(1) is a local-session concept.
         (spawn-spec (if (and ghostel-macos-login-shell
                              (not remote-p)
                              (eq system-type 'darwin))
                         (ghostel--macos-login-wrap shell shell-args)
                       (cons shell shell-args)))
         (spawn-program (car spawn-spec))
         (spawn-args (cdr spawn-spec))
         (proc (ghostel--spawn-pty spawn-program spawn-args
                                   extra-env remote-p)))
    (setq ghostel--shell-program shell)
    (when (and remote-p integration)
      (let ((files (plist-get integration :temp-files))
            (dirs (plist-get integration :temp-dirs)))
        (add-hook 'kill-buffer-hook
                  (lambda () (ghostel--cleanup-temp-paths files dirs))
                  nil t)))
    proc))