(defvar shell-file-name-chars
(if (memq system-type '(ms-dos windows-nt cygwin))
"~/A-Za-z0-9_^$!#%&{}@`'.,:()-"
- "~/A-Za-z0-9+@:_.$#%,={}-")
+ "[]~/A-Za-z0-9+@:_.$#%,={}-")
"String of characters valid in a file name.
This variable is used to initialize `comint-file-name-chars' in the
shell buffer. The value may depend on the operating system or shell.
(defvar shell-file-name-quote-list
(if (memq system-type '(ms-dos windows-nt))
nil
- (append shell-delimiter-argument-list '(?\ ?\* ?\! ?\" ?\' ?\` ?\#)))
+ (append shell-delimiter-argument-list '(?\ ?\* ?\! ?\" ?\' ?\` ?\# ?\\)))
"List of characters to quote when in a file name.
This variable is used to initialize `comint-file-name-quote-list' in the
shell buffer. The value may depend on the operating system or shell.
: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.
(setq shell-dirstack-query
(cond ((string-equal shell "sh") "pwd")
((string-equal shell "ksh") "echo $PWD ~-")
- (t "dirs"))))
+ (t "dirs")))
+ ;; Bypass a bug in certain versions of bash.
+ (when (string-equal shell "bash")
+ (add-hook 'comint-output-filter-functions
+ 'shell-filter-ctrl-a-ctrl-b nil t)))
(comint-read-input-ring t)))
+(defun shell-filter-ctrl-a-ctrl-b (string)
+ "Remove `^A' and `^B' characters from comint output.
+
+Bash uses these characters as internal quoting characters in its
+prompt. Due to a bug in some bash versions (including 2.03,
+2.04, and 2.05b), they may erroneously show up when bash is
+started with the `--noediting' option and Select Graphic
+Rendition (SGR) control sequences (formerly known as ANSI escape
+sequences) are used to color the prompt.
+
+This function can be put on `comint-output-filter-functions'.
+The argument STRING is ignored."
+ (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
+ (save-excursion
+ (goto-char (or comint-last-output-start (point-min)))
+ (while (re-search-forward "[\C-a\C-b]" pmark t)
+ (replace-match "")))))
+
(defun shell-write-history-on-exit (process event)
"Called when the shell process is stopped.
(interactive
(list
(and current-prefix-arg
- (read-buffer "Shell buffer: " "*shell*"))))
+ (read-buffer "Shell buffer: "
+ (generate-new-buffer-name "*shell*")))))
(setq buffer (get-buffer-create (or buffer "*shell*")))
;; Pop to buffer, so that the buffer's window will be correctly set
;; when we call comint (so that comint sets the COLUMNS env var properly).
(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)
"\\)\\($\\|[ \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"))))
(let ((pt (point))) ; wait for 1 line
;; This extra newline prevents the user's pending input from spoofing us.
(insert "\n") (backward-char 1)
- (while (not (looking-at ".+\n"))
+ (while (not (looking-at
+ (concat "\\(" ; skip literal echo in case of stty echo
+ (regexp-quote shell-dirstack-query)
+ "\n\\)?" ; skip if present
+ "\\(" ".+\n" "\\)")) ) ; what to actually look for
(accept-process-output proc)
(goto-char pt)))
(goto-char pmark) (delete-char 1) ; remove the extra newline
;; That's the dirlist. grab it & parse it.
- (let* ((dl (buffer-substring (match-beginning 0) (1- (match-end 0))))
+ (let* ((dl (buffer-substring (match-beginning 2) (1- (match-end 2))))
(dl-len (length dl))
(ds '()) ; new dir stack
(i 0))
"Dynamically complete at point as a command.
See `shell-dynamic-complete-filename'. Returns t if successful."
(let* ((filename (or (comint-match-partial-filename) ""))
- (pathnondir (file-name-nondirectory filename))
- (paths (cdr (reverse exec-path)))
+ (filenondir (file-name-nondirectory filename))
+ (path-dirs (cdr (reverse exec-path)))
(cwd (file-name-as-directory (expand-file-name default-directory)))
(ignored-extensions
(and comint-completion-fignore
(mapconcat (function (lambda (x) (concat (regexp-quote x) "$")))
comint-completion-fignore "\\|")))
- (path "") (comps-in-path ()) (file "") (filepath "") (completions ()))
- ;; Go thru each path in the search path, finding completions.
- (while paths
- (setq path (file-name-as-directory (comint-directory (or (car paths) ".")))
- comps-in-path (and (file-accessible-directory-p path)
- (file-name-all-completions pathnondir path)))
+ (dir "") (comps-in-dir ())
+ (file "") (abs-file-name "") (completions ()))
+ ;; Go thru each dir in the search path, finding completions.
+ (while path-dirs
+ (setq dir (file-name-as-directory (comint-directory (or (car path-dirs) ".")))
+ comps-in-dir (and (file-accessible-directory-p dir)
+ (file-name-all-completions filenondir dir)))
;; Go thru each completion found, to see whether it should be used.
- (while comps-in-path
- (setq file (car comps-in-path)
- filepath (concat path file))
+ (while comps-in-dir
+ (setq file (car comps-in-dir)
+ abs-file-name (concat dir file))
(if (and (not (member file completions))
(not (and ignored-extensions
(string-match ignored-extensions file)))
- (or (string-equal path cwd)
- (not (file-directory-p filepath)))
+ (or (string-equal dir cwd)
+ (not (file-directory-p abs-file-name)))
(or (null shell-completion-execonly)
- (file-executable-p filepath)))
+ (file-executable-p abs-file-name)))
(setq completions (cons file completions)))
- (setq comps-in-path (cdr comps-in-path)))
- (setq paths (cdr paths)))
+ (setq comps-in-dir (cdr comps-in-dir)))
+ (setq path-dirs (cdr path-dirs)))
;; OK, we've got a list of completions.
(let ((success (let ((comint-completion-addsuffix nil))
- (comint-dynamic-simple-complete pathnondir completions))))
+ (comint-dynamic-simple-complete filenondir completions))))
(if (and (memq success '(sole shortest)) comint-completion-addsuffix
(not (file-directory-p (comint-match-partial-filename))))
(insert " "))
(provide 'shell)
+;;; arch-tag: bcb5f12a-c1f4-4aea-a809-2504bd5bd797
;;; shell.el ends here