simplified the prompt code; bash support has been dropped
This commit is contained in:
parent
ba3eb640ec
commit
86f83ced55
2 changed files with 28 additions and 46 deletions
22
data.cpp
22
data.cpp
|
@ -76,6 +76,7 @@ enum {
|
|||
COL_BLUE,
|
||||
COL_RED,
|
||||
COL_RFLASH,
|
||||
COL_CYAN,
|
||||
COL_NONE
|
||||
};
|
||||
|
||||
|
@ -88,13 +89,14 @@ int main(int argc, char **argv) {
|
|||
|
||||
output[0] = 0;
|
||||
|
||||
color_map[COL_GREEN] = "|GREEN|";
|
||||
color_map[COL_DARKGREEN] = "|DARKGREEN|";
|
||||
color_map[COL_YELLOW] = "|YELLOW|";
|
||||
color_map[COL_BLUE] = "|BLUE|";
|
||||
color_map[COL_RED] = "|RED|";
|
||||
color_map[COL_RFLASH] = "|RFLASH|";
|
||||
color_map[COL_NONE] = "|NONE|";
|
||||
color_map[COL_GREEN] = "\e[1;32m";
|
||||
color_map[COL_DARKGREEN] = "\e[0;32m";
|
||||
color_map[COL_YELLOW] = "\e[1;33m";
|
||||
color_map[COL_BLUE] = "\e[1;34m";
|
||||
color_map[COL_RED] = "\e[1;31m";
|
||||
color_map[COL_RFLASH] = "\e[5;31m";
|
||||
color_map[COL_CYAN] = "\e[1;36m";
|
||||
color_map[COL_NONE] = "\e[0m";
|
||||
|
||||
ignored.push_back("rootfs");
|
||||
ignored.push_back("proc");
|
||||
|
@ -124,11 +126,11 @@ int main(int argc, char **argv) {
|
|||
get_memswap(space);
|
||||
get_sysload(sysload);
|
||||
|
||||
append(output, "|HOST|", sysload.color);
|
||||
append(output, "%m", sysload.color); // host
|
||||
append(output, ":");
|
||||
append(output, "|TTY|", COL_DARKGREEN);
|
||||
append(output, "%l", COL_DARKGREEN); // tty
|
||||
append(output, " ");
|
||||
append(output, "|CWD|", COL_DARKGREEN);
|
||||
append(output, "%~", COL_DARKGREEN); // cwd
|
||||
append(output, ":::");
|
||||
|
||||
for (unsigned int i = 0; i < space.size(); i++) {
|
||||
|
|
52
zsh-init
52
zsh-init
|
@ -6,26 +6,15 @@ if [[ -a "$OVER_PROMPT_CFG" ]]; then
|
|||
source "$OVER_PROMPT_CFG"
|
||||
fi
|
||||
|
||||
function tprompt_filter {
|
||||
PRT="$1"
|
||||
PRT="${PRT//|HOST|/%m}"
|
||||
PRT="${PRT//|TTY|/%l}"
|
||||
COLORLESS="$(print -P "%n@${PRT}"|sed 's/|[A-Z]*|//g')"
|
||||
PRT="${PRT//|GREEN|/\%\{\e[1;32m%\}}"
|
||||
PRT="${PRT//|RED|/\%\{\e[1;31m%\}}"
|
||||
PRT="${PRT//|RFLASH|/\%\{\e[5;31m%\}}"
|
||||
PRT="${PRT//|DARKGREEN|/\%\{\e[0;32m%\}}"
|
||||
PRT="${PRT//|YELLOW|/\%\{\e[1;33m%\}}"
|
||||
# PRT="${PRT//|BLUE|/\%\{\e[1;34m%\}}" # not used
|
||||
PRT="${PRT//|CYAN|/\%\{\e[1;36m%\}}"
|
||||
PRT="${PRT//|NONE|/\%\{\e[0m%\}}"
|
||||
((OFFSET = ${COLUMNS} - ${#COLORLESS} + 9))
|
||||
PRT="${PRT//|CWD|/%${OFFSET}<\\\\\\\\\\\\\\\<<%~%<<}" # 16x\ protoze to jde exponencialne pres 4 printy (kazdej jich polovinu sezere :)
|
||||
print "$PRT"
|
||||
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 precmd {
|
||||
local OVER_OPTS
|
||||
local OVER_OPTS RAW_DATA LOGIN_PART STATS_PART DATA TOP_LEFT TOP_RIGHT PADDING PADDING_SIZE
|
||||
set -A OVER_OPTS ${(s. .)OVER_PROMPT_OPTS}
|
||||
|
||||
RAW_DATA="$(/usr/share/over-prompt/data $OVER_OPTS[1] $OVER_OPTS[2] $OVER_OPTS[3])"
|
||||
|
@ -34,27 +23,18 @@ function precmd {
|
|||
set -A DATA ${(s.:::.)RAW_DATA}
|
||||
LOGIN_PART=${DATA[1]}
|
||||
STATS_PART=${DATA[2]}
|
||||
|
||||
PS1a="%(!.|RED|.|GREEN|)%n|NONE|@$LOGIN_PART"
|
||||
PS1b="%(?.|CYAN|.|RED|%?|NONE|:|RED|)%(!.#.$)|NONE| "
|
||||
RPS1="[ |CYAN|%T|NONE| | $STATS_PART"
|
||||
|
||||
# vyrenderovat
|
||||
PS1a="$(print "$(tprompt_filter "$PS1a")")"
|
||||
PS1b="$(print "$(tprompt_filter "$PS1b")")"
|
||||
RPS1="$(print "$(tprompt_filter "$RPS1")")"
|
||||
|
||||
PS1="$(print "$PS1a\n$PS1b")"
|
||||
RPS1="$(print $RPS1)"
|
||||
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")))
|
||||
PADDING=$(printf " "%.0s {1..$PADDING_SIZE})
|
||||
|
||||
print "$TOP_LEFT$PADDING$TOP_RIGHT"
|
||||
|
||||
PS1="$(print "%(?.\e[1;36m.\e[1;31m%?\e[0m:\e[1;31m)%(!.#.$)\e[0m ")"
|
||||
else
|
||||
PS1a="%(!.|RED|.|GREEN|)%n|NONE|@|HOST|:|DARKGREEN||TTY| |CWD|"
|
||||
PS1b="%(?.|CYAN|.|RED|%?|NONE|:|RED|)%(!.#.$)|NONE| "
|
||||
RPS1="[ |CYAN|%T|NONE| | |RFLASH|data gathering error|NONE|"
|
||||
PS1a="$(print "$(tprompt_filter "$PS1a")")"
|
||||
PS1b="$(print "$(tprompt_filter "$PS1b")")"
|
||||
|
||||
PS1="$(print "${PS1a}\n${PS1b}")"
|
||||
RPS1="$(print "$(tprompt_filter "$RPS1")")"
|
||||
print -P "\e[5;31m!!! unable to run /usr/share/over-prompt/data\e[0m"
|
||||
PS1="$(print "%(?.\e[1;36m.\e[1;31m%?\e[0m:\e[1;31m)%(!.#.$)\e[0m ")"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue