From c4da5e91d0533b647b9a043e02490f1886c1da0f Mon Sep 17 00:00:00 2001 From: Malfurious Date: Tue, 20 Jul 2021 23:43:04 -0400 Subject: Merge bash/zsh/fish color modes together This commit removes the differences between the supported shells and removes the options: --bash, --fish, and --zsh. I can not produce any problems in any of these shells using a generic form of the text coloring (ie: the one bash was using), so for simplicity I will opt to unify the way colors are handled and remove knowledge of the running shell. Something that _may_ end up being a problem is properly rendering the prompt in different terminal emulators. If this is of concern, it will be dealt with at a later time. Signed-off-by: Malfurious --- git-sonar | 15 +++++------ prompt.bash | 9 ------- prompt.zsh | 11 -------- sonar-base.sh | 83 ++++++++++++++--------------------------------------------- 4 files changed, 26 insertions(+), 92 deletions(-) delete mode 100755 prompt.bash delete mode 100755 prompt.zsh diff --git a/git-sonar b/git-sonar index 34e857d..ecbf8b8 100755 --- a/git-sonar +++ b/git-sonar @@ -11,7 +11,7 @@ else fi dot="$(cd "$(dirname "$([ -L "$0" ] && $READLINK_CMD -f "$0" || echo "$0")")" || exit; pwd)" -args=("$@") +source "$dot/sonar-base.sh" if [[ -z "$*" ]]; then _git="\033[1;30mgit:(\033[0m" @@ -95,12 +95,9 @@ while [[ $# -gt 0 ]];do if [[ "$command" == "--fetch" ]]; then nohup "$dot/fetch.sh" >/dev/null 2>&1 & fi - - if [[ "$command" == "--zsh" ]]; then - "$dot/prompt.zsh" "${args[@]}" - fi - - if [[ "$command" == "--bash" || "$command" == "--fish" ]]; then - "$dot/prompt.bash" "${args[@]}" - fi done + +if is_repo; then + prepare_colors + render_prompt +fi diff --git a/prompt.bash b/prompt.bash deleted file mode 100755 index 07691fb..0000000 --- a/prompt.bash +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -dot="$(cd "$(dirname "$0")" || exit; pwd)" -source "$dot/sonar-base.sh" - -if is_repo; then - prepare_bash_colors - render_prompt -fi diff --git a/prompt.zsh b/prompt.zsh deleted file mode 100755 index 9c812ac..0000000 --- a/prompt.zsh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env zsh - -dot="$(cd "$(dirname "$0")" || exit; pwd)" -source "$dot/sonar-base.sh" - -if is_repo; then - autoload colors && colors - - prepare_zsh_colors - render_prompt -fi diff --git a/sonar-base.sh b/sonar-base.sh index 95d943e..ed48726 100755 --- a/sonar-base.sh +++ b/sonar-base.sh @@ -28,82 +28,39 @@ get_fetch_time() { } -prepare_bash_colors() { - if [ -f "$rcfile_path/.gitradarrc.bash" ]; then - source "$rcfile_path/.gitradarrc.bash" - elif [ -f "$rcfile_path/.gitradarrc" ]; then +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" - COLOR_REMOTE_BEHIND="\x01${GIT_RADAR_COLOR_REMOTE_BEHIND:-"\\033[1;31m"}\x02" - COLOR_REMOTE_DIVERGED="\x01${GIT_RADAR_COLOR_REMOTE_DIVERGED:-"\\033[1;33m"}\x02" - COLOR_REMOTE_NOT_UPSTREAM="\x01${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-"\\033[1;31m"}\x02" + COLOR_REMOTE_AHEAD="${GIT_RADAR_COLOR_REMOTE_AHEAD:-"\\033[1;32m"}" + COLOR_REMOTE_BEHIND="${GIT_RADAR_COLOR_REMOTE_BEHIND:-"\\033[1;31m"}" + COLOR_REMOTE_DIVERGED="${GIT_RADAR_COLOR_REMOTE_DIVERGED:-"\\033[1;33m"}" + COLOR_REMOTE_NOT_UPSTREAM="${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-"\\033[1;31m"}" - COLOR_LOCAL_AHEAD="\x01${GIT_RADAR_COLOR_LOCAL_AHEAD:-"\\033[1;32m"}\x02" - COLOR_LOCAL_BEHIND="\x01${GIT_RADAR_COLOR_LOCAL_BEHIND:-"\\033[1;31m"}\x02" - COLOR_LOCAL_DIVERGED="\x01${GIT_RADAR_COLOR_LOCAL_DIVERGED:-"\\033[1;33m"}\x02" + COLOR_LOCAL_AHEAD="${GIT_RADAR_COLOR_LOCAL_AHEAD:-"\\033[1;32m"}" + COLOR_LOCAL_BEHIND="${GIT_RADAR_COLOR_LOCAL_BEHIND:-"\\033[1;31m"}" + COLOR_LOCAL_DIVERGED="${GIT_RADAR_COLOR_LOCAL_DIVERGED:-"\\033[1;33m"}" - COLOR_CHANGES_STAGED="\x01${GIT_RADAR_COLOR_CHANGES_STAGED:-"\\033[1;32m"}\x02" - COLOR_CHANGES_UNSTAGED="\x01${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-"\\033[1;31m"}\x02" - COLOR_CHANGES_CONFLICTED="\x01${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-"\\033[1;33m"}\x02" - COLOR_CHANGES_UNTRACKED="\x01${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-"\\033[1;37m"}\x02" + COLOR_CHANGES_STAGED="${GIT_RADAR_COLOR_CHANGES_STAGED:-"\\033[1;32m"}" + COLOR_CHANGES_UNSTAGED="${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-"\\033[1;31m"}" + COLOR_CHANGES_CONFLICTED="${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-"\\033[1;33m"}" + COLOR_CHANGES_UNTRACKED="${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-"\\033[1;37m"}" - COLOR_STASH="\x01${GIT_RADAR_COLOR_STASH:-"\\033[1;33m"}\x02" + COLOR_STASH="${GIT_RADAR_COLOR_STASH:-"\\033[1;33m"}" - COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}\x02" + COLOR_BRANCH="${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}" 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}"}" - RESET_COLOR_LOCAL="\x01${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}\x02" - RESET_COLOR_REMOTE="\x01${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\x02" - RESET_COLOR_CHANGES="\x01${GIT_RADAR_COLOR_CHANGES_RESET:-"\\033[0m"}\x02" - RESET_COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH_RESET:-"\\033[0m"}\x02" - RESET_COLOR_STASH="\x01${GIT_RADAR_COLOR_STASH:-"\\033[0m"}\x02" - -} - -prepare_zsh_colors() { - if [ -f "$rcfile_path/.gitradarrc.zsh" ]; then - source "$rcfile_path/.gitradarrc.zsh" - elif [ -f "$rcfile_path/.gitradarrc" ]; then - source "$rcfile_path/.gitradarrc" - fi - - PRINT_F_OPTION="%s" - - COLOR_REMOTE_AHEAD="%{${GIT_RADAR_COLOR_REMOTE_AHEAD:-${fg_bold[green]}}%}" - COLOR_REMOTE_BEHIND="%{${GIT_RADAR_COLOR_REMOTE_BEHIND:-${fg_bold[red]}}%}" - COLOR_REMOTE_DIVERGED="%{${GIT_RADAR_COLOR_REMOTE_DIVERGED:-${fg_bold[yellow]}}%}" - COLOR_REMOTE_NOT_UPSTREAM="%{${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-${fg_bold[red]}}%}" - - COLOR_LOCAL_AHEAD="%{${GIT_RADAR_COLOR_LOCAL_AHEAD:-${fg_bold[green]}}%}" - COLOR_LOCAL_BEHIND="%{${GIT_RADAR_COLOR_LOCAL_BEHIND:-${fg_bold[red]}}%}" - COLOR_LOCAL_DIVERGED="%{${GIT_RADAR_COLOR_LOCAL_DIVERGED:-${fg_bold[yellow]}}%}" - - COLOR_CHANGES_STAGED="%{${GIT_RADAR_COLOR_CHANGES_STAGED:-${fg_bold[green]}}%}" - COLOR_CHANGES_UNSTAGED="%{${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-${fg_bold[red]}}%}" - COLOR_CHANGES_CONFLICTED="%{${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-${fg_bold[yellow]}}%}" - COLOR_CHANGES_UNTRACKED="%{${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-${fg_bold[white]}}%}" - - COLOR_STASH="%{${GIT_RADAR_COLOR_STASH:-${fg_bold[yellow]}}%}" - - local italic_m - italic_m="$(printf '\xF0\x9D\x98\xAE')" - - 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}"}" - - RESET_COLOR_LOCAL="%{${GIT_RADAR_COLOR_LOCAL_RESET:-$reset_color}%}" - RESET_COLOR_REMOTE="%{${GIT_RADAR_COLOR_REMOTE_RESET:-$reset_color}%}" - RESET_COLOR_CHANGES="%{${GIT_RADAR_COLOR_CHANGES_RESET:-$reset_color}%}" - RESET_COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH_RESET:-$reset_color}%}" - RESET_COLOR_STASH="%{${GIT_RADAR_COLOR_STASH:-$reset_color}%}" + RESET_COLOR_LOCAL="${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}" + RESET_COLOR_REMOTE="${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}" + RESET_COLOR_CHANGES="${GIT_RADAR_COLOR_CHANGES_RESET:-"\\033[0m"}" + RESET_COLOR_BRANCH="${GIT_RADAR_COLOR_BRANCH_RESET:-"\\033[0m"}" + RESET_COLOR_STASH="${GIT_RADAR_COLOR_STASH:-"\\033[0m"}" } in_current_dir() { -- cgit v1.2.3