一个bash的PS1,网上找到的,略做修改

sh/bash/dash/ksh/zsh等Shell脚本
回复
funicorn
帖子: 1318
注册时间: 2005-09-13 4:56
系统: Ubuntu Jammy Jellyfi

一个bash的PS1,网上找到的,略做修改

#1

帖子 funicorn » 2012-08-21 4:25

原文地址:http://www.ubuntubuzz.com/2012/04/add-s ... ds-on.html
gnome-terminal
gnome-terminal
把下面的代码保存为~/.bash_ps1,在~/.bashrc最后加上下面一段

代码: 全选

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]
头像
link_01
帖子: 1024
注册时间: 2008-11-05 13:24

Re: 一个bash的PS1,网上找到的,略做修改

#2

帖子 link_01 » 2012-08-21 9:56

我还是用简单换行吧

代码: 全选

linkOx@debian:/var/tmp
$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\n\$
linkOx@debian:/var/tmp
$ 
笔记
-------------------------------------
http://blog.163.com/wqt_1101
tusooa
帖子: 6548
注册时间: 2008-10-31 22:12
系统: 践兔
联系:

Re: 一个bash的PS1,网上找到的,略做修改

#3

帖子 tusooa » 2012-08-27 14:08

● echo $PS1
%{%}$(tlcr-check) $(date-now) %{%}%{%}%m%{%} $_prompt_color%{%}$_prompt_pwd%{%} $(get_prompt_git)
%{%}%{%}●%{%}

代码: 全选

] ls -ld //
回复