우선 : BASH 셸을 사용하고 있는지 확인하십시오.
저는 MacBook의 Mountain Lion에 있고 PS1 명령은 일종의 일종입니다. 내 프롬프트는 다음과 같습니다.
⌘ ~/SVN-Precommit-Kitchen-Sink-Hook.git/ (master) _
질문에 대한 답은 무엇을 원하는지 궁금합니다. BASH 프롬프트는 모든 종류의 깔끔한 것들을 처리 할 수있는 모든 종류의 이스케이프 시퀀스를 내장 할 수 있습니다. Kornshell은 해킹을 거의하지 않을 것입니다.
유형 man bash
을 입력하고 PROMPTING 표제를 찾으십시오. 다음과 같이 표시됩니다.
When executing interactively, bash displays the primary prompt PS1 when it is ready to read a com-
mand, and the secondary 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 + patch level (e.g., 2.00.0)
\w the current working directory, with $HOME abbreviated with a tilde
\W the basename of the current working directory, with $HOME abbreviated with a tilde
\! 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
간단한 프롬프트를 봅시다. 내 사용자 이름, 현재있는 시스템 및 현재 디렉토리를 표시하려고합니다.나는이 같은 PS1을 설정할 수 있습니다
PS1="\[email protected]\h:\w$ "
이 나에게 줄 것이다 :
[email protected]:~$ _
가 \u
내 사용자 이름 (데이비드)되면, \h
내 컴퓨터 이름 (davebook) 및 \w
표시입니다 현재 디렉토리는 내 $HOME
디렉토리와 관계가 있습니다.
은 또한 너무 프롬프트에서 명령을 포함 할 수 있습니다 :
지금 날짜와 시간이 내 메시지에 포함됩니다
PS1="\$(date) \[email protected]\h:\w$ "
: 바보의
Fri Feb 1 09:45:53 EST 2013 [email protected]:~
정렬 (I 날짜를 포맷해야 게다가, BASH는 이미 날짜에 대한 시퀀스를 구축했습니다.)하지만 당신은 그 아이디어를 얻었습니다.
나 자신 만의 메시지를 작성하는 것이 좋습니다. 만약 사용자가 git
이라면 명령 행을 편안하게 사용하고있을 것입니다. 원하는 방법을 찾기 위해 스스로 신속하게 명령을 내릴 수 있습니다. \$(command)
구문을 사용하여 새로운 PS 명령을 실행할 때마다 실행되는 대화식 명령을 포함 할 수 있습니다. ANSI escape codes을 사용하여 프롬프트의 다른 부분을 색칠하거나 환상적인 것을 만들 수 있습니다.
프롬프트를 천천히 그리고 비트 단위로 빌드하십시오. PS1
를 설정하는 쉘 스크립트를 작성하고,이처럼의 소스 : 당신은 당신이하고자하는 일을 할 때까지
$ echo "PS='\[email protected]\h:\w\$ " > prompt.sh
$ chmod a+x prompt.sh
$ . prompt.sh
그런 다음, 프롬프트에 더 많은 기능을 추가 할 수 있습니다.
개인적으로 나는 적어도 예상치 못한 경우 가끔 혼란스러워하기 때문에 개인적으로 멋진 메시지를 피합니다. 예를 들어, VI 시퀀스를 편집에 사용하고 명령 행을 편집하려고 할 때마다 프롬프트가 완전히 떨어져 버립니다.
화려한 프롬프트는 Talking Moose과 같은 프로그램을 생각 나게합니다. 처음 몇 분 동안은 정말 멋지다. 그 다음에 정말 짜증나기도합니다.
나는 내 문제를 해결할 때 다른 대답을 받아 들였지만, 할 수만 있다면 대답을 +1000 할 것이다. 나는이 작품을 어떻게 사용했는지 몰랐기 때문에이 스 니펫을 사용했고, 지금 당신 덕분에! 기본적으로 git 브랜치가 필요했기 때문에 나중에 쓸모없는 부분을 제거하기 위해 나 자신의 프롬프트를 확실히 만들려고 노력할 것입니다. 다시 한 번 감사드립니다! – romainberger
이 답변의 결론에 전적으로 동의합니다. 귀하의 프롬프트를 적응 일반적으로 잘 작동합니다. 내 경험에 비추어 볼 때 색상 순서를 가져 오면 백 스페이스, 기록 및 줄 바꿈과 관련하여 프롬프트에서 이상한 동작이 발생할 수 있습니다. 나는 며칠 동안 다채로운 프롬프트를 즐겼다. 그리고 컬러 컨트롤 시퀀스를 다시 제거했다. 이제 bash는 다시 잘 작동한다. 'll' 출력을 색칠하는 것은 전혀 문제가되지 않습니다. –