【PS1】使用 ps1 裝飾自己的 terminal 吧!

前言

PS1 全名為 Prompt String 1
通常每次查 PS1 都會查到某遊戲機
總之如果不喜歡安裝很多東西來裝飾自己的 teminal,PS1 提供了非常輕量化的方式,
只要輸入指令就可以直接完成裝飾了!

幾個範例

以下製作為 script,可以放在 ~/.bashrc 裡面讓每次啟動終端機時自動執行 script

#!/bin/bash 
export PS1='🐧 \[\e[38;5;228;1m\]\T\[\e[0m\] | \[\e[38;5;177;1m\]\u\[\e[0m\] at \[\e[38;5;208;1m\]\h\[\e[0m\] in \[\e[38;5;156;1m\]\w\[\e[0m\] \[\e[38;5;159;1m\]$(git branch 2>/dev/null | grep '"'"'*'"'"' | colrm 1 2)
\[\e[0m\]> ' 
#!/bin/bash 
export PS1='👻 \[\e[38;5;228;1m\]\T\[\e[0m\] | \[\e[38;5;177;1m\]\u\[\e[0m\] at \[\e[38;5;208;1m\]\h\[\e[0m\] in \[\e[38;5;156;1m\]\w\[\e[0m\] \[\e[38;5;159;1m\]$(git branch 2>/dev/null | grep '"'"'*'"'"' | colrm 1 2)
\[\e[0m\]> ' 
#!/bin/bash 
export PS1='🐍 \[\e[38;5;228;1m\]\T\[\e[0m\] | \[\e[38;5;177;1m\]\u\[\e[0m\] at \[\e[38;5;208;1m\]\h\[\e[0m\] in \[\e[38;5;156;1m\]\w\[\e[0m\] \[\e[38;5;159;1m\]$(git branch 2>/dev/null | grep '"'"'*'"'"' | colrm 1 2)
\[\e[0m\]> '

好用網站

自己如果想自製,也很推薦使用網路上的 bash prompt generator,
相關的功能都已經視覺化做完了,只要視覺化的拉一拉就好

  • https://robotmoon.com/bash-prompt-generator/ 裡面還有參考的代稱
  • - https://bash-prompt-generator.org/

    Reference

    Licensed under CC BY-NC-SA 4.0