From f4c8a00a281a1afaecc72cb4e6369172a290a1c1 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sun, 6 Aug 2017 14:08:25 +0200 Subject: [PATCH] [EShell] Move configuration to dedicated package Not clear whether this is a good idea, though. --- init.el | 105 +----------------------------------- site-lisp/db-eshell.el | 118 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 104 deletions(-) create mode 100644 site-lisp/db-eshell.el diff --git a/init.el b/init.el index 07644e2..3eb2842 100644 --- a/init.el +++ b/init.el @@ -934,110 +934,7 @@ _h_ _l_ _o_k _y_ank (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on) (add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m))) -(use-package eshell - :commands (eshell) - :config (progn - - (require 'em-prompt) - (require 'em-term) - (require 'em-cmpl) - - (setq eshell-cmpl-cycle-completions nil - eshell-save-history-on-exit t - eshell-scroll-to-bottom-on-input t - eshell-prefer-lisp-functions nil) - - (setenv "PAGER" "cat") - - (defun eshell-clear-buffer () - "Clear terminal." - (interactive) - (let ((inhibit-read-only t)) - (erase-buffer) - (eshell-send-input))) - - ;; eshell is a bit strange and sets up its mode map as a local map; - ;; because of this we need to put key definitions into a hook - (add-hook 'eshell-mode-hook - (lambda () - (bind-key "C-a" #'eshell-bol eshell-mode-map) - (bind-key "C-l" #'eshell-clear-buffer eshell-mode-map))) - - (add-to-list 'eshell-command-completions-alist - '("gunzip" "gz\\'")) - - (add-to-list 'eshell-command-completions-alist - '("tar" "\\(\\.tar|\\.tgz\\|\\.tar\\.gz\\)\\'")) - - (setq eshell-prompt-function - (lambda () - (concat - "[" (user-login-name) - "@" (getenv "HOST") - ":" (abbreviate-file-name (eshell/pwd)) - "]\n→ ")) - eshell-prompt-regexp - "^→ ") - - (add-hook 'eshell-mode-hook - (lambda () - (add-hook 'eshell-output-filter-functions 'eshell-truncate-buffer))) - - ;; Git Completion - ;; https://tsdh.wordpress.com/2013/05/31/eshell-completion-for-git-bzr-and-hg/ - - (require 'pcomplete) - - (defun pcmpl-git-commands () - "Return the most common git commands by parsing the git output." - (with-temp-buffer - (call-process "git" nil (current-buffer) nil "help" "--all") - (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<)))) - - (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)))))))) +(use-package db-eshell) ;; * Lisp diff --git a/site-lisp/db-eshell.el b/site-lisp/db-eshell.el new file mode 100644 index 0000000..eb6fe72 --- /dev/null +++ b/site-lisp/db-eshell.el @@ -0,0 +1,118 @@ +;;; db-eshell --- Configuration for eshell + +;;; Commentary: + +;;; Code: + + +;; Setup + +(require 'em-prompt) +(require 'em-term) +(require 'em-cmpl) + + +;; Customization + +(setq eshell-cmpl-cycle-completions nil + eshell-scroll-to-bottom-on-input t + eshell-prefer-lisp-functions nil) + +(setenv "PAGER" "cat") + +(defun eshell-clear-buffer () + "Clear terminal." + (interactive) + (let ((inhibit-read-only t)) + (erase-buffer) + (eshell-send-input))) + +;; eshell is a bit strange and sets up its mode map as a local map; +;; because of this we need to put key definitions into a hook +(add-hook 'eshell-mode-hook + (lambda () + (bind-key "C-a" #'eshell-bol eshell-mode-map) + (bind-key "C-l" #'eshell-clear-buffer eshell-mode-map))) + +(add-to-list 'eshell-command-completions-alist + '("gunzip" "gz\\'")) + +(add-to-list 'eshell-command-completions-alist + '("tar" "\\(\\.tar|\\.tgz\\|\\.tar\\.gz\\)\\'")) + +(setq eshell-prompt-function + (lambda () + (concat + "[" (user-login-name) + "@" (getenv "HOST") + ":" (abbreviate-file-name (eshell/pwd)) + "]\n→ ")) + eshell-prompt-regexp + "^→ ") + +(add-hook 'eshell-mode-hook + (lambda () + (add-hook 'eshell-output-filter-functions 'eshell-truncate-buffer))) + + +;; Git Completion +;; https://tsdh.wordpress.com/2013/05/31/eshell-completion-for-git-bzr-and-hg/ + +(require 'pcomplete) + +(defun pcmpl-git-commands () + "Return the most common git commands by parsing the git output." + (with-temp-buffer + (call-process "git" nil (current-buffer) nil "help" "--all") + (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<)))) + +(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) +;;; db-eshell ends here