Skip to content

Commit e796c96

Browse files
committed
Added a configuration option to suffix/prefix the prompt
Now, you can add a prefix and/or suffix to your git-radar prompt that will only show if you are in a git repo. Note: The PROMPT_FORMAT line was changed to remove the leading space in the string. With it in, if you define a prefix a space will still be there even if the user may not want it. So it can be overridden by the user with one of the new variables, but by default, the prefix still adds that space anyways.
1 parent 2ac25e3 commit e796c96

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,25 @@ The default prompt format uses this to add spaces only if the feature would
255255
render. In that way the prompt always looks well spaced out no matter how many
256256
features are rendering.
257257

258+
### Prefixing and Suffixing the Full git-radar Prompt
259+
260+
Much like the previous section, it may be that we want our git-radar prompt to
261+
be prefixed or suffixed by some string of characters but only when you are in a
262+
repository.
263+
264+
To do this, use the built in variables that can be assigned in a .gitradarrc
265+
file.
266+
267+
For example:
268+
269+
```bash
270+
GIT_RADAR_PROMPT_SUFFIX_CHAR=" >> "
271+
GIT_RADAR_PROMPT_PREFIX_CHAR=" << "
272+
```
273+
274+
This will produce a prompt like this: `<< git:(master) >>`, where `<<` and `>>`
275+
only show, if we are actually in a git repository.
276+
258277

259278
## Support
260279

radar-base.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ get_fetch_time() {
2828

2929
}
3030

31+
get_prompt_prefix_and_suffix_strings() {
32+
if [ -f "$rcfile_path/.gitradarrc.bash" ]; then
33+
source "$rcfile_path/.gitradarrc.bash"
34+
elif [ -f "$rcfile_path/.gitradarrc.zsh" ]; then
35+
source "$rcfile_path/.gitradarrc.zsh"
36+
elif [ -f "$rcfile_path/.gitradarrc" ]; then
37+
source "$rcfile_path/.gitradarrc"
38+
fi
39+
40+
declare -n ret1=$1
41+
declare -n ret2=$2
42+
ret1="${GIT_RADAR_PROMPT_PREFIX_STRING:-" "}"
43+
ret2="${GIT_RADAR_PROMPT_SUFFIX_STRING:-""}"
44+
}
45+
3146
prepare_bash_colors() {
3247
if [ -f "$rcfile_path/.gitradarrc.bash" ]; then
3348
source "$rcfile_path/.gitradarrc.bash"
@@ -56,7 +71,7 @@ prepare_bash_colors() {
5671
COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}\x02"
5772
MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"\\x01\\033[0m\\x02\\xF0\\x9D\\x98\\xAE\\x01\\033[0m\\x02"}"
5873

59-
PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}"
74+
PROMPT_FORMAT="${GIT_RADAR_FORMAT:-"\\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}"
6075

6176
RESET_COLOR_LOCAL="\x01${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}\x02"
6277
RESET_COLOR_REMOTE="\x01${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\x02"
@@ -604,7 +619,9 @@ render_prompt() {
604619
fi
605620
fi
606621

607-
printf '%b' "$output" | sed \
622+
get_prompt_prefix_and_suffix_strings prefix_string suffix_string
623+
624+
printf '%b' "${prefix_string}${output}${suffix_string}" | sed \
608625
-e "$remote_sed" \
609626
-e "$branch_sed" \
610627
-e "$changes_sed" \

0 commit comments

Comments
 (0)