summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hunter <m@lfurio.us>2026-03-01 01:06:55 -0500
committerMatt Hunter <m@lfurio.us>2026-03-16 04:36:28 -0400
commit8f1e0156d4c47497453a234fe31ca299a259796b (patch)
treed2ce8332b8a946ace054079714de3df66e9d51b8
parentdd2c76dd67f7054b2b0eb1b3a967cdb4c358343b (diff)
downloadgit-sonar-8f1e0156d4c47497453a234fe31ca299a259796b.tar.gz
git-sonar-8f1e0156d4c47497453a234fe31ca299a259796b.zip
Refactor rc config file management
All commands which source content from one of the rc files are collected together at the bottom of the script, in the portion that runs before prompt rendering. Attempt to source from any and all of the files that happen to exist, instead of just taking the first that we find. This allows for instance, the .bash rc file to provide only bash-specific additions that are combined with variables present in .gitradarrc. However, a new ".gitsonarrc" file is now recognized as well whose use should be preferred by new users. File load precedence is such that ".gitsonarrc", if present, has the final say on what variables to use. To improve portability, "source" statements are converted to the POSIX-compliant "." syntax. As part of this code reorganization, the get_fetch_time() function is removed - logic merged into the fetch() function. Signed-off-by: Matt Hunter <m@lfurio.us>
-rwxr-xr-xgit-sonar28
1 files changed, 7 insertions, 21 deletions
diff --git a/git-sonar b/git-sonar
index b2d140e..2ff238f 100755
--- a/git-sonar
+++ b/git-sonar
@@ -7,27 +7,8 @@
GIT_SONAR_VERSION="v0.8.1"
dot_git=""
-rcfile_path="$HOME"
-
-get_fetch_time() {
- if [ -f "$rcfile_path/.gitradarrc.bash" ]; then
- source "$rcfile_path/.gitradarrc.bash"
- elif [ -f "$rcfile_path/.gitradarrc.zsh" ]; then
- source "$rcfile_path/.gitradarrc.zsh"
- elif [ -f "$rcfile_path/.gitradarrc" ]; then
- source "$rcfile_path/.gitradarrc"
- fi
-
- FETCH_TIME="${GIT_RADAR_FETCH_TIME:-"$((5 * 60))"}"
- echo "$FETCH_TIME"
-
-}
prepare_colors() {
- if [ -f "$rcfile_path/.gitradarrc" ]; then
- source "$rcfile_path/.gitradarrc"
- fi
-
PRINT_F_OPTION=""
COLOR_REMOTE_AHEAD="\x01${GIT_RADAR_COLOR_REMOTE_AHEAD:-"\\033[1;32m"}\x02"
@@ -109,8 +90,7 @@ time_to_update() {
}
fetch() {
- # Gives $FETCH_TIME a value
- get_fetch_time
+ FETCH_TIME="${GIT_RADAR_FETCH_TIME:-"$((5 * 60))"}"
if time_to_update "$FETCH_TIME"; then
record_timestamp
@@ -576,6 +556,12 @@ fi
# Guard all active operations by this is_repo check
if is_repo; then
+ # Merge configuration from accepted RC files
+ [ -f "$HOME/.gitradarrc" ] && . "$HOME/.gitradarrc"
+ [ -f "$HOME/.gitradarrc.bash" ] && . "$HOME/.gitradarrc.bash"
+ [ -f "$HOME/.gitradarrc.zsh" ] && . "$HOME/.gitradarrc.zsh"
+ [ -f "$HOME/.gitsonarrc" ] && . "$HOME/.gitsonarrc"
+
[ -n "$do_fetch" ] && fetch >/dev/null 2>&1
prepare_colors
render_prompt