@@ -21,7 +21,7 @@ set -euo pipefail
21
21
22
22
# Help message
23
23
_help () {
24
- cat << EOF
24
+ cat << EOF
25
25
mace [subcommand]
26
26
27
27
-h, --help Show this help message.
@@ -49,169 +49,177 @@ EOF
49
49
50
50
# Error and message printing
51
51
print_err () {
52
- printf " mace: [error]: %s\n" " $1 " >&2 # Print errors to stderr
52
+ printf " mace: [error]: %s\n" " $1 " >&2 # Print errors to stderr
53
53
}
54
54
55
55
print_msg () {
56
- printf " mace: %s\n" " $1 "
56
+ printf " mace: %s\n" " $1 "
57
57
}
58
58
59
59
# Dependency checking
60
60
check_depends () {
61
- for cmd in emacs doom; do
62
- if ! command -v " $cmd " & > /dev/null; then
63
- print_err " $cmd does not exist in your path."
64
- exit 1
65
- fi
66
- done
61
+ for cmd in emacs doom; do
62
+ if ! command -v " $cmd " & > /dev/null; then
63
+ print_err " $cmd does not exist in your path."
64
+ exit 1
65
+ fi
66
+ done
67
67
}
68
68
69
69
# Emacs status checking
70
70
check_active_emacs () {
71
- pidof -q emacs & > /dev/null
71
+ pidof -q emacs & > /dev/null
72
72
}
73
73
74
74
# Core functions
75
75
kill_daemon () {
76
- if check_active_emacs; then
77
- emacsclient -e ' (save-some-buffers 1 nil)' 2> /dev/null || print_err " Could not save buffers."
78
- emacsclient -e ' (kill-emacs)' 2> /dev/null || print_err " Could not kill daemon."
79
- else
80
- print_err " No daemon running."
81
- fi
76
+ if check_active_emacs; then
77
+ emacsclient -e ' (save-some-buffers 1 nil)' 2> /dev/null || print_err " Could not save buffers."
78
+ emacsclient -e ' (kill-emacs)' 2> /dev/null || print_err " Could not kill daemon."
79
+ else
80
+ print_err " No daemon running."
81
+ fi
82
82
}
83
83
84
84
start_daemon () {
85
- if check_active_emacs; then
86
- print_err " A daemon is already running."
87
- return 1
88
- fi
89
- print_msg " Starting daemon."
90
- emacs --daemon || { print_err " Could not start Emacs?..." && return 1; }
91
-
92
- print_msg " Finished launching daemon."
93
- run_eclient " $@ "
94
- return 0
85
+ if check_active_emacs; then
86
+ print_err " A daemon is already running."
87
+ return 1
88
+ fi
89
+ print_msg " Starting daemon."
90
+ emacs --daemon || { print_err " Could not start Emacs?..." && return 1; }
91
+
92
+ print_msg " Finished launching daemon."
93
+ run_eclient " $@ "
94
+ return 0
95
95
}
96
96
97
97
restart_daemon () {
98
- kill_daemon
99
- start_daemon " $@ "
100
- notify-send -a " mace" " Emacs daemon restarted!"
98
+ kill_daemon
99
+ start_daemon " $@ "
100
+ notify-send -a " mace" " Emacs daemon restarted!"
101
101
}
102
102
103
103
# Helper functions (simplified)
104
104
status_daemon () {
105
- if check_active_emacs; then
106
- print_msg " Emacs daemon is ACTIVE."
107
- else
108
- print_msg " Emacs daemon is not currently running."
109
- fi
105
+ if check_active_emacs; then
106
+ print_msg " Emacs daemon is ACTIVE."
107
+ else
108
+ print_msg " Emacs daemon is not currently running."
109
+ fi
110
110
}
111
111
112
112
run_eclient () {
113
- emacsclient -c -n --alternate-editor=' ' " $@ "
113
+ emacsclient -c -n --alternate-editor=' ' " $@ "
114
114
}
115
115
116
116
run_gui () {
117
- emacsclient -nc --alternate-editor=' ' " $@ "
117
+ emacsclient -nc --alternate-editor=' ' " $@ "
118
118
}
119
119
120
120
doom_capture () {
121
- org-capture || notify-send " Something went wrong..."
122
- exit 0
121
+ org-capture || notify-send " Something went wrong..."
122
+ exit 0
123
123
}
124
124
125
125
# Doom command handling
126
126
handle_doom () {
127
- local doom_subcommand=" $1 "
128
- local proc_count=$(( $(nproc) - 2 ))
129
- local proc_cmd=" -j $proc_count "
130
-
131
- case " $doom_subcommand " in
132
- s | sync) doom sync --aot $proc_cmd ;;
133
- sb | sync-rebuild) doom sync --rebuild --aot $proc_cmd ;;
134
- u | upgrade) doom upgrade --aot $proc_cmd ;;
135
- gc) doom gc ;;
136
- d | doctor) doom doctor ;;
137
- * )
138
- print_err " Cannot recognise the subcommand!"
139
- _help
140
- exit 1
141
- ;;
142
- esac
127
+ local doom_subcommand=" $1 "
128
+ local proc_count=$(( $(nproc) - 2 ))
129
+ local proc_cmd=" -j $proc_count "
130
+ local gc_cmd=" --gc"
131
+
132
+ case " $doom_subcommand " in
133
+ s | sync) eval " doom sync --aot $proc_cmd $gc_cmd " ;;
134
+ su) eval " doom sync -u --aot $proc_cmd $gc_cmd " ;;
135
+ sb | sync-rebuild) eval " doom sync --rebuild --aot $proc_cmd $gc_cmd " ;;
136
+ u | upgrade) eval " doom upgrade --aot $proc_cmd " ;;
137
+ gc) doom gc ;;
138
+ d | doctor) doom doctor ;;
139
+ * )
140
+ print_err " Cannot recognise the subcommand!"
141
+ _help
142
+ exit 1
143
+ ;;
144
+ esac
143
145
144
146
}
145
147
146
148
# Option parsing
147
149
while getopts " hSARKGTDpCd:" opt; do
148
150
149
- case " $opt " in
150
- h)
151
- _help
152
- exit 0
153
- ;;
154
- S)
155
- start_daemon
156
- exit 0
157
- ;;
158
- A)
159
- if check_active_emacs; then
160
- print_msg " Emacs daemon is ACTIVE."
161
- exit 0
162
- else
163
- print_msg " Emacs daemon is not currently running."
164
- exit 1
165
- fi
166
- ;;
167
- R)
168
- restart_daemon " $@ "
169
- exit 0
170
- ;;
171
- K)
172
- kill_daemon
173
- exit 0
174
- ;;
175
- D)
176
- emacs --debug-init
177
- exit 0
178
- ;;
179
- p)
180
- pkill -USR2 emacs
181
- exit 0
182
- ;;
183
- G)
184
- run_gui " $@ " # Open in GUI mode with optional arguments
185
- exit 0
186
- ;;
187
- T)
188
- emacsclient -t -nw -a " " " $@ " 2> /dev/null # Open in terminal
189
- exit 0
190
- ;;
191
- C) # Doom capture
192
- emacsclient -e ' (+org-capture/open-frame)' || notify-send " Something went wrong..."
193
- exit 0
194
- ;;
195
- d) # Handle Doom subcommands directly
196
- handle_doom " $OPTARG "
197
- exit 0
198
- ;;
199
- * )
200
- _help
201
- exit 1
202
- ;;
203
- esac
151
+ case " $opt " in
152
+ h)
153
+ _help
154
+ exit 0
155
+ ;;
156
+ S)
157
+ start_daemon
158
+ exit 0
159
+ ;;
160
+ A)
161
+ if check_active_emacs; then
162
+ print_msg " Emacs daemon is ACTIVE."
163
+ exit 0
164
+ else
165
+ print_msg " Emacs daemon is not currently running."
166
+ exit 1
167
+ fi
168
+ ;;
169
+ R)
170
+ restart_daemon " $@ "
171
+ exit 0
172
+ ;;
173
+ K)
174
+ kill_daemon
175
+ exit 0
176
+ ;;
177
+ D)
178
+ emacs --debug-init
179
+ exit 0
180
+ ;;
181
+ p)
182
+ pkill -USR2 emacs
183
+ exit 0
184
+ ;;
185
+ G)
186
+ run_gui " $@ " # Open in GUI mode with optional arguments
187
+ exit 0
188
+ ;;
189
+ T)
190
+ notify-send " We do not currently handle terminal emacs properly."
191
+
192
+ # if [ "$#" -eq 0 ]; then
193
+ # If no files
194
+ # emacsclient -t -a emacs
195
+ # else
196
+ # exec emacsclient -t -a=emacs "$@" 2>/dev/null
197
+ # fi
198
+ ;;
199
+ C) # Doom capture
200
+ emacsclient -e ' (+org-capture/open-frame)' -a ' emacs' > /dev/null || notify-send " Something went wrong opening capture window..."
201
+ exit 0
202
+ ;;
203
+ d) # Handle Doom subcommands directly
204
+ handle_doom " $OPTARG "
205
+ exit 0
206
+ ;;
207
+ * )
208
+ _help
209
+ exit 1
210
+ ;;
211
+ esac
204
212
done
205
213
shift $(( OPTIND - 1 )) # Remove parsed options
206
214
207
215
# Automatic start logic
208
216
if [ " $# " -eq 0 ] || [ -z " $DISPLAY " ] || [ -n " ${TMUX:- 0} " ]; then
209
- if ! check_active_emacs; then
210
- echo " No Emacs daemon, launching one now..."
211
- emacs
212
- # start_daemon && run_eclient
213
- exit 0
214
- fi
215
- run_eclient
217
+ if ! check_active_emacs; then
218
+ echo " No Emacs daemon, launching one now..."
219
+ emacs
220
+ # start_daemon && run_eclient
216
221
exit 0
222
+ fi
223
+ run_eclient
224
+ exit 0
217
225
fi
0 commit comments