Skip to content

Commit e074fac

Browse files
ZSH only version of async files changes
1 parent 6384987 commit e074fac

File tree

1 file changed

+62
-23
lines changed

1 file changed

+62
-23
lines changed

radar-base.sh

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ timethis() {
1414
echo "$1 - $dur" >> $HOME/duration.dat
1515
}
1616

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+
1739
prepare_bash_colors() {
1840
if [ -f "$rcfile_path/.gitradarrc.bash" ]; then
1941
source "$rcfile_path/.gitradarrc.bash"
@@ -391,35 +413,52 @@ untracked_status() {
391413
}
392414

393415
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
407431

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
411435

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
415443

416-
if [[ -n "$untracked_changes" ]]; then
417-
untracked_changes="$separator$untracked_changes"
444+
changes="$staged_changes$conflicted_changes$unstaged_changes$untracked_changes"
418445
fi
419446

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
421461
fi
422-
printf $PRINT_F_OPTION "${changes:1}"
423462
}
424463

425464
bash_color_changes_status() {

0 commit comments

Comments
 (0)