blob: 137c5b0e9abc7c9aecc1d48d12bc51f8596633f8 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
;;; terminal-here.el --- Run an external terminal in current directory -*- lexical-binding: t; -*-
;; Copyright (C) 2015 Free Software Foundation, Inc.
;; Author: David Shepherd <davidshepherd7@gmail.com>
;; Version: 0.1
;; Package-Requires: ((emacs "24"))
;; Keywords: tools, frames
;; URL: https://github.com/davidshepherd7/terminal-here
;;; Commentary:
;; An Emacs package to help open external terminal emulators in the directory of
;; the current buffer. See the readme.md file for more details.
;;; Code:
(defun terminal-here--default-terminal-command ()
"Pick a good default command to use."
(cond
((eq system-type 'darwin)
(lambda (dir) (list "open" "-a" "Terminal.app" dir)))
((or (eq system-type 'windows-nt) (eq system-type 'ms-dos) (eq system-type 'cygwin))
(lambda (dir) (list "start" "/D" dir "cmd")))
;; Probably X11!
(t '("x-terminal-emulator"))))
(defcustom terminal-here-terminal-command
(terminal-here--default-terminal-command)
"The command used to start a terminal.
Either a list of strings: (terminal-binary arg1 arg2 ...); or a
function taking a directory and returning such a list."
:group 'terminal-here
:type '(choice (repeat string)
(function)))
(defun terminal-here-launch-in-directory (dir)
"Launch a terminal in directory DIR."
(let* ((term-command (if (functionp terminal-here-terminal-command)
(funcall terminal-here-terminal-command dir)
terminal-here-terminal-command))
(process-name (car term-command))
(default-directory dir))
(apply #'start-process process-name nil term-command)))
;;;###autoload
(defun terminal-here-launch ()
"Launch a terminal in the current working directory.
This is the directory of the current buffer unless you have
changed it by running `cd'."
(interactive)
(terminal-here-launch-in-directory default-directory))
;;;###autoload
(defun terminal-here-project-launch ()
"Launch a terminal in the current project root.
If projectile is installed the projectile root will be used,
Otherwise `vc-root-dir' will be used."
(interactive)
(terminal-here-launch-in-directory (cond
((and (functionp 'projectile-project-root) (projectile-project-root)))
((and (functionp 'vc-root-dir) (vc-root-dir)))
(t (signal 'user-error "Failed to detect project root, if you are in a version-controlled project try installing projectile or upgrading to emacs 25")))))
(provide 'terminal-here)
;;; terminal-here.el ends here
|