new render program prototype mostly finished
This commit is contained in:
parent
afd9900397
commit
cd3dd70b45
2 changed files with 441 additions and 189 deletions
59
zsh-init
59
zsh-init
|
@ -1,20 +1,11 @@
|
|||
#! /bin/zsh
|
||||
|
||||
autoload -U colors && colors
|
||||
|
||||
OVER_PROMPT_CFG="/etc/over/prompt.cfg"
|
||||
|
||||
if [[ -a "$OVER_PROMPT_CFG" ]]; then
|
||||
source "$OVER_PROMPT_CFG"
|
||||
fi
|
||||
|
||||
function strlen {
|
||||
local PLAIN
|
||||
PLAIN="$(echo $1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")"
|
||||
|
||||
echo ${#PLAIN}
|
||||
}
|
||||
|
||||
function set_title {
|
||||
if [[ ${TERM} == "screen-bce" || ${TERM} == "screen" ]]; then
|
||||
print -Pn "\033k\033${@}\033\134"
|
||||
|
@ -29,55 +20,11 @@ function preexec {
|
|||
}
|
||||
|
||||
function precmd {
|
||||
local CUT OVER_OPTS RAW_DATA LOGIN_PART STATS_PART DATA TOP_LEFT TOP_RIGHT PADDING PADDING_SIZE GIT_BRANCH COLOR
|
||||
set -A OVER_OPTS ${(s. .)OVER_PROMPT_OPTS}
|
||||
|
||||
PS1="$(print "%(?.%{\e[1;36m%}.%{\e[1;31m%}%?%{\e[0m%}:%{\e[1;31m%})%(\!.#.$)%{\e[0m%} ")"
|
||||
|
||||
RAW_DATA="$(/usr/share/over-prompt/data $OVER_OPTS[1] $OVER_OPTS[2] $OVER_OPTS[3])"
|
||||
|
||||
GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
|
||||
|
||||
if [[ -n "$GIT_BRANCH" ]]; then
|
||||
# rebuild index
|
||||
git update-index -q --ignore-submodules --refresh
|
||||
|
||||
# so that I can check if there are unstaged changes
|
||||
git diff-files --quiet --ignore-submodules
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
COLOR="%{\e[1;32m%}"
|
||||
else
|
||||
COLOR="%{\e[1;31m%}"
|
||||
fi
|
||||
|
||||
RPS1="$(print "$COLOR$GIT_BRANCH%{\e[0m%}")"
|
||||
else
|
||||
unset RPS1
|
||||
fi
|
||||
|
||||
if [[ -n "$RAW_DATA" ]]; then
|
||||
set -A DATA ${(s.:::.)RAW_DATA}
|
||||
LOGIN_PART=${DATA[1]}
|
||||
STATS_PART=${DATA[2]}
|
||||
|
||||
TOP_LEFT=$(print -P "%(\!.\e[1;31m.\e[1;32m)%n\e[0m@$LOGIN_PART")
|
||||
TOP_RIGHT=$(print -P "[ \e[1;36m%T\e[0m | $STATS_PART")
|
||||
PADDING_SIZE=$(($COLUMNS - $(strlen "$TOP_LEFT") - $(strlen "$TOP_RIGHT")))
|
||||
|
||||
# if [[ $PADDING_SIZE -lt 0 ]]; then
|
||||
# CUT=$((0 - $PADDING_SIZE))
|
||||
# TOP_LEFT="${TOP_LEFT[$CUT,-1]}"
|
||||
# fi
|
||||
|
||||
PADDING=$(printf " "%.0s {1..$PADDING_SIZE})
|
||||
|
||||
print "$TOP_LEFT$PADDING$TOP_RIGHT"
|
||||
else
|
||||
print -P "\e[5;31m!!! unable to run /usr/share/over-prompt/data\e[0m"
|
||||
fi
|
||||
python3 ./render.py $? $COLUMNS 1.25 2.5 0.15 0.05
|
||||
|
||||
set_title "${PWD}"
|
||||
}
|
||||
|
||||
unset OVER_PROMPT_CFG
|
||||
unset PS1
|
||||
unset RPS1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue