aboutsummaryrefslogtreecommitdiff
path: root/.emacs.local.d/modes/eshell.el
diff options
context:
space:
mode:
authorRaúl Benencia <rul@kalgan.cc>2019-06-23 11:43:30 -0700
committerRaúl Benencia <rul@kalgan.cc>2019-06-23 13:32:01 -0700
commit284c8327c95bb0c71b111ebf95723a35a478295c (patch)
treefaea9db4b1bba00d73d33b2065ed102f88b76b2c /.emacs.local.d/modes/eshell.el
Add emacs config
Diffstat (limited to '.emacs.local.d/modes/eshell.el')
-rw-r--r--.emacs.local.d/modes/eshell.el85
1 files changed, 85 insertions, 0 deletions
diff --git a/.emacs.local.d/modes/eshell.el b/.emacs.local.d/modes/eshell.el
new file mode 100644
index 0000000..c9be093
--- /dev/null
+++ b/.emacs.local.d/modes/eshell.el
@@ -0,0 +1,85 @@
+(setq eshell-history-size 512)
+(setq eshell-prompt-regexp "^.*> ")
+
+(require 'em-hist) ; So the history vars are defined
+(if (boundp 'eshell-save-history-on-exit)
+ (setq eshell-save-history-on-exit t)) ; Don't ask, just save
+(if (boundp 'eshell-ask-to-save-history)
+ (setq eshell-ask-to-save-history 'always)) ; For older(?) version
+
+(defun eshell/ef (fname-regexp &optional dir)
+ (ef fname-regexp (or dir default-directory)))
+
+
+;;; ---- path manipulation
+
+(defun pwd-repl-home (pwd)
+ (interactive)
+ (let* ((home (expand-file-name (getenv "HOME")))
+ (home-len (length home)))
+ (if (and
+ (>= (length pwd) home-len)
+ (equal home (substring pwd 0 home-len)))
+ (concat "~" (substring pwd home-len))
+ pwd)))
+
+(defun curr-dir-git-branch-string (pwd)
+ "Returns current git branch as a string, or the empty string if
+PWD is not in a git repo (or the git command is not found)."
+ (interactive)
+ (when (and (eshell-search-path "git")
+ (locate-dominating-file pwd ".git"))
+ (let ((git-output (shell-command-to-string (concat "git branch | grep '\\*' | sed -e 's/^\\* //'"))))
+ (concat "[g:"
+ (if (> (length git-output) 0)
+ (substring git-output 0 -1)
+ "(no branch)")
+ "] "))))
+
+(defun curr-dir-svn-string (pwd)
+ (interactive)
+ (when (and (eshell-search-path "svn")
+ (locate-dominating-file pwd ".svn"))
+ (concat "[s:"
+ (cond ((string-match-p "/trunk\\(/.*\\)?" pwd)
+ "trunk")
+ ((string-match "/branches/\\([^/]+\\)\\(/.*\\)?" pwd)
+ (match-string 1 pwd))
+ (t
+ "(no branch)"))
+ "] ")))
+
+(setq eshell-prompt-function
+ (lambda ()
+ (concat
+ (or (curr-dir-git-branch-string (eshell/pwd))
+ (curr-dir-svn-string (eshell/pwd)))
+ ((lambda (p-lst)
+ (if (> (length p-lst) 3)
+ (concat
+ (mapconcat (lambda (elm) (if (zerop (length elm)) ""
+ (substring elm 0 1)))
+ (butlast p-lst 3)
+ "/")
+ "/"
+ (mapconcat (lambda (elm) elm)
+ (last p-lst 3)
+ "/"))
+ (mapconcat (lambda (elm) elm)
+ p-lst
+ "/")))
+ (split-string (pwd-repl-home (eshell/pwd)) "/"))
+ "> ")))
+
+;; ; From http://www.emacswiki.org/cgi-bin/wiki.pl/EshellWThirtyTwo
+;; ; Return nil, otherwise you'll see the return from w32-shell-execute
+;; (defun eshell/open (file)
+;; "Invoke (w32-shell-execute \"Open\" FILE) and substitute slashes for
+;; backslashes"
+;; (w32-shell-execute "Open" (substitute ?\\ ?/ (expand-file-name file)))
+;; nil)
+
+(add-hook 'eshell-mode-hook
+ (lambda ()
+ (local-set-key "\C-c\C-q" 'eshell-kill-process)
+ (local-set-key "\C-c\C-k" 'compile)))
nihil fit ex nihilo