-
-
Notifications
You must be signed in to change notification settings - Fork 391
Eshell
pcomplete
is already enabled in Eshell, but we want to add Helm support. Add the following to your init file:
(add-hook 'eshell-mode-hook
(lambda ()
(eshell-cmpl-initialize)
(define-key eshell-mode-map [remap pcomplete] 'helm-esh-pcomplete)
(define-key eshell-mode-map (kbd "M-p") 'helm-eshell-history)))
Now, the TAB
key should provide Helm support for pcomplete
.
When you use sudo
in Eshell, there is no completion on the command you enter after sudo
. This is true regardless of whether Helm is enabled.
To fix this problem, you can define a pcomplete/sudo
function and add it to your configuration.
(defun pcomplete/sudo ()
(let ((prec (pcomplete-arg 'last -1)))
(cond ((string= "sudo" prec)
(while (pcomplete-here*
(funcall pcomplete-command-completion-function)
(pcomplete-arg 'last) t))))))
However, the above example of pcomplete/sudo
will not work in some cases without modifications to some Emacs functions due to unresolved Emacs bugs. To fix this, you can use my pcomplete-extension, which will provide more Helm completions like apt-get
and find
.
You can enhance Emacs pcomplete
by writing your own pcomplete
functions. See my pcomplete-extension for enhanced completions.
Here an example with find
command:
(defun pcomplete/find ()
(let ((prec (pcomplete-arg 'last -1)))
(cond ((and (pcomplete-match "^-" 'last)
(string= "find" prec))
(pcomplete-opt "HLPDO"))
((pcomplete-match "^-" 'last)
(while (pcomplete-here
'("-amin" "-anewer" "-atime" "-cmin" "-cnewer" "-context"
"-ctime" "-daystart" "-delete" "-depth" "-empty" "-exec"
"-execdir" "-executable" "-false" "-fls" "-follow" "-fprint"
"-fprint0" "-fprintf" "-fstype" "-gid" "-group"
"-help" "-ignore_readdir_race" "-ilname" "-iname"
"-inum" "-ipath" "-iregex" "-iwholename"
"-links" "-lname" "-ls" "-maxdepth"
"-mindepth" "-mmin" "-mount" "-mtime"
"-name" "-newer" "-nogroup" "-noignore_readdir_race"
"-noleaf" "-nouser" "-nowarn" "-ok"
"-okdir" "-path" "-perm" "-print"
"-print0" "-printf" "-prune" "-quit"
"-readable" "-regex" "-regextype" "-samefile"
"-size" "-true" "-type" "-uid"
"-used" "-user" "-version" "-warn"
"-wholename" "-writable" "-xdev" "-xtype"))))
((string= "-type" prec)
(while (pcomplete-here (list "b" "c" "d" "p" "f" "l" "s" "D"))))
((string= "-xtype" prec)
(while (pcomplete-here (list "b" "c" "d" "p" "f" "l" "s"))))
((or (string= prec "-exec")
(string= prec "-execdir"))
(while (pcomplete-here* (funcall pcomplete-command-completion-function)
(pcomplete-arg 'last) t))))
(while (pcomplete-here (pcomplete-entries) nil 'identity))))
To search Eshell history with Helm, use the helm-eshell-history
command. The following is an example configuration:
(add-hook 'eshell-mode-hook
(lambda ()
(define-key eshell-mode-map
(kbd "M-p")
'helm-eshell-history)))