terminal 右边显示时间

警告
本文最后更新于 2019-05-13,文中内容可能已过时。

~/.oh-my-zsh/themes/agnoster.themes 增加

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

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+1 ))
    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}"

        # Black='\033[30m'        # Black
        # Red='\033[31m'          # Red
        # Green='\033[32m'        # Green
        # Yellow='\033[33m'       # Yellow
        # Blue='\033[34m'         # Blue
        # Purple='\033[35m'       # Purple
        # Cyan='\033[36m'         # Cyan
        # White='\033[37m'        # White

        echo -e "\033[1A\033[36m${RDATE}\033[36m"

    else
        echo -e "${RDATE}"
    fi

}

相关内容

william 支付宝支付宝
william 微信微信
0%