36
36
# -D Unless this option is specified, report zero staged, unstaged and conflicted
37
37
# changes for repositories with bash.showDirtyState = false.
38
38
function gitstatus_start() {
39
+ if [[ " $BASH_VERSION " < 4 ]]; then
40
+ >&2 printf ' gitstatus_start: need bash version >= 4.0, found %s\n' " $BASH_VERSION "
41
+ >&2 printf ' \n'
42
+ >&2 printf ' To see the version of the current shell, type:\n'
43
+ >&2 printf ' \n'
44
+ >&2 printf ' \033[32mecho\033[0m \033[33m"$BASH_VERSION"\033[0m\n'
45
+ >&2 printf ' \n'
46
+ >&2 printf ' The output of `\033[32mbash\033[0m --version` may be different and is not relevant.\n'
47
+ return 1
48
+ fi
49
+
39
50
unset OPTIND
40
51
local opt timeout=5 max_dirty=-1 extra_flags
41
52
local max_num_staged=1 max_num_unstaged=1 max_num_conflicted=1 max_num_untracked=1
@@ -69,7 +80,7 @@ function gitstatus_start() {
69
80
local gitstatus_plugin_dir=" $PWD "
70
81
fi
71
82
72
- local tmpdir req_fifo resp_fifo
83
+ local tmpdir req_fifo resp_fifo culprit
73
84
74
85
function gitstatus_start_impl() {
75
86
local log_level=" ${GITSTATUS_LOG_LEVEL:- } "
@@ -137,7 +148,7 @@ function gitstatus_start() {
137
148
}
138
149
139
150
set -- -d " $gitstatus_plugin_dir " -s " $uname_s " -m " $uname_m " \
140
- -p " printf '.\036' >&$fd_out " -- _gitstatus_set_daemon
151
+ -p " printf '.\036' >&$fd_out " -e " $fd_out " - - _gitstatus_set_daemon
141
152
[[ " ${GITSTATUS_AUTO_INSTALL:- 1} " -ne 0 ]] || set -- -n " $@ "
142
153
source " $gitstatus_plugin_dir " /install || return
143
154
[[ -n " $_gitstatus_bash_daemon " ]] || return
@@ -166,7 +177,7 @@ function gitstatus_start() {
166
177
trap - ${sig[@]}
167
178
case " $ret " in
168
179
0|129|130|131|137|141|143|159)
169
- echo -nE $' bye\x1f 0\x1e ' >& " $fd_out "
180
+ echo -nE $' } bye\x1f 0\x1e ' >& " $fd_out "
170
181
exit " $ret "
171
182
;;
172
183
esac
@@ -192,7 +203,7 @@ function gitstatus_start() {
192
203
trap " trap - ${sig[*]} ; kill $pid &>/dev/null" ${sig[@]}
193
204
wait " $pid "
194
205
trap - ${sig[@]}
195
- echo -nE $' bye\x1f 0\x1e ' >& " $fd_out "
206
+ echo -nE $' } bye\x1f 0\x1e ' >& " $fd_out "
196
207
) & disown
197
208
) & disown
198
209
} 0< /dev/null & > " $GITSTATUS_DAEMON_LOG "
@@ -205,12 +216,15 @@ function gitstatus_start() {
205
216
[[ " $GITSTATUS_DAEMON_PID " == [1-9]* ]] || return
206
217
207
218
local reply
208
- echo -nE $' hello\x1f\x1e ' >& $_GITSTATUS_REQ_FD || return
219
+ echo -nE $' } hello\x1f\x1e ' >& $_GITSTATUS_REQ_FD || return
209
220
local dl=
210
221
while true ; do
211
- IFS=' ' read -rd $' \x1e ' -u $_GITSTATUS_RESP_FD -t " $timeout " reply || return
212
- [[ " $reply " == $' hello\x1f 0' ]] && break
213
- [[ " $reply " == . ]] || return
222
+ reply=
223
+ if ! IFS=' ' read -rd $' \x1e ' -u $_GITSTATUS_RESP_FD -t " $timeout " reply; then
224
+ culprit=" $reply "
225
+ return 1
226
+ fi
227
+ [[ " $reply " == $' }hello\x1f 0' ]] && break
214
228
if [[ -z " $dl " ]]; then
215
229
dl=1
216
230
if [[ -t 2 ]]; then
@@ -238,8 +252,11 @@ function gitstatus_start() {
238
252
}
239
253
240
254
if ! gitstatus_start_impl; then
241
- echo " " >&2
242
- echo " gitstatus_start: failed to start gitstatusd" >&2
255
+ >&2 printf ' \n'
256
+ >&2 printf ' [\033[31mERROR\033[0m]: gitstatus failed to initialize.\n'
257
+ if [[ -n " ${culprit-} " ]]; then
258
+ >&2 printf ' \n%s\n' " $culprit "
259
+ fi
243
260
[[ -z " ${req_fifo:- } " ]] || command rm -f " $req_fifo "
244
261
[[ -z " ${resp_fifo:- } " ]] || command rm -f " $resp_fifo "
245
262
unset -f gitstatus_start_impl
0 commit comments