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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
128 changes: 115 additions & 13 deletions theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
# Git code based on https://github.com/joeytwiddle/git-aware-prompt/blob/master/prompt.sh
# More info about color codes in https://en.wikipedia.org/wiki/ANSI_escape_code

MULTILINE="YES" # set to "YES" to put add a \n before and after the prompt
SHORT_USER_INFO="YES" # set to "YES" to omit the hostname
SHORT_CWD="YES" # set to "YES" to show only the basename of the CWD
PADDING=" " # use this character sequence to pad the segments around the separators

PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""}
POWERLINE_LEFT_SEPARATOR=" "
POWERLINE_PROMPT="last_status user_info cwd scm"
POWERLINE_LEFT_SEPARATOR="${PADDING}"
POWERLINE_PROMPT="last_status python_virtual_env user_info cwd npm scm"

USER_INFO_SSH_CHAR=" "
USER_INFO_PROMPT_COLOR="C B"
USER_INFO_SSH_CHAR="${PADDING}"
USER_INFO_PROMPT_COLOR="C Bl"

SCM_GIT_CHAR=" "
VIRTUAL_ENV_PROMPT_COLOR="M B"


NPM_PROMPT_COLOR="Y Bl"

SCM_GIT_CHAR="${PADDING}"
SCM_PROMPT_CLEAN=""
SCM_PROMPT_DIRTY="*"
SCM_PROMPT_AHEAD="↑"
Expand All @@ -27,7 +36,7 @@ SCM_PROMPT_STAGED_COLOR="Y Bl"
SCM_PROMPT_UNSTAGED_COLOR="R Bl"
SCM_PROMPT_COLOR=${SCM_PROMPT_CLEAN_COLOR}

CWD_PROMPT_COLOR="B C"
CWD_PROMPT_COLOR="B Bl"

STATUS_PROMPT_COLOR="Bl R B"
STATUS_PROMPT_ERROR="✘"
Expand Down Expand Up @@ -75,19 +84,105 @@ function __color {
echo "\[\e[${mod};${fg};${bg}m\]"
}

function __powerline_python_virtual_env_prompt {
local venv_path="$VIRTUAL_ENV"
local color=${VIRTUAL_ENV_PROMPT_COLOR}
local venv_info=""
if [[ "$venv_path" != "" ]]; then
venv_info=$(basename $venv_path)
if [[ -f "venv/pyvenv.cfg" ]]; then
shopt -s extglob
configfile="venv/pyvenv.cfg" # set the actual path name of your (DOS or Unix) config file
while IFS=' =' read -r lhs rhs
do
if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
rhs="${rhs%%\#*}" # Del in line right comments
rhs="${rhs%%*( )}" # Del trailing spaces
rhs="${rhs%\"*}" # Del opening string quotes
rhs="${rhs#\"*}" # Del closing string quotes
if [[ ! $lhs == *-* ]]; then
declare $lhs="$rhs"
fi
fi
done < $configfile
if [[ -v prompt ]]; then
eval prompt=$prompt
venv_info="$prompt"
fi
else
venv_info=$(basename ${venv_path})
fi
fi
[[ -n "${venv_info}" ]] && echo "${PADDING}(${venv_info})${PADDING}|${color}"
}

function __powerline_user_info_prompt {
local user_info=""
local color=${USER_INFO_PROMPT_COLOR}
local hostname_escape="@\\h"
[[ "$SHORT_USER_INFO" == "YES" ]] && hostname_escape=""
if [[ -n "${SSH_CLIENT}" ]]; then
user_info="${USER_INFO_SSH_CHAR}\u@\h"
user_info="${USER_INFO_SSH_CHAR}\u${hostname_escape}"
else
user_info="\u@\h"
user_info="\u${hostname_escape}"
fi
[[ -n "${user_info}" ]] && echo "${user_info}|${color}"
[[ -n "${user_info}" ]] && echo "${PADDING}${user_info}${PADDING}|${color}"
}

function __powerline_cwd_prompt {
echo "\w|${CWD_PROMPT_COLOR}"
local cwd_escape="\\w"
[[ "$SHORT_CWD" == "YES" ]] && cwd_escape="\\W"
echo "${cwd_escape}${PADDING}|${CWD_PROMPT_COLOR}"
}

function __powerline_npm_prompt {
npm_package_file_name="package.json"
npm_package_file=""
git_top_level=""
npm_name=""
npm_version=""

find_git_top_level() {
git_top_level=$(git rev-parse --show-toplevel 2> /dev/null)
return 0
}

find_npm_package_file() {
npm_package_file="$npm_package_file_name"
if [ -n "$git_top_level" ]; then
git_top_level=$(sed 's/\([A-Za-z]\):/\/\L\1/' <<< "${git_top_level}")
npm_package_file="${git_top_level}/${npm_package_file}"
fi
if [ ! -f "$npm_package_file" ]; then
npm_package_file=""
return 1
fi
}

find_npm_name() {
if [[ -n "$npm_package_file" ]]; then
npm_name=$(awk -F '"' '/name/ {print $4}' $npm_package_file)
fi
}

find_npm_version() {
if [[ -n "$npm_package_file" ]]; then
npm_version=$(awk -F '"' '/version/ {print $4}' $npm_package_file)
fi
}

local color
local npm_info

find_git_top_level && find_npm_package_file && find_npm_name && find_npm_version

# not in NPM package
[[ -z "$npm_package_file" ]] && return

npm_info="${npm_name}@${npm_version}"
color=${NPM_PROMPT_COLOR}

[[ "$npm_info" != "@" ]] && echo "${npm_info}${PADDING}|${color}"
}

function __powerline_scm_prompt {
Expand Down Expand Up @@ -168,7 +263,7 @@ function __powerline_scm_prompt {
[[ -n "$git_behind" ]] && scm_info+="${SCM_PROMPT_BEHIND}${git_behind_count}"
[[ -n "$git_ahead" ]] && scm_info+="${SCM_PROMPT_AHEAD}${git_ahead_count}"

[[ -n "${scm_info}" ]] && echo "${scm_info}|${color}"
[[ -n "${scm_info}" ]] && echo "${scm_info}${PADDING}|${color}"
}

function __powerline_left_segment {
Expand All @@ -195,9 +290,11 @@ function __powerline_left_segment {

function __powerline_last_status_prompt {
local symbols=()
local stopped_jobs
read -N1 stopped_jobs < <(jobs -sp)
[[ $last_status -ne 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ERROR_COLOR})${STATUS_PROMPT_ERROR}"
[[ $UID -eq 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ROOT_COLOR})${STATUS_PROMPT_ROOT}"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="$(__color ${STATUS_PROMPT_JOBS_COLOR})${STATUS_PROMPT_JOBS}"
[[ ! -z "$stopped_jobs" ]] && symbols+="$(__color ${STATUS_PROMPT_JOBS_COLOR})${STATUS_PROMPT_JOBS}"

[[ -n "$symbols" ]] && echo "$symbols|${STATUS_PROMPT_COLOR}"
}
Expand All @@ -206,6 +303,8 @@ function __powerline_prompt_command {
local last_status="$?" ## always the first
local separator_char="${POWERLINE_PROMPT_CHAR}"

[[ "$MULTILINE" == "YES" ]] && separator_char="${POWERLINE_LEFT_SEPARATOR}"

LEFT_PROMPT=""
SEGMENTS_AT_LEFT=0
LAST_SEGMENT_COLOR=""
Expand All @@ -217,7 +316,10 @@ function __powerline_prompt_command {
done

[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(__color - ${LAST_SEGMENT_COLOR})${separator_char}$(__color)"
PS1="${LEFT_PROMPT} "

[[ "$MULTILINE" == "YES" ]] \
&& PS1="\n${LEFT_PROMPT}\n\$ " \
|| PS1="${LEFT_PROMPT} "

## cleanup ##
unset LAST_SEGMENT_COLOR \
Expand Down