• [daily] 宇宙终极shell之zsh


    很久以前,我就知道zsh。后来在并不遥远的好几年前,第一次装arch的时候,默认shell就是zsh。虽然用起来不太习惯,但是仍然蛮好用的。

    决定好好的学一下zsh,如果可以就切换过去,毕竟bash兼容。最近最大的感悟,就是时刻要跟上潮流,学习时髦的东西 :)不要被年轻人淘汰掉。。。

    老实说,第一次用zsh的时候,我并没有觉得怎么样,反而觉得用着bash古朴一下,也没什么不好的。直到头两天体验了一下fish,一下子被惊艳到了。遂决定果断跨入新时代!

    参考

    圣教读物zsh-archwiki (接触任何新东西之前,第一件事就是先回圣教翻翻文档,已然成了习惯)

    高级阅读http://zsh.sourceforge.net/Guide/

    zsh号称宇宙终极shell;同时还要另一个宇宙终极shell fish。据说fish才是真正的终极shell。

    区别在于,fish没有zsh那么多繁杂的配置,开箱即用。但是fish不完全兼容bash。zsh完全兼容bash。

    我毕竟还是要工作的,工作里大部分还是用bash,所以还是首选zsh。

    zsh最被人诟病的是配置,然而没关系,因为我们有了ohmyzsh 。

    开始

    安装:

    pacman -S zsh

    将默认shell切换为zsh:

    [tong@T7 tss_sys]$ chsh -l
    /bin/sh
    /bin/bash
    /bin/zsh
    /usr/bin/zsh
    [tong@T7 tss_sys]$ chsh -s /usr/bin/zsh tong

    当然还可以使用另外两个方式:

      A. 编辑/etc/passwd, 找到用户的对应行,修改。

      B. 使用usermod命令。并不推荐。因为它并不检查-s的参数有效性,写错就完蛋鸟。

    [tong@TStation ~]$ usermod -s /usr/bin/zsh tong

      总之,推荐使用chsh。

    配置:

      当你第一次运行bash的时候,它会检查$HOME目录下是否存在配置文件.zsh,如果不存在,会进入配置引导程序,如下:

    This is the Z Shell configuration function for new users,
    zsh-newuser-install.
    You are seeing this message because you have no zsh startup files
    (the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
    ~).  This function can help you with a few settings that should
    make your use of the shell easier.
    
    You can:
    
    (q)  Quit and do nothing.  The function will be run again next time.
    
    (0)  Exit, creating the file ~/.zshrc containing just a comment.
         That will prevent this function being run again.
    
    (1)  Continue to the main menu.
    
    --- Type one of the keys in parentheses --- 

    如果没有进入,可以使用以下命令进入:

    $ zsh /usr/share/zsh/functions/Newuser/zsh-newuser-install -f

     配置完成后,可以把 .bashrc 中的配置项拷贝到 .zshrc 中。至此,就可以想之前的bash一样正常工作了。

    不过有一点值得注意的,环境变了PATH需要设置在.zprofile文件中,如下:

    Configuring $PATH
    Normally, the path should be set in ~/.zshenv, but Arch Linux sources /etc/profile after sourcing ~/.zshenv.
    To prevent your $PATH being overwritten, set it in ~/.zprofile.

    为了兼容bash,arch在打包时,给/etc/zprofie文件中加了一行,详细内容,见圣教wiki。

    截止目前,基本功能已经可以使用,其他高级功能都是需要配置的,所以暂时都用不了。可没关系,因为我们有ohmyzsh。

    我是这样的,T7中我装了oh-my-zsh 为了快速体验。TStation我只配置到了截止到目前为止,我准备慢慢的读zsh的手册,慢慢的自己配起来。

    懒惰的单身汉:

    1. 安装 oh-my-zsh 一个zsh的配置框架,zsh存在了很多年了(不知道在哪里看到的80年代就有了?懒得去找了),直到ohmyzsh的出现,才使zsh在地下慢慢的流行起来。装了之后就不需要去啃手册了。真正的开箱即用。

    [tong@TStation ~]$ yaourt -S aur/oh-my-zsh-git

    安装完成后,设置zsh使用oh-my-zsh插件。

    [tong@TStation ~]$ mv .zshrc .zshrc.bak
    [tong@TStation ~]$ cp /usr/share/oh-my-zsh/zshrc .zshrc
    [tong@TStation ~]$ 

    选择一个喜欢的主题吧:

    如果没有喜欢的,不要紧,more is here

    ➜  ~ ls /usr/share/oh-my-zsh/themes |head -n 3                      
    3den.zsh-theme
    adben.zsh-theme
    af-magic.zsh-theme
    ➜  ~~ sed "s/ZSH_THEME=".*"/ZSH_THEME="apple"/" -i .zshrc 

    这还不够,我们需要,fish一下的命令颜色 zsh-syntax-highlighting 。我们将使用zsh以及新的主题,完成这个安装。

    /home/tong [tong@TStation] [17:08]
    > yaourt -S zsh-syntax-highlighting 

    这是一个zsh插件,在zshrc中启动之,在最后添加一行:

    /home/tong [tong@TStation] [17:14]
    > tail -n1 .zshrc 
    source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
    
    /home/tong [tong@TStation] [17:14]
    > 

    至此,就有了丰富的颜色。

    下一个,不知道干嘛的,大概是补全用的,也不是插件,zsh-completions 反正这样用的:

    /home/tong [tong@TStation] [17:29]
    > sudo pacman -S zsh-completions

    /home/tong [tong@TStation] [17:32]
    > tail -n 3 .zshrc
    autoload -U compinit && compinit

    /home/tong [tong@TStation] [17:33]
    > source .zshrc

    最后一个插件,zsh-autosuggestions 这个插件,其实我并不建议使用,因为提示出来的建议,你在颜色上并区分不出来,所以经常把自己搞迷糊。它并不像fish一样是浅色的。而且,据说还会有一下小问题,总之,目前还不太成熟。

    /home/tong [tong@TStation] [17:35]
    > proxychains yaourt -S zsh-autosuggestions 
    /home/tong [tong@TStation] [17:40]
    > tail -n 3 .zshrc
    source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
    
    /home/tong [tong@TStation] [17:40]
    > source .zshrc 

    好了,配好了,开心的coding吧 :)

    勤劳的好少年:

    勤劳的好少年,定然不屑于使用ohmyzsh的。那就自己去配好了,谁要管你!!!

    Let‘s Begin here: http://zsh.sourceforge.net/Guide/

    Good luck!

    来个基础配置先: 之后的慢慢来~~~

    TStation% cat .zshrc
    # Created by newuser for 5.2
    
    alias ls='ls --color=auto'
    alias ll='ls -l --color=auto'
    
    source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
    source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
    
    autoload -Uz compinit
    compinit
    TStation% 

    to be continue...

  • 相关阅读:
    cookie和session的区别和用法
    JavaScript深浅拷贝
    前端知识
    typescript -- ts
    vue笔记精华部分
    宜人贷项目里-----正则匹配input输入月份规则
    PHP-Socket-阻塞与非阻塞,同步与异步概念的理解
    PHP socket客户端长连接
    PHP exec/system启动windows应用程序,执行.bat批处理,执行cmd命令
    查看局域网内所有ip
  • 原文地址:https://www.cnblogs.com/hugetong/p/6053334.html
Copyright © 2020-2023  润新知