Fix issue where super prompt would fail to delete text due to borked non-printing characters.
This commit is contained in:
parent
5297c7a7e9
commit
2fa5caec8a
|
@ -1,26 +1,8 @@
|
||||||
function colorize() {
|
# This file just contains some nice variable names for color codes.
|
||||||
local TEXT=$2
|
C_NO='\[\033[0m\]'
|
||||||
local NO_COLOR="\033[0m"
|
C_RED='\[\033[1;31m\]'
|
||||||
case "$1" in
|
C_GREEN='\[\033[1;32m\]'
|
||||||
red)
|
C_YELLOW='\[\033[1;33m\]'
|
||||||
local COLOR="\033[31m"
|
C_BLUE='\[\033[1;34m\]'
|
||||||
;;
|
C_MAGENTA='\[\033[1;35m\]'
|
||||||
green)
|
C_CYAN='\[\033[1;36m\]'
|
||||||
local COLOR="\033[32m"
|
|
||||||
;;
|
|
||||||
yellow)
|
|
||||||
local COLOR="\033[33m"
|
|
||||||
;;
|
|
||||||
blue)
|
|
||||||
local COLOR="\033[34m"
|
|
||||||
;;
|
|
||||||
magenta)
|
|
||||||
local COLOR="\033[35m"
|
|
||||||
;;
|
|
||||||
cyan)
|
|
||||||
local COLOR="\033[36m"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
echo -e "${COLOR}${TEXT}${NO_COLOR}"
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,38 +5,26 @@
|
||||||
src_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
src_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
source $src_dir/colorize.sh
|
source $src_dir/colorize.sh
|
||||||
|
|
||||||
function sp_git_info {
|
function sp_git {
|
||||||
# Get the current branch name
|
# Get the current branch name
|
||||||
local git_branch=$(git branch 2>/dev/null | grep "*" | cut -d ' ' -f 2) || ""
|
local git_branch=$(git branch 2>/dev/null | grep "*" | cut -d ' ' -f 2) || ""
|
||||||
|
|
||||||
# If we're in a git repo, add the repo (i.e. top-level directory) name, parens, and a newline
|
# If we're in a git repo, add the repo (i.e. top-level directory) name, and parens
|
||||||
if [ "$git_branch" != "" ]; then
|
if [ "$git_branch" != "" ]; then
|
||||||
local git_repo=$(git rev-parse --show-toplevel)
|
local git_repo=$(git rev-parse --show-toplevel)
|
||||||
git_branch=\($(colorize magenta ${git_repo//*\/})"|"$(colorize magenta ${git_branch})\)
|
git_repo=${git_repo//*\/}
|
||||||
printf "%s\n" "$git_branch"
|
echo "(${git_repo}|${git_branch})"
|
||||||
else
|
|
||||||
printf ""
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_path {
|
function sp_path {
|
||||||
local git_dir=$(git rev-parse --show-toplevel 2>/dev/null)
|
local git_dir=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||||
if [ "$git_dir" != "" ]; then
|
if [ "$git_dir" != "" ]; then
|
||||||
local path=$(colorize green ${PWD//$git_dir/\!})
|
local path=${PWD//$git_dir/\!}
|
||||||
else
|
else
|
||||||
local path=$(colorize green ${PWD//$HOME/\~})
|
local path=${PWD//$HOME/\~}
|
||||||
fi
|
fi
|
||||||
|
echo $path
|
||||||
printf $path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function super_prompt {
|
export PS1="[${C_YELLOW}\u${C_NO}@${C_BLUE}${HOSTNAME}${C_NO}:${C_GREEN}\$(sp_path)${C_NO}] ${C_MAGENTA}\$(sp_git)${C_NO}\n${C_RED}\$ ${C_NO}"
|
||||||
local user=$(colorize yellow $(whoami))
|
|
||||||
local host=$(colorize blue ${HOSTNAME})
|
|
||||||
local prompt_char=$(colorize red '$')
|
|
||||||
|
|
||||||
sp_git_info
|
|
||||||
printf "[%s@%s:%s]\n%s " "$user" "$host" "$(sp_path)" "$prompt_char"
|
|
||||||
}
|
|
||||||
|
|
||||||
export PS1="\$(super_prompt)"
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user