2017-12-03 09:19:05 +01:00
|
|
|
|
;;; db-eshell --- Configuration for eshell -*- lexical-binding: t -*-
|
2017-08-06 14:08:25 +02:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2018-01-24 19:29:57 +01:00
|
|
|
|
;; Parts inspired by:
|
|
|
|
|
;; - https://www.masteringemacs.org/article/complete-guide-mastering-eshell
|
|
|
|
|
;; - https://github.com/howardabrams/dot-files/blob/master/emacs-eshell.org
|
2017-08-06 14:08:25 +02:00
|
|
|
|
|
2018-01-24 19:29:57 +01:00
|
|
|
|
;;; Code:
|
2017-08-06 14:08:25 +02:00
|
|
|
|
|
|
|
|
|
|
2018-11-03 12:01:34 +01:00
|
|
|
|
;; Various
|
2017-08-06 14:08:25 +02:00
|
|
|
|
|
|
|
|
|
(defun eshell-clear-buffer ()
|
|
|
|
|
"Clear terminal."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(eshell-send-input)))
|
|
|
|
|
|
2018-07-19 13:49:26 +02:00
|
|
|
|
(defun eshell/default-prompt-function ()
|
|
|
|
|
"A prompt for eshell of the form
|
|
|
|
|
|
2018-07-19 14:30:01 +02:00
|
|
|
|
┌─[$USER@$HOST] [$PWD]
|
|
|
|
|
└─
|
2018-07-19 13:49:26 +02:00
|
|
|
|
|
|
|
|
|
"
|
|
|
|
|
(let ((head-face '(:foreground "#859900")))
|
2018-07-19 14:30:01 +02:00
|
|
|
|
(format (concat (propertize "┌─" 'face head-face)
|
2018-07-20 14:26:34 +02:00
|
|
|
|
"%s@%s %s\n"
|
2018-07-19 14:30:01 +02:00
|
|
|
|
(propertize "└─" 'face head-face)
|
2018-07-20 14:26:34 +02:00
|
|
|
|
(if (zerop (user-uid)) "#" "$")
|
2018-07-19 14:30:01 +02:00
|
|
|
|
(propertize " " 'face '(:weight bold)))
|
2018-07-19 13:49:26 +02:00
|
|
|
|
(user-login-name)
|
|
|
|
|
(system-name)
|
|
|
|
|
(propertize (abbreviate-file-name (eshell/pwd))
|
|
|
|
|
'face '(:foreground "#dc322f")))))
|
|
|
|
|
|
2018-07-19 13:50:02 +02:00
|
|
|
|
(defun eshell/gst (&rest args)
|
|
|
|
|
(magit-status (pop args) nil)
|
|
|
|
|
(eshell/echo))
|
|
|
|
|
|
2018-07-19 14:02:44 +02:00
|
|
|
|
(defun eshell-insert-history ()
|
|
|
|
|
"Displays the eshell history to select and insert back into your eshell."
|
|
|
|
|
;; directly taken from Howard Abrams
|
|
|
|
|
(interactive)
|
|
|
|
|
(insert (completing-read "Eshell history: "
|
2018-11-03 12:09:54 +01:00
|
|
|
|
(seq-uniq (ring-elements eshell-history-ring)))))
|
2018-07-19 14:02:44 +02:00
|
|
|
|
|
2017-08-06 14:08:25 +02:00
|
|
|
|
|
2018-10-20 14:53:47 +02:00
|
|
|
|
;; Git Completion
|
|
|
|
|
;; https://tsdh.wordpress.com/2013/05/31/eshell-completion-for-git-bzr-and-hg/
|
|
|
|
|
|
2017-08-06 14:08:25 +02:00
|
|
|
|
(defun pcmpl-git-commands ()
|
|
|
|
|
"Return the most common git commands by parsing the git output."
|
|
|
|
|
(with-temp-buffer
|
2018-01-24 19:29:42 +01:00
|
|
|
|
(if (not (zerop (call-process "git" nil (current-buffer) nil "help" "--all")))
|
|
|
|
|
(warn "Cannot call `git’ to obtain list of available commands; completion won’t be available.")
|
|
|
|
|
(goto-char 0)
|
|
|
|
|
(search-forward "available git commands in")
|
|
|
|
|
(let (commands)
|
|
|
|
|
(while (re-search-forward
|
|
|
|
|
"^[[:blank:]]+\\([[:word:]-.]+\\)[[:blank:]]*\\([[:word:]-.]+\\)?"
|
|
|
|
|
nil t)
|
|
|
|
|
(push (match-string 1) commands)
|
|
|
|
|
(when (match-string 2)
|
|
|
|
|
(push (match-string 2) commands)))
|
|
|
|
|
(sort commands #'string<)))))
|
2017-08-06 14:08:25 +02:00
|
|
|
|
|
|
|
|
|
(defconst pcmpl-git-commands (pcmpl-git-commands)
|
|
|
|
|
"List of `git' commands.")
|
|
|
|
|
|
|
|
|
|
(defvar pcmpl-git-ref-list-cmd "git for-each-ref refs/ --format='%(refname)'"
|
|
|
|
|
"The `git' command to run to get a list of refs.")
|
|
|
|
|
|
|
|
|
|
(defun pcmpl-git-get-refs (type)
|
|
|
|
|
"Return a list of `git' refs filtered by TYPE."
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert (shell-command-to-string pcmpl-git-ref-list-cmd))
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(let (refs)
|
|
|
|
|
(while (re-search-forward (concat "^refs/" type "/\\(.+\\)$") nil t)
|
|
|
|
|
(push (match-string 1) refs))
|
|
|
|
|
(nreverse refs))))
|
|
|
|
|
|
|
|
|
|
(defun pcmpl-git-remotes ()
|
|
|
|
|
"Return a list of remote repositories."
|
|
|
|
|
(split-string (shell-command-to-string "git remote")))
|
|
|
|
|
|
|
|
|
|
(defun pcomplete/git ()
|
|
|
|
|
"Completion for `git'."
|
|
|
|
|
;; Completion for the command argument.
|
|
|
|
|
(pcomplete-here* pcmpl-git-commands)
|
|
|
|
|
(cond
|
|
|
|
|
((pcomplete-match "help" 1)
|
|
|
|
|
(pcomplete-here* pcmpl-git-commands))
|
|
|
|
|
((pcomplete-match (regexp-opt '("pull" "push")) 1)
|
|
|
|
|
(pcomplete-here (pcmpl-git-remotes)))
|
|
|
|
|
;; provide branch completion for the command `checkout'.
|
|
|
|
|
((pcomplete-match (regexp-opt '("checkout" "co")) 1)
|
|
|
|
|
(pcomplete-here* (append (pcmpl-git-get-refs "heads")
|
|
|
|
|
(pcmpl-git-get-refs "tags"))))
|
|
|
|
|
(t
|
|
|
|
|
(while (pcomplete-here (pcomplete-entries))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; End
|
|
|
|
|
|
|
|
|
|
(provide 'db-eshell)
|
2018-11-03 12:01:34 +01:00
|
|
|
|
|
2017-08-06 14:08:25 +02:00
|
|
|
|
;;; db-eshell ends here
|