Created
March 15, 2015 00:04
-
-
Save yongqli/c98665ef7dd1e254c6fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RPROMPT="%F{yellow}[%D{%H:%M:%S}]%f" | |
strlen () { | |
FOO=$1 | |
local zero='%([BSUbfksu]|([FB]|){*})' | |
LEN=${#${(S%%)FOO//$~zero/}} | |
echo $LEN | |
} | |
# show right prompt with date ONLY when command is executed | |
preexec () { | |
DATE=$( date +"[%H:%M:%S]" ) | |
local len_right=$( strlen "$DATE" ) | |
len_right=$(( $len_right+2 )) | |
local right_start=$(($COLUMNS - $len_right)) | |
local len_cmd=$( strlen "$@" ) | |
local len_prompt=$(strlen "$PROMPT" ) | |
local len_left=$(($len_cmd+$len_prompt)) | |
RDATE="\033[${right_start}C ${DATE}" | |
if [ $len_left -lt $right_start ]; then | |
# command does not overwrite right prompt | |
# ok to move up one line | |
echo -e "\033[1A${RDATE}" | |
else | |
echo -e "${RDATE}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment