-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_em.sh
executable file
·58 lines (53 loc) · 1.92 KB
/
install_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
read -r -d '' EMACSSERVERCODE << "EOM"
# Begin script: running emacs faster
unalias em >/dev/null 2>&1
em() {
if [[ "$@" == "stop" ]]; then
kill -9 $(ps -ef | grep '.*emacs.*daemon.*' | grep -v grep | awk '{print $2}') >/dev/null 2>&1
kill -9 $(ps -ef | grep '.*Emacs\.app.*daemon.*' | grep -v grep | awk '{print $2}') >/dev/null 2>&1
return
fi
if [[ $(ps aux | grep -w ".*emacs.*daemon.*" | grep -v grep | wc -l) -gt 0 ]]; then
echo "daemon is running"
if [[ $(ps aux | grep -w ".*emacs.*daemon.*" | grep -v grep | wc -l) -gt 1 ]]; then
kill -9 $(ps aux | grep '.*emacs.*daemon.*' | grep -v 'grep' | awk '{print $2}')
emacs --daemon
fi
elif [[ $(ps aux | grep -w ".*Emacs\.app.*daemon.*" | grep -v grep | wc -l) -gt 0 ]]; then
echo "daemon is running"
if [[ $(ps aux | grep -w ".*Emacs\.app.*daemon.*" | grep -v grep | wc -l) -gt 1 ]]; then
kill -9 $(ps aux | grep '.*Emacs\.app.*daemon.*' | grep -v 'grep' | awk '{print $2}')
emacs --daemon
fi
else
echo "daemon is starting"
emacs --daemon
fi
if [[ "$@" == "" ]]; then
emacsclient -create-frame --alternate-editor="" .
else
emacsclient -create-frame --alternate-editor="" "$@"
fi
}
# End script: running emacs faster
EOM
declare file=".zshenv"
touch ~/$file
declare regex="source.*emacs_server.sh"
declare file_content=$( cat ~/"${file}" )
if [[ " $file_content " =~ $regex ]] # please note the space before and after the file content
then
echo "Updating config..."
sed -i '' "/$regex/d" ~/$file
else
echo "Adding new config"
fi
rm ~/.emacs.d/emacs_server.sh
touch ~/.emacs.d/emacs_server.sh
echo "$EMACSSERVERCODE" >> ~/.emacs.d/emacs_server.sh
echo "source ~/.emacs.d/emacs_server.sh" >> ~/$file
source ~/$file
if [[ "$@" == "uninstall" ]]; then
rm ~/.emacs.d/emacs_server.sh 2>/dev/null
sed -i '' "/$regex/d" ~/$file
fi