summaryrefslogtreecommitdiff
path: root/lisp/shell.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/shell.el')
-rw-r--r--lisp/shell.el52
1 files changed, 35 insertions, 17 deletions
diff --git a/lisp/shell.el b/lisp/shell.el
index 32128241655..5cdc0385a6f 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -110,11 +110,6 @@
"Directory support in shell mode."
:group 'shell)
-;; Unused.
-;;; (defgroup shell-faces nil
-;;; "Faces in shell buffers."
-;;; :group 'shell)
-
;;;###autoload
(defcustom shell-dumb-shell-regexp (purecopy "cmd\\(proxy\\)?\\.exe")
"Regexp to match shells that don't save their command history, and
@@ -326,6 +321,15 @@ Thus, this does not include the shell's current directory.")
(defvar shell-dirstack-query nil
"Command used by `shell-resync-dirs' to query the shell.")
+(defcustom shell-has-auto-cd nil
+ "If non-nil, `shell-mode' handles implicit \"cd\" commands.
+Implicit \"cd\" is changing the directory if the command is a directory.
+You can make this variable buffer-local to change it, per shell-mode instance.
+Useful for shells like zsh that has this feature."
+ :type 'boolean
+ :group 'shell-directories
+ :version "28.1")
+
(defvar shell-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-f" 'shell-forward-command)
@@ -455,6 +459,16 @@ Thus, this does not include the shell's current directory.")
(push (mapconcat #'identity (nreverse arg) "") args)))
(cons (nreverse args) (nreverse begins)))))
+;;;###autoload
+(defun split-string-shell-command (string)
+ "Split STRING (a shell command) into a list of strings.
+General shell syntax, like single and double quoting, as well as
+backslash quoting, is respected."
+ (with-temp-buffer
+ (insert string)
+ (let ((comint-file-name-quote-list shell-file-name-quote-list))
+ (car (shell--parse-pcomplete-arguments)))))
+
(defun shell-command-completion-function ()
"Completion function for shell command names.
This is the value of `pcomplete-command-completion-function' for
@@ -463,7 +477,7 @@ Shell buffers. It implements `shell-completion-execonly' for
(if (pcomplete-match "/")
(pcomplete-here (pcomplete-entries nil
(if shell-completion-execonly
- 'file-executable-p)))
+ #'file-executable-p)))
(pcomplete-here
(nth 2 (shell--command-completion-data)))))
@@ -556,8 +570,7 @@ Variables `comint-output-filter-functions', a hook, and
`comint-scroll-to-bottom-on-input' and `comint-scroll-to-bottom-on-output'
control whether input and output cause the window to scroll to the end of the
buffer."
- (when (called-interactively-p 'any)
- (error "Can't be called interactively; did you mean `shell-script-mode' instead?"))
+ :interactive nil
(setq comint-prompt-regexp shell-prompt-pattern)
(shell-completion-vars)
(setq-local paragraph-separate "\\'")
@@ -744,7 +757,7 @@ Make the shell buffer the current buffer, and return it.
(current-buffer)))
;; The buffer's window must be correctly set when we call comint
;; (so that comint sets the COLUMNS env var properly).
- (pop-to-buffer buffer)
+ (pop-to-buffer-same-window buffer)
(with-connection-local-variables
;; On remote hosts, the local `shell-file-name' might be useless.
@@ -756,7 +769,8 @@ Make the shell buffer the current buffer, and return it.
(file-local-name
(expand-file-name
(read-file-name "Remote shell path: " default-directory
- shell-file-name t shell-file-name)))))
+ shell-file-name t shell-file-name
+ #'file-remote-p)))))
;; Rain or shine, BUFFER must be current by now.
(unless (comint-check-proc buffer)
@@ -842,13 +856,15 @@ Environment variables are expanded, see function `substitute-in-file-name'."
str) ; skip whitespace
(match-end 0)))
(case-fold-search)
- end cmd arg1)
+ end cmd arg1 cmd-subst-fn)
(while (string-match shell-command-regexp str start)
(setq end (match-end 0)
cmd (comint-arguments (substring str start end) 0 0)
arg1 (comint-arguments (substring str start end) 1 1))
(if arg1
(setq arg1 (shell-unquote-argument arg1)))
+ (if shell-has-auto-cd
+ (setq cmd-subst-fn (comint-substitute-in-file-name cmd)))
(cond ((string-match (concat "\\`\\(" shell-popd-regexp
"\\)\\($\\|[ \t]\\)")
cmd)
@@ -865,7 +881,9 @@ Environment variables are expanded, see function `substitute-in-file-name'."
(string-match (concat "\\`\\(" shell-chdrive-regexp
"\\)\\($\\|[ \t]\\)")
cmd))
- (shell-process-cd (comint-substitute-in-file-name cmd))))
+ (shell-process-cd (comint-substitute-in-file-name cmd)))
+ ((and shell-has-auto-cd (file-directory-p cmd-subst-fn))
+ (shell-process-cd cmd-subst-fn)))
(setq start (progn (string-match shell-command-separator-regexp
str end)
;; skip again
@@ -986,7 +1004,7 @@ Environment variables are expanded, see function `substitute-in-file-name'."
The `dirtrack' package provides an alternative implementation of
this feature; see the function `dirtrack-mode'."
- nil nil nil
+ :lighter nil
(setq list-buffers-directory (if shell-dirtrack-mode default-directory))
(if shell-dirtrack-mode
(add-hook 'comint-input-filter-functions #'shell-directory-tracker nil t)
@@ -1181,7 +1199,7 @@ Returns t if successful."
(if data
(prog2 (unless (window-minibuffer-p)
(message "Completing command name..."))
- (apply #'completion-in-region data)))))
+ (completion-in-region (nth 0 data) (nth 1 data) (nth 2 data))))))
(defun shell-command-completion ()
"Return the completion data for the command at point, if any."
@@ -1234,7 +1252,7 @@ Returns t if successful."
(list
start end
(lambda (string pred action)
- (if (string-match "/" string)
+ (if (string-search "/" string)
(completion-file-name-table string pred action)
(complete-with-action action completions string pred)))
:exit-function
@@ -1296,7 +1314,7 @@ Returns non-nil if successful."
(if data
(prog2 (unless (window-minibuffer-p)
(message "Completing variable name..."))
- (apply #'completion-in-region data)))))
+ (completion-in-region (nth 0 data) (nth 1 data) (nth 2 data))))))
(defun shell-environment-variable-completion ()
@@ -1310,7 +1328,7 @@ Returns non-nil if successful."
(looking-at "\\$?[({]*")
(match-end 0)))
(variables (mapcar (lambda (x)
- (substring x 0 (string-match "=" x)))
+ (substring x 0 (string-search "=" x)))
process-environment))
(suffix (pcase (char-before start) (?\{ "}") (?\( ")") (_ ""))))
(list start end variables