优雅的配置linux终端

2024-01-17 14:23:43 浏览数 (2)

欢迎关注R语言数据分析指南

❝最近发现很多初次使用linux系统的朋友不太习惯使用Tab进行路径补齐,从而导致在输入路径时经常出现bug,本节来介绍如何修改ubuntu默认的bash与zsh来优化终端。 ❞

bash修改

代码语言:javascript复制
vim ~/.bashrc

找到bashrc中下方内容的字符,将前方的#去除修改为如下内容即可,经过如此修改就可以使用Tab键进行补齐了。

修改前bashrc

代码语言:javascript复制
#enable programmable completion features (you don't need to enable
#this, if it's already enabled in /etc/bash.bashrc and /etc/profile
#sources /etc/bash.bashrc).
#if ! shopt -oq posix; then
#if [ -f /usr/share/bash-completion/bash_completion ]; then
#    . /usr/share/bash-completion/bash_completion
# elif [ -f /etc/bash_completion ]; then
#   . /etc/bash_completion
# fi
#fi

修改后bashrc

代码语言:javascript复制
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
代码语言:javascript复制
source ~/.bashrc

上方为系统默认bash的修改方法,但是目前使用bash已经比较落伍了,现在主流使用zsh即「oh-my-zsh」

zsh

代码语言:javascript复制
sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

这段代码主要下载了install.sh文件并进行了安装,如果实际运行中下载不了可公众号后台回复「zsh」获取小编下载好的安装包.

后续配置

代码语言:javascript复制
sudo usermod -s /usr/bin/zsh $(whoami) #设置zsh为默认
# 配置 zsh
sudo apt install powerline fonts-powerline #安装字体

sudo apt install zsh-theme-powerlevel9k #安装主题

echo "source /usr/share/powerlevel9k/powerlevel9k.zsh-theme" >> ~/.zshrc

sudo apt install zsh-syntax-highlighting # 安装语法并启用高亮插件

echo "source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc 

source ~/.zshrc

还可以修改zshrc中的ZSH_THEME参数设置更多的主题

0 人点赞