-
Notifications
You must be signed in to change notification settings - Fork 88
/
em.sh
executable file
·181 lines (133 loc) · 3.6 KB
/
em.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env sh
#
# Emacs Client Wrapper
#
# It helps to manage Emacs client and daemon.
#
#
#
#
#-----------------------------------------------
BROWSER=chromium-browser
function emacs_eval () {
echo "$1"
emacsclient -a "" -n --eval $1
}
function emacs_start () {
emacs --daemon
}
function emacs_shutdown () {
emacsclient --eval "(kill-emacs)"
}
case "$1" in
# Start Emacs Server
-start)
emacs_start
;;
-stop)
emacs_shutdown
;;
-restart)
emacsclient --eval "(kill-emacs)"
emacs --daemon ;;
# Open Emacs Frame (GUI)
-gui)
if [ -z "$2"] ;
then
emacsclient -a "" -c &
else
emacsclient -a "" -c "$2" &
fi
;;
# Open Emacs in Terminal
-cli)
if [ -z "$2"] ;
then
emacsclient -a "" -t
else
emacsclient -a "" -t "$2"
fi
;;
# Edit file without enter CLI or GUI interface.
-edit)
emacsclient -a "" -n "$2"
;;
# Execute Command (Eval)
-eval)
emacsclient -a "" -n --eval "$2"
;;
-eval-frame)
emacsclient -a "" -n --eval "(with-selected-frame (make-frame) (eval \"$2\"))"
;;
-open)
emacsclient -a "" -n --eval "(find-file \"$2\")"
;;
# Load Emacs Lisp Source
-load)
emacsclient -a "" -n --eval "(load \"$2\")" ;;
# Browser man page in terminal
-man)
emacsclient -a "" -t -e "(woman \"$2\")" ;;
-manual)
$BROWSER "http://www.gnu.org/software/emacs/manual" ;;
-show)
case "$2" in
load-path)
emacsclient -a "" --eval "load-path" \
| sed 's/["|\)|\(]//g' | sed 's/\s/\n/g'
;;
exec-path)
emacsclient -a "" --eval "exec-path" \
| sed 's/["|\)|\(]//g' | sed 's/\s/\n/g'
;;
esac
;;
## List all files opened.
##
-files)
emacsclient -a "" --eval "(remove-if #'null (mapcar #'buffer-file-name (buffer-list)))" \
| sed 's/["|\)|\(]//g' | sed 's/\s/\n/g'
;;
## Open Emacs shell in a new window
# -ielm)
# emacsclient -a "" -c --eval "(progn (new-frame) (ielm))"
# ;;
## Open Emascs Elisp shell (IELM) on terminal:
-ielm)
emacsclient -a "" -t --eval "(ielm)"
;;
-ielm-frame)
emacsclient -a "" --eval "(with-selected-frame (make-frame) (frame))"
;;
## Open Emacs eshell on terminal
-eshell)
emacsclient -a "" -t --eval "(eshell)"
;;
## Open Ehsell on a new frame
-eshell-gui)
emacsclient -a "" --eval "(with-selected-frame (make-frame) (eshell))"
;;
*)
echo "
Emacs Sever/Client Manager (em)
Usage:
./em <option>
-start Starts Emacs as sever, daemon.
-stop Stop Emacs daemon.
-edit <file> Open file in daemon.
-gui Open a new Emacs frame
-cli Open Emacs in terminal
-cmd <command> Evaluates s-expression in Emacs, example:
./em.sh \"(+ 1 2 3 4 5)\"
-files Show all files opened.
-load <file.el> Load a Emacs Lisp source file.
-man <manpage> Browser man page in terminal, example:
./em -man cbrt
-manual Open Emacs Manual in Web Browser:
------------------------------------------------
-show [option] Get Emacs Information.
load-path Show Emacs Load Path
exec-path Show Emacs Exec Path
"
;;
esac