about summary refs log tree commit diff
path: root/init/eshell-setup.el
diff options
context:
space:
mode:
authorVincent Ambo <vincent@kivra.com>2014-10-21T17·37+0200
committerVincent Ambo <vincent@kivra.com>2014-10-21T17·37+0200
commit1f70abb1769a3528f23bc96ee3f570338ace50d3 (patch)
tree9517f6eab292a13cdd4a4cfb7768471aace41a3c /init/eshell-setup.el
parent10057a887b931b25d93691992c35665cac277fcb (diff)
Move all configuration to subfolder
Diffstat (limited to 'init/eshell-setup.el')
-rw-r--r--init/eshell-setup.el92
1 files changed, 92 insertions, 0 deletions
diff --git a/init/eshell-setup.el b/init/eshell-setup.el
new file mode 100644
index 000000000000..43b1c16b33d6
--- /dev/null
+++ b/init/eshell-setup.el
@@ -0,0 +1,92 @@
+;; EShell configuration
+
+(require 'eshell)
+
+;; Generic settings
+;; Hide banner message ...
+(setq eshell-banner-message "")
+
+(defun eshell-mode-hook-setup ()
+  "Sets up EShell when it is loaded"
+  (setq eshell-path-env (concat
+			 "/usr/local/bin:"
+			 (concat home-dir "/bin:")
+			 "/usr/local/share/python:"
+                         "/opt/java/bin"
+			 eshell-path-env))
+
+  (setenv "PATH" eshell-path-env))
+
+(add-hook 'eshell-mode-hook 'eshell-mode-hook-setup)
+
+;; Prompt configuration
+
+(defun clean-pwd (path)
+  "Turns a path of the form /foo/bar/baz into /f/b/baz
+   (inspired by fish shell)"
+  (let* ((hpath (replace-regexp-in-string home-dir
+                                          "~"
+                                          path))
+         (current-dir (split-string hpath "/"))
+	 (cdir (last current-dir))
+	 (head (butlast current-dir)))
+    (concat (mapconcat (lambda (s)
+			 (if (string= "" s) nil
+			   (substring s 0 1)))
+		       head
+		       "/")
+	    (if head "/" nil)
+	    (car cdir))))
+
+(defun vcprompt (&optional args)
+  "Call the external vcprompt command with optional arguments.
+   VCPrompt"
+  (replace-regexp-in-string
+   "\n" ""
+   (shell-command-to-string (concat  "vcprompt" args))))
+
+(defmacro with-face (str &rest properties)
+  `(propertize ,str 'face (list ,@properties)))
+
+(defun prompt-f ()
+  "My EShell prompt displaying VC info and such"
+  (concat
+   (with-face (concat (clean-pwd (eshell/pwd)) " ") :foreground  "#96a6c8")
+   ;(with-face (vcprompt " -f \"(%s:%b%a%m) \"") :foreground "#5f627f")
+   (if (= 0 (user-uid))
+       (with-face "#" :foreground "#f43841")
+     (with-face "$" :foreground "#73c936"))
+   (with-face " " :foreground "#95a99f")))
+
+
+(setq eshell-prompt-function 'prompt-f)
+(setq eshell-highlight-prompt nil)
+(setq eshell-prompt-regexp "^.+? \\((\\(git\\|svn\\|hg\\|darcs\\|cvs\\|bzr\\):.+?) \\)?[$#] ")
+
+;; Ignore version control folders in autocompletion
+(setq eshell-cmpl-cycle-completions nil
+      eshell-save-history-on-exit t
+      eshell-cmpl-dir-ignore "\\`\\(\\.\\.?\\|CVS\\|\\.svn\\|\\.git\\)/\\'")
+
+;; Load some EShell extensions
+(eval-after-load 'esh-opt
+  '(progn
+     (require 'em-term)
+     (require 'em-cmpl)
+     ;; More visual commands!
+     (add-to-list 'eshell-visual-commands "ssh")
+     (add-to-list 'eshell-visual-commands "tail")
+     (add-to-list 'eshell-visual-commands "sl")))
+
+(setq eshell-directory-name "~/.config/eshell/")
+
+;; EShell functions that come in handy
+
+;; clear in eshell
+(defun eshell/clear ()
+  "clear the eshell buffer."
+  (interactive)
+  (let ((inhibit-read-only t))
+    (erase-buffer)))
+
+(provide 'eshell-setup)