这个 bash 插件是什么?

这个 bash 插件是什么?

我以前在 bash 中用过这个插件,每次输入命令后都会显示当前时间。几年前我添加了这个插件,但我不记得是怎么添加的了。它也没有列在 terminator 插件中。现在我要换一台新笔记本电脑了,我需要再次安装这个插件。

你们有人知道这个吗?谢谢。

在此处输入图片描述

答案1

此脚本将添加一条灰色虚线,并在行尾显示日期和时间,如果您以 root 用户身份运行,它将变为红色:

在此处输入图片描述


/home/<username>/.bashrc在两个文件的底部添加以下几行/root/.bashrc笔记: /root/.bashrc必须使用 root 权限进行编辑,例如sudo gedit /root/.bashrc

if [ -f "$HOME/.bash_ps1" ]; then
    . "$HOME/.bash_ps1"
fi

将以下代码复制并粘贴到名为的新文件中 /home/<username>/.bash_ps1

# Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="--- "

reset_style='\[\033[00m\]'

# determine if root or not
a=$(id -u)
if [ "$a" = 0 ]
then
    # for root
    status_style=$reset_style'\[\033[1;31m\]' # bold red; use 0;37m for lighter color
    command_style=$reset_style'\[\033[1;31m\]' # bold red
else
    # for other users
    status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
    command_style=$reset_style'\[\033[1;29m\]' # bold black
fi
prompt_style=$reset_style

# Prompt variable:

PS1="$status_style"'$fill $(date +"%m/%d/%y ")\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}-18
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

接下来,在文件夹中创建一个链接/root,以便在切换到root用户时调用它:

sudo -s
cd /root
ln -s /home/<username>/.bash_ps1

保存完所有内容后,现在每次打开新的终端窗口时,它都应该像上面的图片一样。在终端中输入每个命令后按下 Enter 键,就会出现时间戳,这样可以更轻松地向后滚动并查看运行该特定命令的时间。

希望这可以帮助!

答案2

这可能会有帮助。另一种可能是 oh-my-zsh。

我安装了这个,并且使用了这个主题rkj

我的终端是这样的,

┌─[luvpreet@DHARI-Inspiron-3542] - [~] - [2017-08-28 06:45:20]
└─[0] 

首先,它显示当前用户和主机名( luvpreet@DHARI-Inspiron-3542)。然后,它告诉您当前所在的目录( ~)。然后是当前时间( 2017-08-28 06:45:20)。然后是您所运行的上一个命令的状态代码( 0(successful))。

您可以在此处查看。 https://github.com/robbyrussell/oh-my-zsh 那里还有很多其他很酷的主题可供选择。

相关内容