1 ;;; org-eshell.el - Support for links to working directories in eshell
2 ;; Copyright (C) 2011 Free Software Foundation, Inc.
4 ;; Author: Konrad Hinsen <konrad.hinsen AT fastmail.net>
7 ;; This file is not part of GNU Emacs.
9 ;; Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 (org-add-link-type "eshell" 'org-eshell-open
)
30 (add-hook 'org-store-link-functions
'org-eshell-store-link
)
32 (defun org-eshell-open (link)
33 "Switch to am eshell buffer and execute a command line.
34 The link can be just a command line (executed in the default
35 eshell buffer) or a command line prefixed by a buffer name
37 (let* ((buffer-and-command
38 (if (string-match "\\([A-Za-z0-9-+*]+\\):\\(.*\\)" link
)
39 (list (match-string 1 link
)
40 (match-string 2 link
))
41 (list eshell-buffer-name link
)))
42 (eshell-buffer-name (car buffer-and-command
))
43 (command (cadr buffer-and-command
)))
44 (if (get-buffer eshell-buffer-name
)
45 (switch-to-buffer eshell-buffer-name
)
52 (defun org-eshell-store-link ()
53 "Store a link that, when opened, switches back to the current eshell buffer
54 and the current working directory."
55 (when (eq major-mode
'eshell-mode
)
56 (let* ((command (concat "cd " dired-directory
))
57 (link (concat (buffer-name) ":" command
)))
59 :link
(org-make-link "eshell:" link
)
60 :description command
))))
65 ;;; org-eshell.el ends here