Loading... > 本文原发于旧站上,因为重配服务器时经常会用到,因此留此处备忘。 # 1 zsh ## 1.1 安装zsh: ``` apt-get install zsh ``` ## 1.2 修改默认Shell 设置zsh为默认: ``` chsh -s /bin/zsh ``` 设置bash为默认(如果想改回去): ``` chsh -s /bin/bash ``` 重新连接服务器即可看到效果。 ## 1.3 安装oh-my-zsh 参考官方Github上的说明如下: 用curl: ``` sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" ``` 用wget: ``` sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" ``` <details> <summary>一个可能遇到的问题</summary> 然而我的其中一个服务器总是报错“Public key signature verification has failed.” 参考 stackoverflow.com 上的一个回答 ,这个解决方法对我有效: ``` $ dpkg -l | grep libgnutls ii libgnutls-deb0-28:amd64 3.3.8-6+deb8u7 amd64 GNU TLS library - main runtime library ii libgnutls-openssl27:amd64 3.3.8-6+deb8u7 amd64 GNU TLS library - OpenSSL wrapper ii libgnutls30:amd64 3.5.8-5+deb9u3 amd64 GNU TLS library - main runtime library $ apt-get remove --purge libgnutls-deb0-28 ``` 然后再执行上面的安装命令就可以了。 </details> 安装过程服务器输出: ``` Cloning Oh My Zsh... Cloning into '/root/.oh-my-zsh'... remote: Counting objects: 849, done. remote: Compressing objects: 100% (708/708), done. remote: Total 849 (delta 18), reused 758 (delta 15), pack-reused 0 Receiving objects: 100% (849/849), 582.16 KiB | 0 bytes/s, done. Resolving deltas: 100% (18/18), done. Looking for an existing zsh config... Using the Oh My Zsh template file and adding it to ~/.zshrc __ __ ____ / /_ ____ ___ __ __ ____ _____/ /_ / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ / /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / \____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ /____/ ....is now installed! Please look over the ~/.zshrc file to select plugins, themes, and options. p.s. Follow us at https://twitter.com/ohmyzsh. p.p.s. Get stickers and t-shirts at https://shop.planetargon.com. ``` 这步成功以后,Shell界面应该出现了➜ ~ 。 让oh-my-zsh显示全路径: ``` nano ~/.oh-my-zsh/themes/robbyrussell.zsh-theme ``` 第二行中间有个`%c`,修改为`[$PWD]`。修改之后为: ``` PROMPT+=' %{$fg[cyan]%}[$PWD]%{$reset_color%} $(git_prompt_info)' ``` ## 1.4 auto suggestions ```shell git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions ``` Add the plugin to the list of plugins for Oh My Zsh to load (inside `~/.zshrc`): ```shell plugins=( # other plugins... zsh-autosuggestions ) ``` # 2 Powerline 参照官方文档,安装步骤如下: ## 2.1 安装Powerline ``` apt-get install python-pip #准备pip pip install powerline-status ``` 查看安装情况: ``` pip show powerline-status ``` 输出中含有 `Location: /usr/local/lib/python2.7/dist-packages`,因人而异。这是后续操作中的 `{repository_root}`。 ## 2.2 安装字体 对于Debian和Ubuntu,可以使用快速安装法: apt-get install fonts-powerline ## 2.3 整合进zsh 整合进各类Shell参见官方文档。 对于zsh,在 /root/下,vim .zshrc,在最后一行添加: ``` . {repository_root}/powerline/bindings/zsh/powerline.zsh #Location 和我一样的直接用这个即可:. /usr/local/lib/python2.7/dist-packages/powerline/bindings/zsh/powerline.zsh ``` `{repository_root}`是之前提到的Powerline安装的位置,不过这行代码有一个坑:最前面的点与后面的路径是有一个空格的! 重新连接Shell,发现Powerline的漂亮的面包屑导航出现了! ## 2.4 整合进Vim Powerline要求Vim在编译安装时添加python支持。所以一般首先需要重新安装Vim。 之后配置Vim: ``` vim /etc/vim/vimrc #编辑vimrc #在最后加入以下内容: set rtp+={repository_root}/powerline/bindings/vim/ #Location和我一样的用:set rtp+=/usr/local/lib/python2.7/dist-packages/powerline/bindings/vim/ set laststatus=2 set t_Co=256 ``` 重新进入Vim应该就能看到底部Powerline提供的状态栏了。 # 3 thefuck 用于纠正错误命令。 ## 3.1 环境配置 安装python3: ``` apt install python3-dev python3-pip ``` ## 3.2 安装thefuck ``` pip3 install thefuck ``` ## 3.3 配置 在zsh中添加支持: ``` vim .zshrc # 方法1 加入以下代码: eval $(thefuck --alias) # You can use whatever you want as an alias, like for Mondays: # 上行解释:这个是可以用别称来代替fuck,可能作者考虑到使用者想优雅一点。下面这行是用设定FUCK为别称之一的方法: # eval $(thefuck --alias FUCK) ``` 方法2 先后执行两遍fuck(有提示) ## 3.4 使用 在输入错误命令后,执行 fuck或者自己设定的别称即可…… Last modification:September 27, 2021 © Allow specification reprint Support Appreciate the author Like 0 如果觉得我的文章对你有用,请随意赞赏