|
|
改善字符模式底下,目錄前進後退的方式。
在~/.profile寫下面這幾行
- function cd
- {
- if test "$@" = ".."
- then builtin cd ..
- elif test "$@" = "."
- then builtin cd .
- elif test "$@" = "-"
- then builtin cd -
- else pushd "$@">/dev/null
- fi
- }
- function bd { pushd +1>/dev/null; }
- function fd { pushd -0>/dev/null; }
- alias vd="dirs -v"
复制代码
在字符模式,可以使用cd進入目錄,bd (back directory)退回,fd (forward directory)往前,並使用vd,可以看到目錄堆疊的狀態。
- [root@jiunypc ~ ~]# cd /etc/cron.daily
- [root@jiunypc ~ cron.daily]# cd /var/lib/pacman/local
- [root@jiunypc cron.daily local]# bd
- [root@jiunypc ~ cron.daily]# fd
- [root@jiunypc cron.daily local]# vd
- 0 /var/lib/pacman/local
- 1 /etc/cron.daily
- 2 ~
- 3 ~
复制代码
然後我們希望字符底下的提示符號,可以告訴我們一些目錄的訊息,如下面的設定可以顯示成這個樣子.
- #jiunypc是你的主機名稱, rtorrent是你現在目錄的位址, etc是你前一個目錄的位址,
- #root是你的帳號,
- [root@jiunypc etc rtorrent]#
复制代码- blue=`tput setf 1`
- green=`tput setf 2`
- cyan=`tput setf 3`
- red2=`tput setf 4`
- pink=`tput setf 5`
- olive=`tput setf 6`
- gray=`tput setf 7`
- slategray=`tput setf 8`
- red=`tput setf 9`
- #如果顯示完整的目錄地址,那真的太長了,不美觀也浪費終端機的行數,
- #所以用basename這個指令取得比較短的地址。
- PS1="\[$green\][\[$blue\]\u@\h \[$red\]\$(basename \$(dirs +1)) \$(basename \$(dirs +0))\[$green\]]\[$olive\]#\[$red\] ";export PS1
复制代码
基本上一開始會提示如下的錯誤的訊息,不用管它。(那個沒關係)
- -bash: dirs: directory stack empty
- basename: missing operand
- 請嘗試執行‘basename --help’來獲取更多資訊。
复制代码
不然你也可以把這一行寫在~/.profile的最下面。
- #一開始先丟一個~給堆疊,避免$PS1提示錯誤
- pushd ~ >/dev/null
复制代码 |
|