commit 83b4115338d629f6e972360e7df240c6e077076e
parent deeb13d80708bcd1b787d8bec2e11f742af455d2
Author: hhvn <dev@hhvn.uk>
Date: Mon, 18 Apr 2022 18:09:36 +0100
Use tmpfiles for rc prompt (avoid using up rc's memory)
Diffstat:
M | .rcrc | | | 92 | +++++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
1 file changed, 52 insertions(+), 40 deletions(-)
diff --git a/.rcrc b/.rcrc
@@ -18,7 +18,16 @@ fn __prompt_exit_colour {
}
}
+fn __prompt_cleanup {
+ for (f in $__prompt_tmp) {
+ rm -f $f
+ }
+ __prompt_tmp = ()
+ tput sgr0
+}
+
fn sigexit {
+ __prompt_cleanup
for (f in $manconfs) {
rm -f $f
}
@@ -28,6 +37,7 @@ fn sigexit {
fn __prompt {
__prompt_exitcodes = $status
__prompt_gitoutput = 0
+ __prompt_tmp = (/tmp/$pid.prompt.tmp $__prompt_tmp)
# exit codes
# rc produces a list if there is a pipeline
@@ -57,49 +67,51 @@ fn __prompt {
__prompt_tput setaf 5
printf '%s ' `{whoami}
- # branch
- __prompt_tput setaf 3
- __prompt_branch = `{git branch >[2]/dev/null |
+ if (!~ $hide_git 1) {
+ # branch
+ __prompt_tput setaf 3
+ __prompt_branch = `{git branch >[2]/dev/null |
grep '^*' |
awk '{print $2 "|"}'}
- if (!~ $__prompt_branch ()) {
- printf '%s' $__prompt_branch
- __prompt_gitoutput = 1
- }
+ if (!~ $__prompt_branch ()) {
+ printf '%s' $__prompt_branch
+ __prompt_gitoutput = 1
+ }
- # unstaged changes
- __prompt_diff = ``(''){git diff >[2]/dev/null}
- __prompt_diffstatus = $bqstatus
- if (~ $__prompt_diff ?*) {
- __prompt_tput setaf 8
- printf '%s+' `{echo $__prompt_diff |
- grep '-E'^$__prompt_gnu_binary '^(\+\+\+|---)' |
- sed -E 's~^[^a]*a/|^[^b]*b/~~' |
- grep -v /dev/null |
- uniq |
- wc -l |
- tr -d '\n'}
- __prompt_gitoutput = 1
- } else if (~ $bqstatus 0) {
- __prompt_tput setaf 15
- printf '='
- __prompt_gitoutput = 1
- }
+ # unstaged changes
+ git diff >[2]/dev/null > $__prompt_tmp(1)
+ __prompt_diffstatus = $bqstatus
+ if (head -n 1 < $__prompt_tmp(1) | grep '^.' >/dev/null) {
+ __prompt_tput setaf 8
+ printf '%s+' `{cat $__prompt_tmp(1) |
+ grep '-E'^$__prompt_gnu_binary '^(\+\+\+|---)' |
+ sed -E 's~^[^a]*a/|^[^b]*b/~~' |
+ grep -v /dev/null |
+ uniq |
+ wc -l |
+ tr -d '\n'}
+ __prompt_gitoutput = 1
+ } else if (~ $bqstatus 0) {
+ __prompt_tput setaf 15
+ printf '='
+ __prompt_gitoutput = 1
+ }
- # unpushed commits
- __prompt_log = ``(''){git log '--pretty=format:commit %h%d' >[2]/dev/null}
- if (!~ `$nl{echo $__prompt_log | head -n1} */*) {
- __prompt_tput setaf 14
- echo $__prompt_log | awk '
- BEGIN {c = 0; exitcode = 1}
- /^commit/ {
- if ($0 ~ /\//) {
- printf("%d^", c)
- exitcode = 0
- exit(0)
- } else c += 1
- }
- END { exit(exitcode) }' && __prompt_gitoutput = 1
+ # unpushed commits
+ git log '--pretty=format:commit %h%d' >[2]/dev/null > $__prompt_tmp(1)
+ if (!~ `$nl{head -n 1 < $__prompt_tmp(1)} */*) {
+ __prompt_tput setaf 14
+ < $__prompt_tmp(1) awk '
+ BEGIN {c = 0; exitcode = 1}
+ /^commit/ {
+ if ($0 ~ /\//) {
+ printf("%d^", c)
+ exitcode = 0
+ exit(0)
+ } else c += 1
+ }
+ END { exit(exitcode) }' && __prompt_gitoutput = 1
+ }
}
if (~ $__prompt_gitoutput 1) {
@@ -112,7 +124,7 @@ fn __prompt {
# end
printf '$ '
- __prompt_tput sgr0
+ __prompt_cleanup
}
# Frontend prompt function