From ea02e3d6bd3ad603224cacb5ee7b56583dd6b693 Mon Sep 17 00:00:00 2001 From: Zanark Date: Thu, 10 Oct 2019 16:54:43 +0530 Subject: [PATCH 1/5] added theme bash files --- themes/gitline/powerline.base.bash | 234 +++++++++++++++++++++++++++++ themes/gitline/redline.theme.bash | 68 +++++++++ 2 files changed, 302 insertions(+) create mode 100644 themes/gitline/powerline.base.bash create mode 100644 themes/gitline/redline.theme.bash diff --git a/themes/gitline/powerline.base.bash b/themes/gitline/powerline.base.bash new file mode 100644 index 00000000..925791fc --- /dev/null +++ b/themes/gitline/powerline.base.bash @@ -0,0 +1,234 @@ +# Define this here so it can be used by all of the Powerline themes +THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} + +#To set color for foreground and background +function set_color { + set +u + if [[ "${1}" != "-" ]]; then + fg="38;5;${1}" + fi + if [[ "${2}" != "-" ]]; then + bg="48;5;${2}" + [[ -n "${fg}" ]] && bg=";${bg}" + fi + echo -e "\[\033[${fg}${bg}m\]" +} + +#Customising User Info Segment +function __powerline_user_info_prompt { + local user_info="${USER}" + local color=${USER_INFO_THEME_PROMPT_COLOR} + local fg_color=15 + + if [[ "${THEME_CHECK_SUDO}" = true ]]; then + if sudo -n uptime 2>&1 | grep -q "load"; then + color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + fi + fi + + case "${POWERLINE_PROMPT_USER_INFO_MODE}" in + "sudo") + if [[ "${color}" = "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then + user_info="👑 ${USER}" + fg_color=227 + color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + fi + ;; + *) + if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then + user_info="${USER_INFO_SSH_CHAR}${USER}" + else + user_info="${USER}" + fi + ;; + esac + [[ -n "${user_info}" ]] && echo "${user_info}|${color}|${fg_color}" +} + +#Customising Ruby Prompt +function __powerline_ruby_prompt { + local ruby_version="" + local fg_color=206 + + if _command_exists rvm; then + ruby_version="$(rvm_version_prompt)" + elif _command_exists rbenv; then + ruby_version=$(rbenv_version_prompt) + fi + + [[ -n "${ruby_version}" ]] && echo "${RUBY_CHAR}${ruby_version}|${RUBY_THEME_PROMPT_COLOR}|${fg_color}" +} + +#Customising Python (venv) Prompt +function __powerline_python_venv_prompt { + set +u + local python_venv="" + local fg_color=206 + + if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then + python_venv="${CONDA_DEFAULT_ENV}" + PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR} + elif [[ -n "${VIRTUAL_ENV}" ]]; then + python_venv=$(basename "${VIRTUAL_ENV}") + fi + + [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}|${fg_color}" +} + +#Customising SCM Prompt +function __powerline_scm_prompt { + local color="" + local scm_prompt="" + local fg_color=206 + + scm_prompt_vars + + # echo "${scm}" + + if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then + if [[ "${SCM_DIRTY}" -eq 3 ]]; then + color=${SCM_THEME_PROMPT_STAGED_COLOR} + fg_color=124 + elif [[ "${SCM_DIRTY}" -eq 2 ]]; then + color=${SCM_THEME_PROMPT_UNSTAGED_COLOR} + fg_color=56 + elif [[ "${SCM_DIRTY}" -eq 1 ]]; then + color=${SCM_THEME_PROMPT_DIRTY_COLOR} + fg_color=118 + elif [[ "${SCM_DIRTY}" -eq 0 ]]; then + color=${SCM_THEME_PROMPT_CLEAN_COLOR} + fg_color=16 + else + color=${SCM_THEME_PROMPT_COLOR} + fg_color=255 + fi + # if [[ "${SCM_BRANCH}" == "master" ]]; then + # color=128 + # fg_color=251 + # fi + if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + elif [[ "${SCM_P4_CHAR}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + elif [[ "${SCM_HG_CHAR}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + fi + echo "${scm_prompt}${scm}|${color}|${fg_color}" + fi +} + +function __powerline_cwd_prompt { + local cwd=$(pwd | sed "s|^${HOME}|~|") + local fg_color=16 + + echo "${cwd}|${CWD_THEME_PROMPT_COLOR}|${fg_color}" +} + +function __powerline_hostname_prompt { + local fg_color=206 + + echo "$(hostname -s)|${HOST_THEME_PROMPT_COLOR}|${fg_color}" +} + +function __powerline_wd_prompt { + local fg_color=206 + + echo "\W|${CWD_THEME_PROMPT_COLOR}|${fg_color}" +} + +function __powerline_clock_prompt { + local fg_color=206 + + echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}|${fg_color}" +} + +function __powerline_battery_prompt { + local color="" + local battery_status="$(battery_percentage 2> /dev/null)" + local fg_color=255 + + if [[ -z "${battery_status}" ]] || [[ "${battery_status}" = "-1" ]] || [[ "${battery_status}" = "no" ]]; then + true + else + if [[ "$((10#${battery_status}))" -le 5 ]]; then + color="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" + elif [[ "$((10#${battery_status}))" -le 25 ]]; then + color="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR}" + else + color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" + fi + ac_adapter_connected && battery_status="${BATTERY_AC_CHAR}${battery_status}" + echo "${battery_status}%|${color}|${fg_color}" + fi +} + +function __powerline_in_vim_prompt { + local fg_color=206 + + if [ -n "$VIMRUNTIME" ]; then + echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}|${fg_color}" + fi +} + +function __powerline_aws_profile_prompt { + local fg_color=206 + + if [[ -n "${AWS_PROFILE}" ]]; then + echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}|${fg_color}" + fi +} + +function __powerline_left_segment { + local OLD_IFS="${IFS}"; IFS="|" + local params=( $1 ) + IFS="${OLD_IFS}" + local separator_char="${POWERLINE_LEFT_SEPARATOR}" + local separator="" + local fg_color=206 + + #for seperator character + if [[ "${SEGMENTS_AT_LEFT}" -gt 0 ]]; then + separator="$(set_color ${LAST_SEGMENT_COLOR} ${params[1]})${separator_char}${normal}" + fi + #change here to cahnge fg color + #echo "${params[0]} -> ${params[1]} -> ${params[2]}" + LEFT_PROMPT+="${separator}$(set_color ${params[2]} ${params[1]}) ${params[0]} ${normal}" + #seperator char color = current bg + LAST_SEGMENT_COLOR=${params[1]} + (( SEGMENTS_AT_LEFT += 1 )) +} + +function __powerline_last_status_prompt { + [[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR}" +} + +function __powerline_prompt_command { + local last_status="$?" ## always the first + local separator_char="${POWERLINE_PROMPT_CHAR}" + + LEFT_PROMPT="" + SEGMENTS_AT_LEFT=0 + LAST_SEGMENT_COLOR="" + + + if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then + LEFT_PROMPT+="$(set_color ${PROMPT_DISTRO_LOGO_COLOR} ${PROMPT_DISTRO_LOGO_COLORBG})${PROMPT_DISTRO_LOGO}$(set_color - -)" + fi + + ## left prompt ## + for segment in $POWERLINE_PROMPT; do + local info="$(__powerline_${segment}_prompt)" + [[ -n "${info}" ]] && __powerline_left_segment "${info}" + done + + [[ "${last_status}" -ne 0 ]] && __powerline_left_segment $(__powerline_last_status_prompt ${last_status}) + [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${normal}" + + PS1="${LEFT_PROMPT} " + + ## cleanup ## + unset LAST_SEGMENT_COLOR \ + LEFT_PROMPT \ + SEGMENTS_AT_LEFT +} + diff --git a/themes/gitline/redline.theme.bash b/themes/gitline/redline.theme.bash new file mode 100644 index 00000000..425c5897 --- /dev/null +++ b/themes/gitline/redline.theme.bash @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +. "$BASH_IT/themes/redline/powerline.base.bash" + +#For the logo +#PROMPT_DISTRO_LOGO="💻" +PROMPT_DISTRO_LOGO_COLOR=15 +PROMPT_DISTRO_LOGO_COLORBG=52 + +#Prompt Seperator Charactors +PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""} +POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:=""} + +#USER INFO CHARACTERS +USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=" "} +USER_INFO_SUDO_CHAR=${POWERLINE_USER_INFO_SUDO_CHAR:=" "} +USER_INFO_THEME_PROMPT_COLOR=91 +USER_INFO_THEME_PROMPT_COLOR_SUDO=1 + +PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:=" "} +CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="❲c❳ "} +PYTHON_VENV_THEME_PROMPT_COLOR=17 + +SCM_NONE_CHAR="" +SCM_GIT_CHAR=${POWERLINE_SCM_GIT_CHAR:=" "} +SCM_HG_CHAR=${POWERLINE_SCM_HG_CHAR:="☿ "} +SCM_THEME_PROMPT_CLEAN=" ✓ " +SCM_THEME_PROMPT_DIRTY=" ⨯ " +SCM_THEME_PROMPT_COLOR=91 +SCM_THEME_PROMPT_CLEAN_COLOR=41 +SCM_THEME_PROMPT_DIRTY_COLOR=94 +SCM_THEME_PROMPT_STAGED_COLOR=220 #52 +SCM_THEME_PROMPT_UNSTAGED_COLOR=81 +#SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} + + +RVM_THEME_PROMPT_PREFIX="" +RVM_THEME_PROMPT_SUFFIX="" +RBENV_THEME_PROMPT_PREFIX="" +RBENV_THEME_PROMPT_SUFFIX="" +RUBY_THEME_PROMPT_COLOR=161 +RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "} + +CWD_THEME_DIR_SEPARATOR="" +CWD_THEME_DIR_SEPARATOR_COLOR=52 +CWD_THEME_PROMPT_COLOR=252 + +HOST_THEME_PROMPT_COLOR=88 + +LAST_STATUS_THEME_PROMPT_COLOR=52 + +CLOCK_THEME_PROMPT_COLOR=240 + +BATTERY_AC_CHAR=${BATTERY_AC_CHAR:="⚡"} +BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=70 +BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=208 +BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160 + +THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} + +IN_VIM_THEME_PROMPT_COLOR=245 +IN_VIM_THEME_PROMPT_TEXT="vim" + +#POWERLINE_PROMPT=${POWERLINE_PROMPT:="python_venv ruby user_info hostname cwd scm"} +#POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby cwd"} + + +safe_append_prompt_command __powerline_prompt_command From 9a543ead482b0157cd7b774dcb1d7594c58e623c Mon Sep 17 00:00:00 2001 From: Zanark Date: Sat, 12 Oct 2019 13:15:24 +0530 Subject: [PATCH 2/5] renamed files --- themes/gitline/{redline.theme.bash => gitline.theme.bash} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename themes/gitline/{redline.theme.bash => gitline.theme.bash} (100%) diff --git a/themes/gitline/redline.theme.bash b/themes/gitline/gitline.theme.bash similarity index 100% rename from themes/gitline/redline.theme.bash rename to themes/gitline/gitline.theme.bash From f99ccbd1f20e2671821669458b5b704fecb3ed00 Mon Sep 17 00:00:00 2001 From: Zanark Date: Fri, 18 Oct 2019 11:13:19 +0530 Subject: [PATCH 3/5] Removed redundant code and added some descriptive comments --- themes/gitline/gitline.theme.bash | 12 ++++++------ themes/gitline/powerline.base.bash | 10 ++-------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/themes/gitline/gitline.theme.bash b/themes/gitline/gitline.theme.bash index 425c5897..3e6be360 100644 --- a/themes/gitline/gitline.theme.bash +++ b/themes/gitline/gitline.theme.bash @@ -2,7 +2,7 @@ . "$BASH_IT/themes/redline/powerline.base.bash" -#For the logo +#For the logo(Uncomment if you want a logo before your name) #PROMPT_DISTRO_LOGO="💻" PROMPT_DISTRO_LOGO_COLOR=15 PROMPT_DISTRO_LOGO_COLORBG=52 @@ -17,10 +17,12 @@ USER_INFO_SUDO_CHAR=${POWERLINE_USER_INFO_SUDO_CHAR:=" "} USER_INFO_THEME_PROMPT_COLOR=91 USER_INFO_THEME_PROMPT_COLOR_SUDO=1 +#PYTHON VENV PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:=" "} CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="❲c❳ "} PYTHON_VENV_THEME_PROMPT_COLOR=17 +#GIT Prompt Symbols SCM_NONE_CHAR="" SCM_GIT_CHAR=${POWERLINE_SCM_GIT_CHAR:=" "} SCM_HG_CHAR=${POWERLINE_SCM_HG_CHAR:="☿ "} @@ -31,9 +33,8 @@ SCM_THEME_PROMPT_CLEAN_COLOR=41 SCM_THEME_PROMPT_DIRTY_COLOR=94 SCM_THEME_PROMPT_STAGED_COLOR=220 #52 SCM_THEME_PROMPT_UNSTAGED_COLOR=81 -#SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} - +#Ruby Prompt Symbols RVM_THEME_PROMPT_PREFIX="" RVM_THEME_PROMPT_SUFFIX="" RBENV_THEME_PROMPT_PREFIX="" @@ -49,8 +50,10 @@ HOST_THEME_PROMPT_COLOR=88 LAST_STATUS_THEME_PROMPT_COLOR=52 +#Clock CLOCK_THEME_PROMPT_COLOR=240 +#For Battery Plugin BATTERY_AC_CHAR=${BATTERY_AC_CHAR:="⚡"} BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=70 BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=208 @@ -61,8 +64,5 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} IN_VIM_THEME_PROMPT_COLOR=245 IN_VIM_THEME_PROMPT_TEXT="vim" -#POWERLINE_PROMPT=${POWERLINE_PROMPT:="python_venv ruby user_info hostname cwd scm"} -#POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby cwd"} - safe_append_prompt_command __powerline_prompt_command diff --git a/themes/gitline/powerline.base.bash b/themes/gitline/powerline.base.bash index 925791fc..45387b02 100644 --- a/themes/gitline/powerline.base.bash +++ b/themes/gitline/powerline.base.bash @@ -1,4 +1,4 @@ -# Define this here so it can be used by all of the Powerline themes +# Sudo check after every command THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} #To set color for foreground and background @@ -75,7 +75,7 @@ function __powerline_python_venv_prompt { [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}|${fg_color}" } -#Customising SCM Prompt +#Customising SCM(GIT) Prompt function __powerline_scm_prompt { local color="" local scm_prompt="" @@ -83,7 +83,6 @@ function __powerline_scm_prompt { scm_prompt_vars - # echo "${scm}" if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then if [[ "${SCM_DIRTY}" -eq 3 ]]; then @@ -102,10 +101,6 @@ function __powerline_scm_prompt { color=${SCM_THEME_PROMPT_COLOR} fg_color=255 fi - # if [[ "${SCM_BRANCH}" == "master" ]]; then - # color=128 - # fg_color=251 - # fi if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" elif [[ "${SCM_P4_CHAR}" == "${SCM_CHAR}" ]]; then @@ -191,7 +186,6 @@ function __powerline_left_segment { separator="$(set_color ${LAST_SEGMENT_COLOR} ${params[1]})${separator_char}${normal}" fi #change here to cahnge fg color - #echo "${params[0]} -> ${params[1]} -> ${params[2]}" LEFT_PROMPT+="${separator}$(set_color ${params[2]} ${params[1]}) ${params[0]} ${normal}" #seperator char color = current bg LAST_SEGMENT_COLOR=${params[1]} From f0c1caa090ecd3614c5c83a7554fe8c6144ab294 Mon Sep 17 00:00:00 2001 From: Zanark Date: Mon, 4 Nov 2019 15:19:52 +0530 Subject: [PATCH 4/5] resolved powerline.base path issue --- themes/gitline/gitline.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/gitline/gitline.theme.bash b/themes/gitline/gitline.theme.bash index 3e6be360..5debacb6 100644 --- a/themes/gitline/gitline.theme.bash +++ b/themes/gitline/gitline.theme.bash @@ -1,6 +1,6 @@ #!/usr/bin/env bash -. "$BASH_IT/themes/redline/powerline.base.bash" +. "$BASH_IT/themes/powerline/powerline.base.bash" #For the logo(Uncomment if you want a logo before your name) #PROMPT_DISTRO_LOGO="💻" From fcc3631a9a55cea9901d74b3725e26a39a2da532 Mon Sep 17 00:00:00 2001 From: Zanark Date: Mon, 4 Nov 2019 15:22:18 +0530 Subject: [PATCH 5/5] resolved powerline.base path issue --- themes/gitline/gitline.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/gitline/gitline.theme.bash b/themes/gitline/gitline.theme.bash index 5debacb6..995b8c07 100644 --- a/themes/gitline/gitline.theme.bash +++ b/themes/gitline/gitline.theme.bash @@ -1,6 +1,6 @@ #!/usr/bin/env bash -. "$BASH_IT/themes/powerline/powerline.base.bash" +. "$BASH_IT/themes/gitline/powerline.base.bash" #For the logo(Uncomment if you want a logo before your name) #PROMPT_DISTRO_LOGO="💻"