summaryrefslogtreecommitdiffstats
path: root/emacs/eshell-init.el
diff options
context:
space:
mode:
authorGravatar Tom Willemsen2012-08-19 00:26:15 +0200
committerGravatar Tom Willemsen2012-08-19 00:26:15 +0200
commitc2efea9e6bb44dde3d4dd559568b48a22407f14f (patch)
tree04c9f06221440a4f62ba5244374b07f84abf182a /emacs/eshell-init.el
parentc93b49d16784cafad5d6144bd2b150a19eb17bef (diff)
downloaddotfiles-c2efea9e6bb44dde3d4dd559568b48a22407f14f.tar.gz
dotfiles-c2efea9e6bb44dde3d4dd559568b48a22407f14f.zip
emacs/Makefile, emacs/eshell-init.el, emacs/init.el
Diffstat (limited to 'emacs/eshell-init.el')
-rw-r--r--emacs/eshell-init.el63
1 files changed, 63 insertions, 0 deletions
diff --git a/emacs/eshell-init.el b/emacs/eshell-init.el
new file mode 100644
index 0000000..1dd8773
--- /dev/null
+++ b/emacs/eshell-init.el
@@ -0,0 +1,63 @@
+;; Eshell settings
+(eval-when-compile
+ '(load "init.el"))
+
+(eval-after-load "em-term"
+ '(add-to-list 'eshell-visual-commands
+ "unison"))
+
+(defun oni:eshell-mode-func ()
+ "Function for `eshell-mode-hook'."
+ (setq truncate-lines nil))
+
+(defun oni:eshell-prompt-function ()
+ (let ((status (if (zerop eshell-last-command-status) ?+ ?-))
+ (hostname (shell-command-to-string "hostname"))
+ (dir (abbreviate-file-name (eshell/pwd)))
+ (branch
+ (shell-command-to-string
+ "git branch --contains HEAD 2>/dev/null | sed -e '/^[^*]/d'"))
+ (userstatus (if (zerop (user-uid)) ?# ?$)))
+ (concat
+ (propertize (char-to-string status)
+ 'face `(:foreground ,(if (= status ?+)
+ (oni:color chameleon-1)
+ (oni:color scarlet-red-2))))
+ " "
+ (propertize (substring hostname 0 -1) 'face 'mode-line-buffer-id)
+ " "
+ (propertize (oni:shorten-dir dir) 'face 'font-lock-string-face)
+ " "
+ (propertize (when (not (string= branch ""))
+ ;; Cut off "* " and "\n"
+ (substring branch 2 -1))
+ 'face 'font-lock-function-name-face)
+ " \n"
+ (propertize (char-to-string userstatus)
+ 'face `(:foreground ,(oni:color sky-blue-1)))
+ "> ")))
+
+;;;###autoload
+(defun oni:raise-eshell ()
+ "Start or switch back to `eshell'. Also change directories to
+ current working directory."
+ (interactive)
+ (let ((dir (file-name-directory
+ (or (buffer-file-name) "~/")))
+ (hasfile (not (eq (buffer-file-name) nil))))
+ (eshell)
+ (if (and hasfile (eq eshell-process-list nil))
+ (progn
+ (eshell/cd dir)
+ (eshell-reset)))))
+
+(defun oni:shorten-dir (dir)
+ "Shorten a directory, (almost) like fish does it."
+ (while (string-match "\\(/\\.?.\\)[^/]+/" dir)
+ (setq dir (replace-match "\\1/" nil nil dir)))
+ dir)
+
+(setq eshell-prompt-regexp "^[#$]> ")
+(setq eshell-highlight-prompt nil)
+(setq eshell-prompt-function 'oni:eshell-prompt-function)
+(add-hook 'eshell-mode-hook 'oni:eshell-mode-func)