1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- (require 'org)
- (require 'eshell)
- (require 'esh-mode)
- (org-add-link-type "eshell" 'org-eshell-open)
- (add-hook 'org-store-link-functions 'org-eshell-store-link)
- (defun org-eshell-open (link)
- "Switch to am eshell buffer and execute a command line.
- The link can be just a command line (executed in the default
- eshell buffer) or a command line prefixed by a buffer name
- followed by a colon."
- (let* ((buffer-and-command
- (if (string-match "\\([A-Za-z0-9-+*]+\\):\\(.*\\)" link)
- (list (match-string 1 link)
- (match-string 2 link))
- (list eshell-buffer-name link)))
- (eshell-buffer-name (car buffer-and-command))
- (command (cadr buffer-and-command)))
- (if (get-buffer eshell-buffer-name)
- (switch-to-buffer eshell-buffer-name)
- (eshell))
- (end-of-buffer)
- (eshell-kill-input)
- (insert command)
- (eshell-send-input)))
- (defun org-eshell-store-link ()
- "Store a link that, when opened, switches back to the current eshell buffer
- and the current working directory."
- (when (eq major-mode 'eshell-mode)
- (let* ((command (concat "cd " dired-directory))
- (link (concat (buffer-name) ":" command)))
- (org-store-link-props
- :link (org-make-link "eshell:" link)
- :description command))))
-
- (provide 'org-eshell)
|