Eshell: Move fish completion to separate package
parent
69e484a87f
commit
e8101a0b1b
|
@ -32,7 +32,16 @@ lnn() {
|
|||
fi
|
||||
}
|
||||
|
||||
|
||||
## git-update <repo> <dest-folder>
|
||||
git-update() {
|
||||
if [ -e "$2" ]; then
|
||||
pushd "$2"
|
||||
git pull
|
||||
popd
|
||||
else
|
||||
git clone "$1" "$2"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "==> 'temp' folder"
|
||||
mkdir -pv "$HOME/temp"
|
||||
|
@ -46,13 +55,8 @@ if command -v emacs >/dev/null 2>&1; then
|
|||
echo "==> Emacs extra packages"
|
||||
yes | emacs --batch -l ~/.emacs.d/init.el --eval '(progn (package-refresh-contents) (package-install-selected-packages))'
|
||||
mkdir -pv ~/.emacs.d/site-lisp
|
||||
if [ -e ~/.emacs.d/site-lisp/evil-special-modes ]; then
|
||||
pushd ~/.emacs.d/site-lisp/evil-special-modes
|
||||
git pull
|
||||
popd
|
||||
else
|
||||
git clone https://github.com/Ambrevar/evil-special-modes ~/.emacs.d/site-lisp/evil-special-modes
|
||||
fi
|
||||
git-update https://github.com/Ambrevar/evil-special-modes ~/.emacs.d/site-lisp/evil-special-modes
|
||||
git-update https://github.com/Ambrevar/emacs-fish-completion ~/.emacs.d/site-lisp/fish-completion
|
||||
fi
|
||||
|
||||
echo "==> Go path"
|
||||
|
|
|
@ -190,89 +190,15 @@ See `eshell' for the numeric prefix ARG."
|
|||
(eshell (or arg t))))))
|
||||
|
||||
(when (require 'bash-completion nil t)
|
||||
(defun eshell-bash-completion ()
|
||||
(while (pcomplete-here
|
||||
(nth 2 (bash-completion-dynamic-complete-nocomint (save-excursion (eshell-bol) (point)) (point))))))
|
||||
;; Sometimes `eshell-default-completion-function' does better, e.g. "gcc
|
||||
;; <TAB>" shows .c files.
|
||||
(setq eshell-default-completion-function 'eshell-bash-completion))
|
||||
|
||||
(defun eshell-bash-completion ()
|
||||
(while (pcomplete-here
|
||||
(nth 2 (bash-completion-dynamic-complete-nocomint (save-excursion (eshell-bol) (point)) (point))))))
|
||||
|
||||
;;; TODO: Publish fish completion.
|
||||
;;; If the user fish config change directory on startup, file completion will
|
||||
;;; not be right. One work-around is to add a "cd default-directory" before the
|
||||
;;; "complete", but that's brittle because of unreliable shell escaping.
|
||||
;;; Upstream does not allow for skipping the user config:
|
||||
;;; https://github.com/fish-shell/fish-shell/issues/4165.
|
||||
(defvar fish-completion-command "fish"
|
||||
"The `fish' executable.")
|
||||
|
||||
;; TODO: Make minor mode for buffer-local completion? Probably not worth it.
|
||||
(defun fish-completion-eshell-global-toggle ()
|
||||
"Turn on/off fish shell completion in all future Eshells.
|
||||
Eshell fallbacks on fish whenever it cannot complete normally."
|
||||
(interactive)
|
||||
(if (or (eq eshell-default-completion-function 'fish-completion-eshell-complete)
|
||||
(not (executable-find fish-completion-command)))
|
||||
(progn
|
||||
(setq eshell-default-completion-function (eval (car (get 'eshell-default-completion-function 'standard-value))))
|
||||
(message "fish completion disabled in all future Eshells"))
|
||||
(setq eshell-default-completion-function 'fish-completion-eshell-complete)
|
||||
(message "fish completion enabled in all future Eshells")))
|
||||
|
||||
(defun fish-completion-eshell-toggle ()
|
||||
"Turn on/off fish shell completion in current Eshell.
|
||||
Eshell fallbacks on fish whenever it cannot complete normally."
|
||||
(interactive)
|
||||
(if (or (eq pcomplete-default-completion-function 'fish-completion-eshell-complete)
|
||||
(not (executable-find fish-completion-command)))
|
||||
(progn
|
||||
(setq pcomplete-default-completion-function (eval (car (get 'eshell-default-completion-function 'standard-value))))
|
||||
(message "fish completion disabled in current Eshell"))
|
||||
(setq pcomplete-default-completion-function 'fish-completion-eshell-complete)
|
||||
(message "fish completion enabled in current Eshell")))
|
||||
|
||||
(defun fish-completion-eshell-complete ()
|
||||
"Complete Eshell's prompt with `fish-completion-complete'."
|
||||
(fish-completion-complete (buffer-substring-no-properties
|
||||
(save-excursion (eshell-bol) (point)) (point))))
|
||||
|
||||
(defun fish-completion-complete (raw-prompt)
|
||||
"Complete RAW-PROMPT (any string) using the fish shell."
|
||||
(while (pcomplete-here
|
||||
(let ((comp-list
|
||||
(let* (;; Keep spaces at the end with OMIT-NULLS=nil in `split-string'.
|
||||
(toks (split-string raw-prompt split-string-default-separators nil))
|
||||
;; The first non-empty `car' is the command. Discard
|
||||
;; leading empty strings.
|
||||
(tokens (progn (while (string= (car toks) "")
|
||||
(setq toks (cdr toks)))
|
||||
toks))
|
||||
;; Fish does not support subcommand completion. We make
|
||||
;; a special case of 'sudo' and 'env' since they are
|
||||
;; the most common cases involving subcommands. See
|
||||
;; https://github.com/fish-shell/fish-shell/issues/4093.
|
||||
(prompt (if (not (member (car tokens) '("sudo" "env")))
|
||||
raw-prompt
|
||||
(setq tokens (cdr tokens))
|
||||
(while (and tokens
|
||||
(or (string-match "^-.*" (car tokens))
|
||||
(string-match "=" (car tokens))))
|
||||
;; Skip env/sudo parameters, like LC_ALL=C.
|
||||
(setq tokens (cdr tokens)))
|
||||
(mapconcat 'identity tokens " "))))
|
||||
;; Completion result can be a filename. pcomplete expects
|
||||
;; cannonical file names (i.e. without '~') while fish preserves
|
||||
;; non-cannonical results. If the result contains a directory,
|
||||
;; expand it.
|
||||
(mapcar (lambda (e) (car (split-string e "\t")))
|
||||
(split-string
|
||||
(with-output-to-string
|
||||
(with-current-buffer standard-output
|
||||
(call-process fish-completion-command nil t nil "-c" (format "complete -C'%s'" prompt))))
|
||||
"\n" t)))))
|
||||
(if (and comp-list (file-name-directory (car comp-list)))
|
||||
(pcomplete-dirs-or-entries)
|
||||
comp-list)))))
|
||||
(when (and (executable-find "fish")
|
||||
(require 'fish-completion nil t))
|
||||
(fish-completion-eshell-global-toggle))
|
||||
|
||||
(provide 'init-eshell)
|
||||
|
|
Loading…
Reference in New Issue