静看光阴荏苒
不管不顾不问不说也不念

Zsh和Oh My Zsh的安装配置

能偷懒就偷点懒,我开始用zsh了,主要是看上了自动补全功能。。一直我都不怎么敢用,因为有时候可能一条命令错了就没办法挽回了。。然后我找了一下除了等下要装的自动补全插件以外还有一个代码高亮的插件,这个插件可以显示出当前你输的命令是对的还是错的,对的就显示绿色,错的就是红色,这样也算可以综合一下吧。

安装zsh:

apy -y install wget git nano
apt -y install zsh
yum -y install wget git nano
yum -y install epel-release && yum -y install zsh

把shell切换为zsh然后重新登录:

chsh -s /bin/zsh

安装oh-my-zsh:

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

安装自动补全和代码高亮插件:

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

修改ohmyzsh的配置文件:

nano ~/.zshrc

修改下面的位置,启用自动补全和代码高亮插件:

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

修改自动补全的底色:

nano ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

找到这一行,修改fg=后面的内容:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=cyan'

此处颜色默认支持:black/red/green/yellow/blue/magenta/cyan/white。因为我个人是习惯使用Xshell的NewBlack配色,所以这个地方我把颜色都设置了然后测试了一下,发现只有cyan比较符合一点。。

然后是ohmyzsh默认的主题把主机名/当前用户/当前所在路径都隐藏掉了,说实话我有点不习惯,然后就自己修改了一下,把这些重新显示出来:

cd ~/.oh-my-zsh/themes
cp robbyrussell.zsh-theme imlala.zsh-theme
nano imlala.zsh-theme

把PROMPT改为下面我这样:

PROMPT='%{$fg_bold[yellow]%}%n@%m ${ret_status} %{$fg[cyan]%}%d%{$reset_color%} $(git_prompt_info)'

然后修改配置文件:

nano ~/.zshrc

主题改成刚才自定义的:

ZSH_THEME="imlala"

使之前的这些更改生效(最好还是直接重新登录一次):

source ~/.zshrc

如果不想用了,需要还原成默认的shell:

cat /etc/shells
chsh -s /bin/bash

样式和自动补全的效果,比原生的还是方便很多的:

我觉得我要写个一键安装脚本了,这样一台台机器去装太鸡儿麻烦了。。。

下面附一张ohmyzsh自定义主题的代码表格,也许以后会用到:

代码说明
%T系统时间(时:分)
%*系统时间(时:分:秒)
%D系统日期(年-月-日)
%n你的用户名
%B - %b开始到结束使用粗体打印
%U - %u开始到结束使用下划线打印
%d你目前的工作目录
%~你目前的工作目录相对于~的相对路径
%M计算机的主机名
%m计算机的主机名(在第一个句号之前截断)
%l你当前的tty
%n登录名
赞(8)
未经允许不得转载:荒岛 » Zsh和Oh My Zsh的安装配置
分享到: 更多 (0)

评论 14

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    看起来zsh比bash舒服啊

    TheEastWind5年前 (2019-02-17) Google Chrome 72.0.3626.109 Google Chrome 72.0.3626.109 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 那肯定的。。主题插件多的眼花缭乱。。

      LALA5年前 (2019-02-17) Google Chrome 71.0.3578.98 Google Chrome 71.0.3578.98 Windows 10 x64 Edition Windows 10 x64 Edition回复
  2. #2

    最近文章缩略图画风不对啊,LALA同学 :lol:

    唐风月5年前 (2019-02-17) Google Chrome 71.0.3578.80 Google Chrome 71.0.3578.80 Windows 10 x64 Edition Windows 10 x64 Edition回复
  3. #3

    强烈要求写个脚本,,每台都安装的确麻烦 :eek:

    qianmianyao5年前 (2019-02-22) WebView 4.0 WebView 4.0 Android 8.1.0 Android 8.1.0回复
    • 安排上了,什么时候能够产出就不知道了。。。

      LALA5年前 (2019-02-23) Google Chrome 71.0.3578.98 Google Chrome 71.0.3578.98 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • 大佬,,我根据你的教程写了一个脚本,,但是有sed替换字符串达到修改配置的那个部分实现的有问题,,你看你能不能改改 :cry:
        https://github.com/zp1998421/shell/blob/master/zsh.sh

        千面妖5年前 (2019-03-02) Google Chrome 72.0.3626.119 Google Chrome 72.0.3626.119 Windows 10 x64 Edition Windows 10 x64 Edition回复
        • 可以的,很不错了,我有空直接在你这个基础上改。。 :wink:

          LALA5年前 (2019-03-03) Google Chrome 71.0.3578.98 Google Chrome 71.0.3578.98 Windows 10 x64 Edition Windows 10 x64 Edition回复
        • 主要这几天在搞Cydia相关的东西。。。可能时间不是很够。。 :razz:

          LALA5年前 (2019-03-03) Google Chrome 71.0.3578.98 Google Chrome 71.0.3578.98 Windows 10 x64 Edition Windows 10 x64 Edition回复
          • 脚本我已经改完了,,,已经可以直接一建配置了 :mrgreen:

            qianmianyao5年前 (2019-03-03) WebView 4.0 WebView 4.0 Android 8.1.0 Android 8.1.0
          • 可以的。

            LALA5年前 (2019-03-04) Google Chrome 71.0.3578.98 Google Chrome 71.0.3578.98 Windows 10 x64 Edition Windows 10 x64 Edition
  4. #4

    然而你的第一条命令就写错了 :shock:

    Hotdog645年前 (2019-03-02) Google Chrome 72.0.3626.119 Google Chrome 72.0.3626.119 Windows 10 x64 Edition Windows 10 x64 Edition回复
  5. #5

    為什麼不用fish?

    none5年前 (2019-03-03) Google Chrome 72.0.3626.119 Google Chrome 72.0.3626.119 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 其实我是更喜欢fish一点,因为很满足我的需求,但是很无奈啊,兼容性差了点。

      LALA5年前 (2019-03-04) Google Chrome 71.0.3578.98 Google Chrome 71.0.3578.98 Windows 10 x64 Edition Windows 10 x64 Edition回复

分享创造快乐

广告合作资源投稿