首頁 美術繪圖 | 美術設計 | 熱門標籤 | 首選 | 首頁宣傳 | 近期作品 論壇: 發表 | 美術工作 | 美術比賽 | 展覽活動 | 美術相關 | 一般討論 | 美術同好 CG 討論 :: Photoshop | Painter | 3D 行動 | AMP

【 立即註冊 】 : 更改個人資料 : : 登入

會員名稱: 登入密碼: 保持登入

Bash Prompt Example: Color/User/Date/Time/Host/Path

發表新主題 回覆主題 討論區 Windows, Linux, Perl, PHP, C/C++, Driver, Web 理論、應用、硬體、軟體

| 1頁, 共1
人氣點閱:2327 發表人
Bash Prompt Example: Color/User/Date/Time/Host/Path 2014-03-03 13:23
/ / /

Bash Prompt Example: Color / User / Date / Time / Host / Path




1. User => \u
代碼:

\u


2. Color
代碼:

BOLD => \[\033[1m\]

RED => \[\033[31m\]

BOLD READ => \[\033[1;31m\]

GREEN => \[\033[32m\]

BOLD GREEN => \[\033[1;32m\]

YELLOW => \[\033[33m\]

BOLD YELLOW => \[\033[1;33m\]

BLUE => \[\033[34m\]

BOLD BLUE => \[\033[1;34m\]

OFF => \[\033[m\] or \[\e[0m\]


3. Host => \h
e.g. username@hostname prmpt
代碼:

\u@\h


4. Date (No Year) => \d
e.g. Mon Mar 03
代碼:

\d


5. Date (YYYY-MM-DD) => \D{Format}
e.g. 2012-08-15
代碼:

\D{%Y-%m-%d}


6. Unix Time Stamp => \D{%s}
e.g. 1365656566
代碼:

\D{%s}


7. Absolute Path => \w
e.g. ~username/myfolder/
代碼:

\w



8. New Lines => \n
e.g.
代碼:

\n



9. Related Path => \W
代碼:

\W



10. Time => \A \t
代碼:

\A     => 14:31      (24 HH:II)
\t     => 14:31:21  (24 HH:II:SS)
\T   =>  02:31:21  (12 HH:II Without AM/PM)
\@   =>  02:31 PM  (AM/PM will be translated up to your locale)



11. History Count => \#
代碼:

\#  ==> It will show how many commands in this shell (bash history counting)


Some bash prompt examples



Example #1: 'user@host $ '
代碼:

export PS1='\u@\h $ '


Example #2: Two lines with (1) First line Date Time (2) 2nd Line '>> ' prompt
代碼:

export PS1='\n\u@\h \[\d \t\] \w \n>> '


Example #3: BOLD + Colorful upon Example #2
代碼:

export PS1='\n\[\033[1;32m\]\u@\h \t \[\e[33m\]\w\[\e[0m\]\n>> '



See also: http://xor.tw/4zlm2
________________

美術插畫設計案子報價系統 v0.1 Beta
爪哇禾雀
Type



繪圖畫廊設計藝廊
攝影相簿留言板
最愛收藏分類標籤
暱稱: Type
註冊: 2002-11-30
發表: 11173
來自: vovo2000.com
V幣: 901761
Re: Bash Prompt Example: Color/User/Date/Time/Host/Path 2014-03-03 13:23
/ / /


See also
=> https://wiki.archlinux.org/index.php/Color_Bash_Prompt

Hate the "~" of \w? (Want the HOME directory to be absolute path as well!)
=> superuser.com/questions/202212/how-can-i-display-the-absolute-path-in-bash-prompt



Details PS1/PS2 Options


代碼:

              \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 (uses the value of the PROMPT_DIRTRIM vari‐
                     able)
              \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

________________

美術插畫設計案子報價系統 v0.1 Beta
爪哇禾雀
Type



繪圖畫廊設計藝廊
攝影相簿留言板
最愛收藏分類標籤
暱稱: Type
註冊: 2002-11-30
發表: 11173
來自: vovo2000.com
V幣: 901761





資訊相關理論、技術、管理、應用、產品等
發表新主題 回覆主題