one-line if-then-elses
This commit is contained in:
parent
bb9e173fd2
commit
c1fc8c0151
25
prompt.sh
25
prompt.sh
@ -1,12 +1,8 @@
|
|||||||
function enrich {
|
function enrich {
|
||||||
flag=$1
|
flag=$1
|
||||||
symbol=$2
|
symbol=$2
|
||||||
if [[ $flag == "true" ]]
|
|
||||||
then
|
if [[ $flag == true ]]; then color="${on}"; else color="${off}"; fi
|
||||||
color="${on}"
|
|
||||||
else
|
|
||||||
color="${off}"
|
|
||||||
fi
|
|
||||||
PS1="${PS1}${color}${symbol} "
|
PS1="${PS1}${color}${symbol} "
|
||||||
}
|
}
|
||||||
function enrich_if_not_null {
|
function enrich_if_not_null {
|
||||||
@ -49,18 +45,26 @@ function enrich_if_greater_than_zero {
|
|||||||
|
|
||||||
function build_prompt {
|
function build_prompt {
|
||||||
PS1=""
|
PS1=""
|
||||||
off="\[\033[1;30m\]"
|
|
||||||
on="\[\033[0;37m\]"
|
on="\[\033[0;37m\]"
|
||||||
|
off="\[\033[1;30m\]"
|
||||||
|
red="\[\033[0;31m\]"
|
||||||
branch_color="\[\033[0;34m\]"
|
branch_color="\[\033[0;34m\]"
|
||||||
blinking="\[\033[1;5;17m\]"
|
blinking="\[\033[1;5;17m\]"
|
||||||
reset="\[\033[0m\]"
|
reset="\[\033[0m\]"
|
||||||
|
|
||||||
current_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
|
current_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
|
||||||
|
if [[ -n "${current_branch}" ]]
|
||||||
|
then
|
||||||
|
is_a_git_repo=true
|
||||||
|
else
|
||||||
|
is_a_git_repo=false
|
||||||
|
fi
|
||||||
enrich_if_not_null "❤" $current_branch
|
enrich_if_not_null "❤" $current_branch
|
||||||
enrich_if_equal "⚯" "${current_branch}" "HEAD"
|
enrich_if_equal "⚯" "${current_branch}" "HEAD"
|
||||||
|
|
||||||
number_of_modifications=$(git status --short 2> /dev/null|grep --count -e ^\.M)
|
number_of_modifications=$(git status --short 2> /dev/null|grep --count -e ^\.M)
|
||||||
enrich_if_greater_than_zero "✎" "${number_of_modifications}"
|
if [[ ${number_of_modifications} -gt 0 ]] ; then has_modifications=true; else has_modifications=false; fi
|
||||||
|
enrich $has_modifications "✎"
|
||||||
|
|
||||||
number_of_modifications_cached=$(git status --short 2> /dev/null|grep --count -e ^M)
|
number_of_modifications_cached=$(git status --short 2> /dev/null|grep --count -e ^M)
|
||||||
enrich_if_greater_than_zero "→" "${number_of_modifications_cached}"
|
enrich_if_greater_than_zero "→" "${number_of_modifications_cached}"
|
||||||
@ -68,7 +72,10 @@ function build_prompt {
|
|||||||
number_of_untracked=$(git status --short 2> /dev/null|grep --count -e ^\?\?)
|
number_of_untracked=$(git status --short 2> /dev/null|grep --count -e ^\?\?)
|
||||||
enrich_if_greater_than_zero "∿" "${number_of_untracked}"
|
enrich_if_greater_than_zero "∿" "${number_of_untracked}"
|
||||||
|
|
||||||
#PS1="${PS1} - ${on}${current_branch}"
|
if [[ ${is_a_git_repo} == true ]]
|
||||||
|
then
|
||||||
|
PS1="${PS1} ${on}(${current_branch})"
|
||||||
|
fi
|
||||||
PS1="${PS1}${reset} :"
|
PS1="${PS1}${reset} :"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user