云网牛站
所在位置:首页 > Linux教程 > 安装和使用Bash-it自定义Linux Bash Shell的方法

安装和使用Bash-it自定义Linux Bash Shell的方法

2019-04-30 09:44:16作者:叶云稿源:云网牛站

本文介绍使用Bash-it轻松自定义Linux Bash Shell的方法,此工具应位于任何Bash用户列表的最顶层,它可以帮助你快速配置更好看的bash shell。

 

在Linux上安装Bash-it

安装Bash-it只需将存储库从Github克隆到~/.bash_it目录即可:

git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it

应该安装git以使命令起作用,如下:

1、Ubuntu/Debian

$ sudo apt-get -y install git

2、CentOS/RHEL

$ sudo yum -y install git

参考:在CentOS 7系统中安装Git 2.20.1的方法

3、在Fedora上安装Git

$ sudo dnf -y install git

4、在Arch/Manjaro上安装git

$ sudo pacman -S git

克隆完成后,运行安装程序脚本,自动备份~/.bash_profile或~/.bashrc:

$ ~/.bash_it/install.sh

Would you like to keep your .bashrc and append bash-it templates at the end? [y/N] y

Your original .bashrc has been backed up to .bashrc.bak

Bash-it template has been added to your .bashrc

Enabling reasonable defaults

bash-it enabled with priority 350.

system enabled with priority 350.

base enabled with priority 250.

alias-completion enabled with priority 365.

general enabled with priority 150.

Installation finished successfully! Enjoy bash-it!

To start using it, open a new tab or 'source /jmutai/.bashrc'.

To show the available aliases/completions/plugins, type one of the following:

bash-it show aliases

bash-it show completions

bash-it show plugins

To avoid issues and to keep your shell lean, please enable only features you really want to use.

Enabling everything can lead to issues.

你的原始.bashrc已备份到.bashrc.bak,并在.bashrc文件的最后增加了bash-it模板。

参考:将.bashrc文件恢复到Ubuntu中的默认设置

 

在Linux上使用Bash-it

我们在Linux系统上安装了Bash-it,让我们激活bash环境来更新更改。

source ~/.bashrc

你的shell应该改变外观:

安装和使用Bash-it自定义Linux Bash Shell的方法

必须编辑修改后的配置(~/.bash_profile或~/.bashrc)文件才能自定义Bash-it。

Bash-it包括自动完成、主题、别名和定制功能,旨在提高你的终端生产力。以下是可用于显示这些配置的有用命令。

1、使用Bash-it别名

使用以下命令列出所有别名:

$ bash-it show aliases

默认情况下,大多数别名未启用,请使用以下命令启用它们:

$ bash-it enable alias  <alias name> [alias name]

例如:

1].为Vagrant启用别名

$ bash-it enable alias vagrant

vagrant启用优先级为150。

2].启用Ansible别名

$ bash-it enable alias ansible

要启用所有别名,请使用:

$ bash-it enable alias all

ag enabled with priority 150.

ansible enabled with priority 150.

apt enabled with priority 150.

atom enabled with priority 150.

bolt enabled with priority 150.

bundler enabled with priority 150.

clipboard enabled with priority 150.

composer enabled with priority 150.

curl enabled with priority 150.

docker enabled with priority 150.

docker-compose enabled with priority 150.

emacs enabled with priority 150.

fuck enabled with priority 150.

general is already enabled.

git enabled with priority 150.

gitsvn enabled with priority 150.

heroku enabled with priority 150.

hg enabled with priority 150.

homebrew enabled with priority 150.

homebrew-cask enabled with priority 150.

homesick enabled with priority 150.

jitsu enabled with priority 150.

kubectl enabled with priority 150.

laravel enabled with priority 150.

maven enabled with priority 150.

msys2 enabled with priority 150.

npm enabled with priority 150.

osx enabled with priority 150.

phoenix enabled with priority 150.

puppet enabled with priority 150.

pyrocms enabled with priority 150.

rails enabled with priority 150.

svn enabled with priority 150.

systemd enabled with priority 150.

textmate enabled with priority 150.

tmux enabled with priority 150.

todo.txt-cli enabled with priority 150.

vagrant is already enabled.

vault enabled with priority 150.

vim enabled with priority 150.

yarn enabled with priority 150.

yarn enabled with priority .

要显示别名的帮助,请运行:

$ bash-it help aliases

请参阅下面示例输出:

vagrant:

vhl='vagrant hosts list'

vscp='vagrant scp'

vsl='vagrant snapshot list'

vst='vagrant snapshot take'

vup="vagrant up'

vupl="vagrant up 2>&1 | tee vagrant.log'

vh="vagrant halt'

vs="vagrant suspend'

vr="vagrant resume'

vrl="vagrant reload'

vssh="vagrant ssh'

vst="vagrant status'

vp="vagrant provision'

vdstr="vagrant destroy'

vl="vagrant list'

vhst="vagrant hostmanager'

vault:

vad="vault delete'

val="vault list'

var="vault read'

varn="vault renew'

varv="vault revoke'

vasrv="vault server'

vas="vault status'

vav="vault version'

vaw="vault write'

vag="vault login -method=github'

varv="vault read -field=value'

要禁用别名,请运行:

$ bash-it disable alias  [alias name]…

或者:

$ bash-it disable alias all

2、使用Bash-it completions

列出所有已安装和可用的completions:

$ bash-it show completions

要启用completion,请执行以下操作:

$ bash-it enable completion  <completion name> [completion name]...

例:

$ bash-it enable completion vagrant virsh pip3 openshift packer knife docker

vagrant enabled with priority 350.

virsh enabled with priority 350.

pip3 enabled with priority 350.

openshift enabled with priority 350.

packer enabled with priority 350.

knife enabled with priority 350.

docker enabled with priority 350.

或者启用所有:

$ bash-it enable completion all

要显示已安装completions的帮助,请使用:

$ bash-it help completions

要禁用completion,请执行以下操作:

$ bash-it disable completion  <completion name> [completion name]...

或者:

$ bash-it disable completion all

3、使用Bash-it插件

插件用于扩展bash功能和功能,Bash-it自带了很多插件,可以通过这些插件解锁它们。

要列出可用插件,请使用以下命令:

$ bash-it show plugins

要启用插件,请使用:

$ bash-it enable plugin  <plugin name> [plugin name]...

或启用所有:

$ bash-it enable plugin all

此示例启用插件,用于显示有关电池电量的信息:

$ bash-it enable plugin battery

battery enabled with priority 250.

然后获取你的bashrc配置文件:

$ source ~/.bashrc

见以下输出:

安装和使用Bash-it自定义Linux Bash Shell的方法

要禁用插件,请执行以下操作:

$ bash-it disable plugin  [plugin name]…

或者

$ bash-it disable plugin all

4、使用搜索功能

Bash-it搜索功能用于快速找出特定框架,编程语言或环境可用的插件,别名或完成内容。

用它来查找与你的工作环境相关的内容,搜索语法是:

$ bash-it search term1 [[-]term2] [[-]term3]....

搜索与Python相关的所有内容:

$ bash-it search python pip

插件:pipsi python

completions:pip pip3 pipenv(参考:在Fedora系统上安装Pipenv的方法使用pip在Manjaro系统中安装pipenv的方法

或者对于Ruby开发人员:

$ bash-it search ruby rake gem bundle irb rails

别名:bundler rails

插件:chruby chruby-auto rails ruby

completions:bundler gem rake

启用的模块显示为绿色,可以在搜索字词前加上“-”,以将其从结果中排除:

$ bash-it search ruby rake gem bundle irb rails -chruby

通过向搜索命令添加--enable或--disable,可以自动启用由于搜索查询而出现的所有模块。

 

改变Bash-it主题

在$BASH_IT/themes中可以选择50多种Bash-it主题:

$ ls ~/.bash_it/themes/

要更改Bash主题,请将BASH_IT_THEME设置为要使用的主题名称:

$ vim ~/.bashrc

设置如下:

安装和使用Bash-it自定义Linux Bash Shell的方法

注意:Bash-it和一些主题使用UTF-8字符,因此请将你的语言环境设置为LC_ALL=en_US.UTF-8。

 

更新Bash-it和卸载Bash-it的方法

1、更新Bash-it

要将Bash-it更新为最新版本,只需运行:

$ bash-it update

Bash-it is up to date, nothing to do!

如果使用的是旧版本的Bash-it,建议使用migrate命令:

$ bash-it migrate

此命令将自动将Bash-it结构迁移到最新版本。

2、卸载Bash-it

要卸载Bash-it,请运行$BASH_IT目录中的uninstall.sh脚本:

$ cd $BASH_IT

$ ./uninstall.sh

Your original .bashrc has been restored.

Uninstallation finished successfully! Sorry to see you go!

Final steps to complete the uninstallation:

-> Remove the /home/jmutai/.bash_it folder

-> Open a new shell/tab/terminal

至此,Bash-it已成功删除掉了。

 

相关主题

在Ubuntu 18.04系统中自定义bash命令提示符的方法

精选文章
热门文章