diff --git a/lisp/shell.el b/lisp/shell.el index 9905fde3712..fdf80cba220 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -202,6 +202,12 @@ This is used for directory tracking and does not do a perfect job." :type 'regexp :group 'shell) +(defcustom shell-command-separator-regexp "[;&|\n \t]*" + "*Regexp to match a single command within a pipeline. +This is used for directory tracking and does not do a perfect job." + :type 'regexp + :group 'shell) + (defcustom shell-completion-execonly t "*If non-nil, use executable files only for completion candidates. This mirrors the optional behavior of tcsh. @@ -608,7 +614,9 @@ Environment variables are expanded, see function `substitute-in-file-name'." (if shell-dirtrackp ;; We fail gracefully if we think the command will fail in the shell. (condition-case chdir-failure - (let ((start (progn (string-match "^[; \t]*" str) ; skip whitespace + (let ((start (progn (string-match + (concat "^" shell-command-separator-regexp) + str) ; skip whitespace (match-end 0))) end cmd arg1) (while (string-match shell-command-regexp str start) @@ -634,7 +642,9 @@ Environment variables are expanded, see function `substitute-in-file-name'." "\\)\\($\\|[ \t]\\)") cmd)) (shell-process-cd (comint-substitute-in-file-name cmd)))) - (setq start (progn (string-match "[; \t]*" str end) ; skip again + (setq start (progn (string-match shell-command-separator-regexp + str end) + ;; skip again (match-end 0))))) (error "Couldn't cd"))))