search

Friday, October 17, 2014

bash: Как изменить командную строку в bash

В bash командную строку можно изменить присвоив значение PS1 в терминале. Вот эта команда добавит время, полный путь в запрос, а также выведет его на следующую строку:
$ PS1="\[\033[01;32m\]\t \[\033[01;34m\]\w\[\033[00m\]\[\033[1;32m\]\n\$ \[\033[m\]"


Чтобы изменения сохранились после перезагрузки, добавьте эту строку в файл ~/.bashrc:
# Configure prompt
export PS1="\[\033[01;32m\]\t \[\033[01;34m\]\w\[\033[00m\]\[\033[1;32m\]\n\$ \[\033[m\]"

Список специальных символов:

\d The date, in "Weekday Month Date" format (e.g., "Tue May 26").


\h The hostname, up to the first . (e.g. deckard)


\H The hostname. (e.g. deckard.SS64.com)


\j The number of jobs currently managed by the shell.


\l The basename of the shell's terminal device name.


\s The name of the shell, the basename of $0 (the portion following the final slash).


\t The time, in 24-hour HH:MM:SS format.


\T The time, in 12-hour HH:MM:SS format.


\@ The time, in 12-hour am/pm format.


\u The username of the current user.


\v The version of Bash (e.g., 2.00)


\V The release of Bash, version + patchlevel (e.g., 2.00.0)


\w The current working directory.


\W The basename of $PWD.


\! The history number of this command.


\# The command number of this command.


\$ If you are not root, inserts a "$"; if you are root, you get a "#" (root uid = 0)


\nnn The character whose ASCII code is the octal value nnn.


\n A newline.


\r A carriage return.


\e An escape character.


\a A bell character.


\\ A backslash.


\[ Begin a sequence of non-printing characters. (like color escape sequences). This allows bash to calculate word wrapping correctly.


\] End a sequence of non-printing characters.


No comments:

Post a Comment