@@ -14,6 +14,28 @@ timethis() {
14
14
echo " $1 - $dur " >> $HOME /duration.dat
15
15
}
16
16
17
+ function top_zsh_pid {
18
+ # Look up the parent of the given PID.
19
+ pid=" ${1:- $$ } "
20
+ found_zsh=" ${2} "
21
+ ppid=" $( ps -p $pid -o ppid=) "
22
+ ppid_name=" $( ps -p $ppid -o comm=) "
23
+
24
+ # printf "${ppid}:${ppid_name} -> "
25
+
26
+ # /sbin/init always has a PID of 1, so if you reach that, the current PID is
27
+ # the top-level parent. Otherwise, keep looking.
28
+ if [[ ${ppid} -eq 1 ]] ; then
29
+ printf " ${ppid} "
30
+ elif [[ ${ppid_name} == * zsh* ]]; then
31
+ top_zsh_pid " ${ppid} " " true"
32
+ elif [[ $found_zsh == " true" ]]; then
33
+ printf " ${pid} "
34
+ else
35
+ top_zsh_pid " ${ppid} " " false"
36
+ fi
37
+ }
38
+
17
39
prepare_bash_colors () {
18
40
if [ -f " $rcfile_path /.gitradarrc.bash" ]; then
19
41
source " $rcfile_path /.gitradarrc.bash"
@@ -391,35 +413,52 @@ untracked_status() {
391
413
}
392
414
393
415
color_changes_status () {
394
- local separator=" ${1:- } "
395
-
396
- local porcelain=" $( porcelain_status) "
397
- local changes=" "
398
-
399
- if [[ -n " $porcelain " ]]; then
400
- local staged_changes=" $( staged_status " $porcelain " " $COLOR_CHANGES_STAGED " " $RESET_COLOR_CHANGES " ) "
401
- local unstaged_changes=" $( unstaged_status " $porcelain " " $COLOR_CHANGES_UNSTAGED " " $RESET_COLOR_CHANGES " ) "
402
- local untracked_changes=" $( untracked_status " $porcelain " " $COLOR_CHANGES_UNTRACKED " " $RESET_COLOR_CHANGES " ) "
403
- local conflicted_changes=" $( conflicted_status " $porcelain " " $COLOR_CHANGES_CONFLICTED " " $RESET_COLOR_CHANGES " ) "
404
- if [[ -n " $staged_changes " ]]; then
405
- staged_changes=" $separator$staged_changes "
406
- fi
416
+ _async_changes () {
417
+ local zsh_parent_pid=" $1 "
418
+ local separator=" ${2:- } "
419
+
420
+ local porcelain=" $( porcelain_status) "
421
+ local changes=" "
422
+
423
+ if [[ -n " $porcelain " ]]; then
424
+ local staged_changes=" $( staged_status " $porcelain " " $COLOR_CHANGES_STAGED " " $RESET_COLOR_CHANGES " ) "
425
+ local unstaged_changes=" $( unstaged_status " $porcelain " " $COLOR_CHANGES_UNSTAGED " " $RESET_COLOR_CHANGES " ) "
426
+ local untracked_changes=" $( untracked_status " $porcelain " " $COLOR_CHANGES_UNTRACKED " " $RESET_COLOR_CHANGES " ) "
427
+ local conflicted_changes=" $( conflicted_status " $porcelain " " $COLOR_CHANGES_CONFLICTED " " $RESET_COLOR_CHANGES " ) "
428
+ if [[ -n " $staged_changes " ]]; then
429
+ staged_changes=" $separator$staged_changes "
430
+ fi
407
431
408
- if [[ -n " $unstaged_changes " ]]; then
409
- unstaged_changes=" $separator$unstaged_changes "
410
- fi
432
+ if [[ -n " $unstaged_changes " ]]; then
433
+ unstaged_changes=" $separator$unstaged_changes "
434
+ fi
411
435
412
- if [[ -n " $conflicted_changes " ]]; then
413
- conflicted_changes=" $separator$conflicted_changes "
414
- fi
436
+ if [[ -n " $conflicted_changes " ]]; then
437
+ conflicted_changes=" $separator$conflicted_changes "
438
+ fi
439
+
440
+ if [[ -n " $untracked_changes " ]]; then
441
+ untracked_changes=" $separator$untracked_changes "
442
+ fi
415
443
416
- if [[ -n " $untracked_changes " ]]; then
417
- untracked_changes=" $separator$untracked_changes "
444
+ changes=" $staged_changes$conflicted_changes$unstaged_changes$untracked_changes "
418
445
fi
419
446
420
- changes=" $staged_changes$conflicted_changes$unstaged_changes$untracked_changes "
447
+ printf $PRINT_F_OPTION " ${changes: 1} "
448
+ kill -s USR1 " $zsh_parent_pid "
449
+ }
450
+
451
+ zsh_parent_pid=" $( top_zsh_pid " $PPID " ) "
452
+
453
+ if [[ -f $( dot_git) /git_radar_changes ]]; then
454
+ cat $( dot_git) /git_radar_changes
455
+ fi
456
+ if [[ ! -f $( dot_git) /git_radar_working ]]; then
457
+ (_async_changes " $zsh_parent_pid " )& > $( dot_git) /git_radar_changes &
458
+ touch $( dot_git) /git_radar_working
459
+ else
460
+ rm $( dot_git) /git_radar_working
421
461
fi
422
- printf $PRINT_F_OPTION " ${changes: 1} "
423
462
}
424
463
425
464
bash_color_changes_status () {
0 commit comments