为OSX的Terminal增加时间分割线

在Terminal中的每个命令之间增加时间分割线,提高可阅读性。打开Terminal应用,确认当前位置在用户根目录中,将.bash_profile文件备份。

cp .bash_profile .bash_profile-backup

编辑.bash_profile文件,在最后添加以下代码:

############################################
# Modified from emilis bash prompt script
# from https://github.com/emilis/emilis-config/blob/master/.bash_ps1
#
# Modified for Mac OS X by
# @corndogcomputer
###########################################
# Fill with minuses

# (this is recalculated every time the prompt is shown in function prompt_command):

fill=”— ”

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””$fill \\t\\n””$prompt_style””${debian_chroot:+($debian_chroot)}\\u@\\h:\\w\\$””$command_style ”

# Reset color for command output

# (this one is invoked every time before a command is executed):

trap ”echo -ne “\\033[00m”” DEBUG

function prompt_command {

# create a $fill of all screen width minus the time string and a space:

let fillsize=${COLUMNS}-9

fill=””

while [ “$fillsize” -gt “0” ]

do

fill=”-${fill}” # fill with underscores 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

保存退出,重新打开Terminal,即可看见效果。

来源:http://osxdaily.com/2011/10/03/add-a-separator-time-stamp-between-terminal-commands-to-increase-readability/