Onde o registro de data e hora desse script define o prompt?

3

Eu encontrei este post antigo , que eu acho útil. Agora, estou tentando, mas em vão, dizer qual parte dele é responsável por imprimir o timestamp no final dos traços.

O seguinte é o script para facilitar a referência:

# Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="—- "
reset_style='\[3[00m\]'
status_style=$reset_style'\[3[0;90m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[3[1;29m\]' # bold black

# Prompt variable:
PS1="$status_style"'$fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w\$'"$command_style "

# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\e[0m"' DEBUG

function prompt_command {
    # create a $fill of all screen width minus the time string and a space:
    let fillsize=${COLUMNS}-9
    fill=""
    while [ "$fillsize" -gt "0" ]
    do
        fill="-${fill}" # fill with underscores to work on
        let fillsize=${fillsize}-1
    done

    # If this is an xterm set the title to user@host:dir
    case "$TERM" in
    xterm*|rxvt*)
        bname='basename "${PWD/$HOME/~}"'
        echo -ne "3]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}
# Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="—- "
reset_style='\[3[00m\]'
status_style=$reset_style'\[3[0;90m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[3[1;29m\]' # bold black

# Prompt variable:
PS1="$status_style"'$fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w\$'"$command_style "

# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\e[0m"' DEBUG

function prompt_command {
    # create a $fill of all screen width minus the time string and a space:
    let fillsize=${COLUMNS}-9
    fill=""
    while [ "$fillsize" -gt "0" ]
    do
        fill="-${fill}" # fill with underscores to work on
        let fillsize=${fillsize}-1
    done

    # If this is an xterm set the title to user@host:dir
    case "$TERM" in
    xterm*|rxvt*)
        bname='basename "${PWD/$HOME/~}"'
        echo -ne "3]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}%pre%7"
        ;;
    *)
        ;;
    esac
}

PROMPT_COMMAND=prompt_command
7" ;; *) ;; esac } PROMPT_COMMAND=prompt_command

Alguma dica?

    
por joker 20.12.2017 / 22:19

1 resposta

6

É o \t nessa linha que compõe o prompt inteiro, incorporando as variáveis (incluindo fill que fornece os traços) que foram atribuídos:

PS1="$status_style"'$fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w\$'"$command_style "

Em PS1 , \t é uma sequência de escape do Bash que imprime a corrente tempo.

Teste:

zanna@toaster:~$ PS1="\t"
21:33:06
    
por Zanna 20.12.2017 / 22:32