터미널 창 프롬프트 텍스트를 변경할 수 있습니까?


11

터미널 창 기본 프롬프트 텍스트가 너무 많은 공간을 차지합니다 (컴퓨터 이름이 너무 길 것 같습니다).

이것을 사용자 정의 할 수 있습니까?

답변:


12

예, PS1환경 변수로 사용자 정의 할 수 있습니다.

파일 .bash_profile이나 .profile파일 에 다음과 같은 것을 넣어서 설정할 수 있습니다 .

PS1="your prompt"

공간을 많이 차지하지 않는 매우 간단한 bash 프롬프트를 원한다면 (찾고있는 것 같습니다) 다음과 같이 현재 디렉토리를 표시하도록 설정할 수 있습니다.

PS1="\w "

이것은 많은 bash PS1 이스케이프 시퀀스\w 중 하나입니다 . 이것은 현재 디렉토리로 확장됩니다.


4

이것은 내 / etc / prompt 파일이며 / etc / profile에서 제공합니다. 이름, 기계 이름, 디렉토리 이름, 사용자에 따라 색상별로 색상을 사용하며 대부분 bash 맨 페이지의 일부 부분이 뻔뻔한 사본입니다.

#
# PROMPTING
#       When  executing  interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the sec-
#       ondary prompt PS2 when it needs more input to complete a command.  Bash allows these prompt strings to be  customized
#       by inserting a number of backslash-escaped special characters that are decoded as follows:
#              \a     an ASCII bell character (07)
#              \d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
#              \D{format}
#                     the  format is passed to strftime(3) and the result is inserted into the prompt string; an empty format
#                     results in a locale-specific time representation.  The braces are required
#              \e     an ASCII escape character (033)
#              \h     the hostname up to the first `.'
#              \H     the hostname
#              \j     the number of jobs currently managed by the shell
#              \l     the basename of the shell's terminal device name
#              \n     newline
#              \r     carriage return
#              \s     the name of the shell, the basename of $0 (the portion following the final slash)
#              \t     the current time in 24-hour HH:MM:SS format
#              \T     the current time in 12-hour HH:MM:SS format
#              \@     the current time in 12-hour am/pm format
#              \A     the current time in 24-hour HH:MM format
#              \u     the username of the current user
#              \v     the version of bash (e.g., 2.00)
#              \V     the release of bash, version + patchelvel (e.g., 2.00.0)
#              \w     the current working directory
#              \W     the basename of the current working directory
#              \!     the history number of this command
#              \#     the command number of this command
#              \$     if the effective UID is 0, a #, otherwise a $
#              \nnn   the character corresponding to the octal number nnn
#              \\     a backslash
#              \[     begin a sequence of non-printing characters, which could be used to embed a terminal  control  sequence
#                     into the prompt
#              \]     end a sequence of non-printing characters
#
#       The  command  number and the history number are usually different: the history number of a command is its position in
#       the history list, which may include commands restored from the history file (see HISTORY below),  while  the  command
#       number  is  the  position in the sequence of commands executed during the current shell session.  After the string is
#
# colors:
# \[...\]   needed, so the shell knows, that this isn't printable output, and newlines are placed at the right position.
#
# ANSI COLORS
CRE="\[
[K\]"
NORMAL="\[[0;39m\]"
# RED: Failure or error message
RED="\[[1;31m\]"
# GREEN: Success message
GREEN="\[[1;32m\]"
# YELLOW: Descriptions
YELLOW="\[[1;33m\]"
# BLUE: System messages
BLUE="\[[1;34m\]"
# MAGENTA: Found devices or drivers
MAGENTA="\[[1;35m\]"
# CYAN: Questions
CYAN="\[[1;36m\]"
# BOLD WHITE: Hint
WHITE="\[[1;37m\]"
#
# default:
# postgres, oracle
#
# PS1=$BLUE"asux]->"$NORMAL\\w"$BLUE ø $NORMAL"
PS1=$BLUE"asux]:"$NORMAL\\w"$BLUE > $NORMAL"
#
# root, stefan:
#
case "$UID" in
    '0')
        PS1=$RED"asux:"$NORMAL\\w"$RED # $NORMAL"
    ;;
    '1000')
    PS1=$GREEN"asux:"$BLUE\\w$YELLOW" > "$NORMAL
    ;;
#    default)
#    ;;
esac

asux내 컴퓨터 이름입니다. 컴퓨터 이름으로 바꾸십시오. 일반 사용자와 수퍼 유저에게는 서로 다른 색상 (루트의 경우 빨간색)과 프롬프트 (>의 경우 사용자, #의 경우)를 사용하는 것이 일반적입니다. ssh를 자주 사용하는 경우 2-3 개의 다른 호스트를 사용하는 경우 시스템 이름과 다른 색상이 유용합니다.

사용자 'postgresql'또는 'oracle'의 색상이 다르지만 더 이상 필요하지 않습니다.

사용자 별 프롬프트 스크린 샷

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.