如何使终端动画的bash shell提示符? [英] How to make an animated bash shell prompt for the terminal?

查看:319
本文介绍了如何使终端动画的bash shell提示符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在终端的动画光标提示符(Ubuntu的14.04),

所以我使这个脚本:

I want to make an animated curser prompt in the terminal(Ubuntu 14.04),
so i make this script:


while [ : ]
do
    echo -ne '|\r'
    sleep 0.3
    echo -ne '/\r'
    sleep 0.3
    echo -ne '一\r'
    sleep 0.3
    echo -ne '\\ \r'
    sleep 0.3
    echo -ne '|\r'
    sleep 0.3
    echo -ne '$\r'
    sleep 0.3
done

但是,当我把它放在.bashrc中PS1 〜/ animated-prompt.sh&安培; 使其文本失真和我写的每一件事被重写 \\ r 字符。



所以反正有使这项工作?

(IDK,好像是把脚本比终端工作之外的其它进程中的线程)

But when i put it in the .bashrc ps1 ~/animated-prompt.sh & it make a text distortion and every thing i write is overridden by the \r character.

so Is there anyway to make this work ?
(IDK, like putting the script to another process thread other than the one that the terminal is working on)

推荐答案

保存和恢复光标位置,而不是\\ r。移动到你想要保存和恢复光标位置之间的动画所需的列位置。

save and restore cursor position instead of \r. Move to required column location where you want animation between saving and restoring cursor position.

有关光标移动参考 http://tldp.org/HOWTO/Bash-提示-HOWTO / x361.html

修改的脚本:

s="\033[s"
u="\033[u"

# Position of column
# As per my command prompt, i want 15th column( so 14C)
pos="\033[1000D\033[14C"
while [ : ]
do
    eval echo -ne '$s$pos\|$u'
    sleep 0.3
    eval echo -ne '$s$pos/$u'
    sleep 0.3
    eval echo -ne '$s$pos一$u'
    sleep 0.3
    eval echo -ne '$s$pos\\\\$u'
    sleep 0.3
    eval echo -ne '$s$pos\|$u'
    sleep 0.3
    eval echo -ne '$s$pos\$$u'
    sleep 0.3
done

[root@hello ~]|

当你使用,它的工作原理与.bashrc中最后一行

As you were using, it works with last line in .bashrc

感谢

这篇关于如何使终端动画的bash shell提示符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆