Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a configuration option to suffix/prefix the prompt #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@ The default prompt format uses this to add spaces only if the feature would
render. In that way the prompt always looks well spaced out no matter how many
features are rendering.

### Prefixing and Suffixing the Full git-radar Prompt

It may be that we want our git-radar prompt to be prefixed or suffixed by some
string of characters, but only when you are in a repository.

To do this, use the built in variables that can be assigned in a .gitradarrc
file.

For example:

```bash
GIT_RADAR_PROMPT_SUFFIX=" >> "
GIT_RADAR_PROMPT_PREFIX=" << "
```

This will produce a prompt like this: `<< git:(master) >>`, where `<<` and `>>`
only show, if we are actually in a git repository.


## Support

Expand Down
12 changes: 9 additions & 3 deletions radar-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ prepare_bash_colors() {
COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}\x02"
MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"\\x01\\033[0m\\x02\\xF0\\x9D\\x98\\xAE\\x01\\033[0m\\x02"}"

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}"}"
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}"}"

PROMPT_PREFIX="${GIT_RADAR_PROMPT_PREFIX:-" "}"
PROMPT_SUFFIX="${GIT_RADAR_PROMPT_SUFFIX:-""}"

RESET_COLOR_LOCAL="\x01${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}\x02"
RESET_COLOR_REMOTE="\x01${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\x02"
Expand Down Expand Up @@ -96,7 +99,10 @@ prepare_zsh_colors() {
COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH:-$reset_color}%}"
MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"%{$reset_color%}$italic_m%{$reset_color%}"}"

PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" %{$fg_bold[grey]%}git:(%{$reset_color%}%{remote: }%{branch}%{ :local}%{$fg_bold[grey]%})%{$reset_color%}%{ :stash}%{ :changes}"}"
PROMPT_FORMAT="${GIT_RADAR_FORMAT:-"%{$fg_bold[grey]%}git:(%{$reset_color%}%{remote: }%{branch}%{ :local}%{$fg_bold[grey]%})%{$reset_color%}%{ :stash}%{ :changes}"}"

PROMPT_PREFIX="${GIT_RADAR_PROMPT_PREFIX:-" "}"
PROMPT_SUFFIX="${GIT_RADAR_PROMPT_SUFFIX:-""}"

RESET_COLOR_LOCAL="%{${GIT_RADAR_COLOR_LOCAL_RESET:-$reset_color}%}"
RESET_COLOR_REMOTE="%{${GIT_RADAR_COLOR_REMOTE_RESET:-$reset_color}%}"
Expand Down Expand Up @@ -604,7 +610,7 @@ render_prompt() {
fi
fi

printf '%b' "$output" | sed \
printf '%b' "${PROMPT_PREFIX}${output}${PROMPT_SUFFIX}" | sed \
-e "$remote_sed" \
-e "$branch_sed" \
-e "$changes_sed" \
Expand Down