一个bash的PS1,网上找到的,略做修改
发表于 : 2012-08-21 4:25
原文地址:http://www.ubuntubuzz.com/2012/04/add-s ... ds-on.html
把下面的代码保存为~/.bash_ps1,在~/.bashrc最后加上下面一段
然后
即可看到效果。
[bash]
# Fill with dashes
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="—" # note here I use half dash of chinese syle.
reset_style='\[\033[00m\]'
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[\033[1;29m\]' # bold black
# Prompt variable:
PS1="$status_style""working in "'\e[1;31m\w\e[m'"$status_style"' $fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\$'"$command_style "
# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\e[0m"' DEBUG
let length=$(echo "$HOME" |wc -m)
function prompt_command {
if [ -n "`echo $(pwd) |grep "$HOME"`" ]
then
let plength=$(pwd |wc -m)-${length}+2
else
let plength=$(pwd |wc -m)
fi
# create a $fill of all screen width minus the hints, path, time string and a space:
let fillsize=${COLUMNS}-${plength}-21
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="—${fill}" # fill with horizontal line to work on
let fillsize=${fillsize}-1
done
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
bname=`basename "${PWD/$HOME/~}"`
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
;;
*)
;;
esac
}
PROMPT_COMMAND=prompt_command
[/bash]
代码: 全选
if [ -f "$HOME/.bash_ps1" ]; then
. "$HOME/.bash_ps1"
fi
代码: 全选
. ~/.bash_ps1
[bash]
# Fill with dashes
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="—" # note here I use half dash of chinese syle.
reset_style='\[\033[00m\]'
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[\033[1;29m\]' # bold black
# Prompt variable:
PS1="$status_style""working in "'\e[1;31m\w\e[m'"$status_style"' $fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\$'"$command_style "
# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\e[0m"' DEBUG
let length=$(echo "$HOME" |wc -m)
function prompt_command {
if [ -n "`echo $(pwd) |grep "$HOME"`" ]
then
let plength=$(pwd |wc -m)-${length}+2
else
let plength=$(pwd |wc -m)
fi
# create a $fill of all screen width minus the hints, path, time string and a space:
let fillsize=${COLUMNS}-${plength}-21
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="—${fill}" # fill with horizontal line to work on
let fillsize=${fillsize}-1
done
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
bname=`basename "${PWD/$HOME/~}"`
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
;;
*)
;;
esac
}
PROMPT_COMMAND=prompt_command
[/bash]