You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
200 lines
5.7 KiB
200 lines
5.7 KiB
# Created by thomasba <mail@thomasba·de>
|
|
|
|
prompt_tba_help () {
|
|
cat <<EOH
|
|
This prompt is color-scheme-able. You can invoke it thus:
|
|
|
|
prompt tba [<text-color> [<parentheses-color> [<time-pwd-color>]]]
|
|
|
|
The default colors are white cyan. This theme works best with
|
|
a dark background.
|
|
EOH
|
|
}
|
|
|
|
prompt_tba_setup () {
|
|
setopt prompt_subst
|
|
|
|
local text_col=${1:-'white'}
|
|
local parens_col=${2:-'cyan'}
|
|
local time_col=${3:-'yellow'}
|
|
|
|
local text="%b%F{$text_col}"
|
|
local parens="%b%F{$parens_col}"
|
|
local punct="%B%F{black}"
|
|
local reset="%b%f"
|
|
|
|
local lpar="$parens($text"
|
|
local rpar="$parens)$text"
|
|
|
|
local time_color="%b%F{$time_col}"
|
|
local red="%B%F{red}"
|
|
local yellow="%B%F{yellow}"
|
|
local green="%b%F{green}"
|
|
local hostname="%B%F{green}"
|
|
local user_color="%b%F{green}"
|
|
if [[ "$(id -u)" = "0" ]] ; then
|
|
user_color="%B%F{red}"
|
|
fi
|
|
|
|
precmd () {
|
|
# let's get the current get branch that we are under
|
|
# ripped from /etc/bash_completion.d/git from the git devs
|
|
git_ps1 () {
|
|
if which git > /dev/null; then
|
|
local g="$(git rev-parse --git-dir 2>/dev/null)"
|
|
if [ -n "$g" ]; then
|
|
local r
|
|
local b
|
|
local date=$(git log --pretty=format:%cd --date=short -n1)
|
|
local v=$(git describe --tags --always)
|
|
if [ -d "$g/rebase-apply" ]; then
|
|
if test -f "$g/rebase-apply/rebasing"; then
|
|
r="|REBASE"
|
|
elif test -f "$g/rebase-apply/applying"; then
|
|
r="|AM"
|
|
else
|
|
r="|AM/REBASE"
|
|
fi
|
|
b="$(git symbolic-ref HEAD 2>/dev/null)"
|
|
elif [ -f "$g/rebase-merge/interactive" ]; then
|
|
r="|REBASE-i"
|
|
b="$(cat "$g/rebase-merge/head-name")"
|
|
elif [ -d "$g/rebase-merge" ]; then
|
|
r="|REBASE-m"
|
|
b="$(cat "$g/rebase-merge/head-name")"
|
|
elif [ -f "$g/MERGE_HEAD" ]; then
|
|
r="|MERGING"
|
|
b="$(git symbolic-ref HEAD 2>/dev/null)"
|
|
else
|
|
if [ -f "$g/BISECT_LOG" ]; then
|
|
r="|BISECTING"
|
|
fi
|
|
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
|
|
if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
|
|
b="$(cut -c1-7 "$g/HEAD")..."
|
|
fi
|
|
fi
|
|
fi
|
|
if [ -n "$1" ]; then
|
|
printf "$1·%s·%s" "${b##refs/heads/}$r" "$date" "$v"
|
|
else
|
|
printf "%s·%s·%s" "${b##refs/heads/}$r" "$date" "$v"
|
|
fi
|
|
fi
|
|
else
|
|
printf ""
|
|
fi
|
|
}
|
|
|
|
GITBRANCH="$(git_ps1)"
|
|
if [ -n "$GITBRANCH" ] ; then
|
|
GITBRANCH=" g:$GITBRANCH"
|
|
fi
|
|
|
|
# The following 9 lines of code comes directly from Phil!'s ZSH prompt
|
|
# http://aperiodic.net/phil/prompt/
|
|
local TERMWIDTH
|
|
(( TERMWIDTH = ${COLUMNS} - 1 ))
|
|
|
|
#local PROMPTSIZE=${#${(%):--- %D{%R.%S %a %b %d %Y}\! }}
|
|
local PROMPTSIZE=${#${(%):----%n-%m----0000-00-00 00:00----}}
|
|
|
|
local PWDSIZE=${#${(%):-%~}}
|
|
|
|
if [[ "$PROMPTSIZE + $PWDSIZE" -gt $TERMWIDTH ]]; then
|
|
(( PR_PWDLEN = $TERMWIDTH - $PROMPTSIZE ))
|
|
fi
|
|
|
|
# set a simple variable to show when in screen
|
|
if [[ -n "${WINDOW}" ]]; then
|
|
SCREEN=" S:${WINDOW}"
|
|
else
|
|
SCREEN=""
|
|
fi
|
|
|
|
# check if jobs are executing
|
|
if [[ $(jobs | wc -l) -gt 0 ]]; then
|
|
JOBS=" J:%j"
|
|
else
|
|
JOBS=""
|
|
fi
|
|
|
|
# I want to know my battery percentage when running on battery power
|
|
if which acpi &> /dev/null; then
|
|
local BATTSTATE="$(LANG=en_US acpi -b 2> /dev/null)"
|
|
local BATTPRCNT="$(echo ${BATTSTATE[(w)4]}|sed -r 's/(^[0-9]+).*/\1/')"
|
|
local BATTCHRG="$(echo ${BATTSTATE[(w)3]}|sed -r 's/(^[A-Za-z]+).*/\1/')"
|
|
# reset values
|
|
BAT=""
|
|
BAT_CHRG=""
|
|
BAT_CRIT=""
|
|
BAT_LOW=""
|
|
# set actual value
|
|
if [[ -z "${BATTPRCNT}" ]]; then
|
|
BAT=""
|
|
elif [[ "${BATTCHRG}" == "Charging" ]] ; then
|
|
BAT_CHRG=" ${green}B:${BATTPRCNT}%%"
|
|
elif [[ "${BATTPRCNT}" -lt 20 ]]; then
|
|
BAT_CRIT=" ${red}B:${BATTPRCNT}%%"
|
|
elif [[ "${BATTPRCNT}" -lt 40 ]]; then
|
|
BAT_LOW=" ${yellow}B:${BATTPRCNT}%%"
|
|
else
|
|
BAT=" B:${BATTPRCNT}%%"
|
|
fi
|
|
fi
|
|
|
|
|
|
IS_SSH_CONN=""
|
|
if [ -n "$SSH_CONNECTION" ] ; then
|
|
IS_SSH_CONN=" ⚡"
|
|
fi
|
|
IS_VENV=""
|
|
if [ -n "$VIRTUAL_ENV" ] ; then
|
|
IS_VENV=" 👻"
|
|
fi
|
|
}
|
|
|
|
# If I am using vi keys, I want to know what mode I'm currently using.
|
|
# zle-keymap-select is executed every time KEYMAP changes.
|
|
# From http://zshwiki.org/home/examples/zlewidgets
|
|
zle-keymap-select() {
|
|
VIMODE="${${KEYMAP/vicmd/ vim:command}/(main|viins)}"
|
|
RPROMPT2="${PR_BOLD_BLUE}${VIMODE}"
|
|
zle reset-prompt
|
|
}
|
|
zle -N zle-keymap-select
|
|
|
|
|
|
PS1="$parens┌─[ $user_color%n$text@$hostname%m$reset $parens]─($reset$time_color%D{%Y-%m-%d %H:%M}$reset$parens)─→ \
|
|
$reset$time_color%\${PR_PWDLEN}<...<%~%<<\
|
|
$reset\
|
|
|
|
$parens├─($red\${IS_SSH_CONN}%(?.. E:%?)$green\${BAT_CHRG}$yellow\${BAT_LOW}$red\${BAT_CRIT}$text\${BAT}\${SCREEN}\${JOBS}\
|
|
\${GITBRANCH}\${IS_VENV} $parens)$reset\
|
|
|
|
$parens└─[%(!.#.$)]${text} "
|
|
PS2="$parens└─[$reset $parens%_$reset $parens]──→$reset "
|
|
PS3="$parens╶─[$text?#$parens]──→$reset "
|
|
PS4="$parens├──→$reset "
|
|
prompt_opts=(cr subst percent)
|
|
}
|
|
|
|
prompt_tba_preview () {
|
|
local color colors
|
|
colors=(red yellow green blue magenta)
|
|
|
|
if (( ! $#* )); then
|
|
for (( i = 1; i <= $#colors; i++ )); do
|
|
color=$colors[$i]
|
|
prompt_preview_theme tba $color
|
|
(( i < $#colors )) && print
|
|
done
|
|
else
|
|
prompt_preview_theme tba "$@"
|
|
fi
|
|
}
|
|
|
|
#prompt_tba_setup "$@"
|
|
|
|
# Vim: set ft=zsh :
|