[Mac] 맥 터미널 프롬프트 설정하기(Prompt Terminal)
OperationSystem

[Mac] 맥 터미널 프롬프트 설정하기(Prompt Terminal)

맥 터미널의 간단한 프롬프트 설정으로 보다 편한 업무 수행을 할 수 있는데요.

오늘은 터미널 프롬프트를 원하는데로 설정하는 방법을 알아보겠습니다.

 

프롬프트란?

명령어 입력줄을 가리켜, 'Command Prompt', '커맨드 프롬프트', 'Shell Prompt' 라고 합니다.

바로 죠기 저 부분이죠.

 

맥 터미널을 처음으로 접하게 되면 보통 '누구누구's MacBook' 혹은 'Imac'등으로 설정 되어있습니다. 여기서 '누구누구'는 컴퓨터의 홈 폴더 이름으로 보통 나타납니다. 굳이 바꿀 필요는 없지만 상황에 맞게 프롬프트를 설정하면 터미널 사용시 훨씬 편하게 사용할 수 있습니다.

프롬프트 설정은 개인의 편의에 따라 달라집니다. 저 같은 경우,

현재 유저 이름 + 시간 + 현재 디렉토리 위치 + $(구분자)

이 조합으로 프롬프트를 구성했습니다. 내가 사용하는 유저의 이름 그리고 현재 디렉토리 위치를 수시로 확인할 수 있기 때문이죠!

 

현재 설정된 프롬프트 확인하는 법!

먼저, 현재 나의 프롬프트 설정을 확인하기 위해선 'echo' 명령어를 사용합니다.

PS1 = "EMPLOYEE" -> 임시 변경

PS1="원하는 프롬프트" 이런식으로 명령어를 입력하면 프롬프트 설정이 바뀌는것으로 확인할 수 있습니다. 하지만 이 방법은 임시로 바꾸는 방법으로 만약 터미널 종료 후 다시 터미널을 열면 값이 초기화 된것을 확인할 수 있습니다.

 

.bash_profile 변경하기 -> 영구적용

영구적인 사용을 위해선 .bash_profile에 PS1 변수 값을 조정해줘야 합니다.

1. vi 편집기로 .bash_profile 을 수정합니다.

sudo vi .bash_profile

 

2. 맨 뒷줄에 새로운 PS1 변수값을 작성합니다.

3. 작성이 끝나면 esc 버튼을 누룬 후 :wq!로 저장 후 나갑니다.

 

Escape Sequence

프롬프트 설정시 사용할 수 있는 Excape 문입니다.

 

\a     an ASCII bell character (07)
\d     the date  in  "Weekday  Month  Date"  format (e.g., "Tue May 26")
\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
\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 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
\]     end a sequence of non-printing characters