summaryrefslogtreecommitdiff
path: root/lisp/init-eshell.el
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2014-10-22 17:24:25 +0200
committerrekado <rekado@elephly.net>2014-10-22 17:25:07 +0200
commit0d4d28dc8b459d9c29db69499f6aca165820338e (patch)
tree5c3462eda95232569a3ac76868e9897127f8c5d3 /lisp/init-eshell.el
parent35e4d21f006d5fc0103031a98fa4c7bfe1f117cc (diff)
move init files to lisp directory
Diffstat (limited to 'lisp/init-eshell.el')
-rw-r--r--lisp/init-eshell.el68
1 files changed, 68 insertions, 0 deletions
diff --git a/lisp/init-eshell.el b/lisp/init-eshell.el
new file mode 100644
index 0000000..d87d0e7
--- /dev/null
+++ b/lisp/init-eshell.el
@@ -0,0 +1,68 @@
+(require 'eshell)
+(require 'shell-switcher)
+(setq shell-switcher-mode t)
+(add-hook 'eshell-mode-hook 'shell-switcher-manually-register-shell)
+(setq eshell-history-size 10000)
+
+;; author: KaiGrossjohann on EmacsWiki
+(defun eshell/ff (&rest args)
+ "Invoke `find-file' on the file.
+ \"ff +42 foo\" also goes to line 42 in the buffer."
+ (while args
+ (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
+ (let* ((line (string-to-number (match-string 1 (pop args))))
+ (file (pop args)))
+ (find-file file)
+ (goto-line line))
+ (find-file (pop args)))))
+
+
+;; convenience functions to input the remote root/home dir when in a
+;; directory on a remote host
+(defun my/tramp-root ()
+ "Print root directory on the remote host."
+ (interactive)
+ (let ((pieces (split-string (eshell/pwd) ":/")))
+ (insert-string (if (> (length pieces) 1)
+ (concat (car pieces) ":/")
+ "/"))))
+
+(defun my/tramp-home ()
+ "Print home directory path on the remote host."
+ (interactive)
+ (let ((pieces (split-string (eshell/pwd) ":/")))
+ (insert-string (if (> (length pieces) 1)
+ (concat (car pieces) ":~/")
+ "~/"))))
+
+(add-hook 'eshell-mode-hook
+ '(lambda () (define-key eshell-mode-map (kbd "C-c /") 'my/tramp-root)))
+(add-hook 'eshell-mode-hook
+ '(lambda () (define-key eshell-mode-map (kbd "C-c ~") 'my/tramp-home)))
+
+
+;; start a hidden eshell on startup
+(add-hook 'emacs-startup-hook #'(lambda ()
+ (let ((default-directory (getenv "HOME")))
+ (command-execute 'eshell)
+ (bury-buffer))))
+
+;; use cat as the pager in shell mode, because shell-mode is not an ANSI terminal
+(setenv "PAGER" "cat")
+
+;; C-d on an empty line in the shell terminates the process.
+(defun my/comint-delchar-or-eof-or-kill-buffer (arg)
+ (interactive "p")
+ (if (null (get-buffer-process (current-buffer)))
+ (kill-buffer)
+ (comint-delchar-or-maybe-eof arg)))
+
+(add-hook 'shell-mode-hook
+ (lambda ()
+ (define-key shell-mode-map
+ (kbd "C-d") 'my/comint-delchar-or-eof-or-kill-buffer)))
+;; TODO: this isn't working
+(add-hook 'term-mode-hook
+ (lambda ()
+ (define-key term-mode-map
+ (kbd "C-d") 'my/comint-delchar-or-eof-or-kill-buffer)))