如何從 Debian 的終端機提示符號中刪除路徑?

如何從 Debian 的終端機提示符號中刪除路徑?

在命令列中,長目錄路徑可能會佔據整行:

長工作目錄路徑

類似的問題也被問過:

  1. 在終端機中隱藏目錄路徑
  2. 從終端機中刪除“PWD”
  3. 從終端刪除完整路徑
  4. 展示bash 提示字元下僅顯示目前目錄名稱

採取的步驟:

  • 在 Debian 中找到 .bashrc 文件 /etc/bash.bashrc
  • 從終端機中的 /etc 目錄:sudo gedit bash.bashrc
  • 找到該行:PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  • 將小寫“w”改為大寫“W”(粗體):

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\\$ '

  • 保存(如 sudo)並重新載入 .bashrc 文件暫時解決了問題,但在新的終端機視窗中沒有解決。顏色也會改變(綠色和藍色被淘汰,所有文字都變成白色)

答案1

您可能有自己的PS1定義~/.bashrc(除非您是 root)覆蓋系統範圍/etc/bash.bashrc(沒有顏色)。你應該PS1在那裡編輯。

在我看來,~/.bashrc這些PS1東西看起來像這樣(預設的 Debian 延伸):

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

第一個定義是帶有顏色的定義。換成你的\w,你應該會很好。\W~/.bashrc

相關內容