Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,14 @@ Git Radar is highly customisable using a prompt format string. The 4 features
above: remote commits, local commits, branch and file changes; are controlled
by the prompt format string.

Feature | Control string
---------------|---------------
Remote commits | `%{remote}`
Local commits | `%{local}`
Branch | `%{branch}`
File changes | `%{changes}`
Stashes | `%{stash}`
Feature | Control string
---------------------------|---------------
Remote commits | `%{remote}`
Local commits | `%{local}`
Branch | `%{branch}`
File changes | `%{changes}`
Stashes | `%{stash}`
Relative path in the repo | `%{git_path}`

You can create any prompt shape you prefer by exporting `GIT_RADAR_FORMAT` with
your preferred shape. The control strings above will be replaced with the output
Expand Down
17 changes: 15 additions & 2 deletions radar-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,18 @@ stash_status() {
fi
}

git_path() {
printf '%s' "$(basename `git rev-parse --show-toplevel`)/$(git rev-parse --show-prefix)"
}

render_prompt() {
output="$PROMPT_FORMAT"
branch_sed=""
remote_sed=""
local_sed=""
changes_sed=""
stash_sed=""

git_path_sed=""

if_pre="%\{([^%{}]{1,}:){0,1}"
if_post="(:[^%{}]{1,}){0,1}\}"
Expand Down Expand Up @@ -597,11 +601,20 @@ render_prompt() {
stash_sed="s/${sed_pre}stash${sed_post}//"
fi
fi
if [[ $PROMPT_FORMAT =~ ${if_pre}git_path${if_post} ]]; then
git_path_result="$(git_path | sed -e 's/[\/&]/\\&/g')"
if [[ -n "git_path_result" ]]; then
git_path_sed="s/${sed_pre}git_path${sed_post}/\2${git_path_result}\4/"
else
git_path_sed="s/${sed_pre}git_path${sed_post}//"
fi
fi

printf '%b' "$output" | sed \
-e "$remote_sed" \
-e "$branch_sed" \
-e "$changes_sed" \
-e "$local_sed" \
-e "$stash_sed"
-e "$stash_sed" \
-e "$git_path_sed"
}