windows 10 linux子系统oh-my-zsh与Cmder配置-2018

教程主要写做目的是为了解决配置过程当中遇到的各类问题,让其余人少走弯路。

1. 起步

  • Linux 子系统开启
  • Cmder安装

略过git

2.配置Cmder

WSL是Linux子系统专用模式。github

  1. 很好的解决的VIM下上下左右导航键无效。
  2. 启动时不在当前目录下。

2.1 为多个子系统配置启动

启动设置项vim

代码
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl --distro-guid={xxxxxxxxxxxxxxxxxxxxxx} -cur_console:pm:/mntwindows

其中子系统惟一标识符,每一个人的都不同。bash

在注册表(regedit)中查找xss

计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss字体

小提示:
由于系统版本不一样,注册表路径可能不彻底相同。
但后面路径 xxxSoftwareMicrosoftWindowsCurrentVersionLxss 应该是相同的。ui

Cmder配置完成

启动效果图spa

3. oh-my-zsh配置

安装任何包以前必定要先更新!
sudo apt-get update.net

3.1 安装zsh

sudo apt-get install zsh

3.2 安装oh-my-zsh

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

若是 遇到证书相似问题
apt-get install ca-certificates

3.3 自动启动zsh

vim ~/.bashrc

if test -t 1; then
    exec zsh
fi

3.4 修改主题

vim ~/.zshrc
ZSH_THEME="agnoster"

终端字体补全
sudo apt-get install fonts-powerline

客户端字体补
注意: 有些字符在windows 上没法显示,因此须要安装字体
nerdfonts.com
选择 Hack

还要设置Cmder字体

更新配置 或者重启终端
source ~/.zshrc

总体效果



若是你是Sublime玩家,能够配合Terminal插件快速调出终端。

Terminal配置Cmder路径
Packages Settings >> Terminal >> Setting - User

{
  "terminal": "D:\\Cmder\\Cmder.exe",
  "parameters": ["/START", "%CWD%"]
}

设置自定义快捷键
Packages Settings >> Terminal >> Key Bindings - Default

[
    { "keys": ["ctrl+t"], "command": "open_terminal" },
    { "keys": ["ctrl+shift+alt+t"], "command": "open_terminal_project_folder" }
]

4. zsh插件安装

4.1 安装命令提示

代码

cd ~/.oh-my-zsh/plugins/
mkdir incr && cd incr
wget http://mimosa-pudica.net/src/incr-0.2.zsh
vim ~/.zshrc 在文件末尾添加一句启动命令
source ~/.oh-my-zsh/plugins/incr/incr*.zsh 
刷新配置
source ~/.zshrc

切记是在末尾添加,否则不能生效。

刷新配置source ~/.zshrc是在终端中执行,不是添加到文件中。(避免读者困惑)

4.2 安装快捷导航

代码

sudo apt-get install autojump
vim ~/.zshrc
plugins=(
  autojump
)
刷新配置
source ~/.zshrc

须要重启终端

autojump 导航错误

当使用传统cd出现以下错误时
autojump_chpwd:4: nice(5) failed: operation not permitted

代码

vim ~/.zshrc
添加下面一句
unsetopt BG_NICE
刷新配置
source ~/.zshrc

4.3 语法检测

代码

cd ~/.oh-my-zsh/plugins/
wget https://github.com/zsh-users/zsh-syntax-highlighting/archive/0.6.0.tar.gz
tar xf 0.6.0.tar.gz
mv zsh-syntax-highlighting-0.6.0 zsh-syntax-highlighting
vim ~/.zshrc
plugins=(
  zsh-syntax-highlighting
)
刷新配置
source ~/.zshrc

解决权限问题
通常启动时会出现zsh-syntax-highlighting权限问题
compaudit | xargs chmod g-w,o-w

4.4 自动完成

代码

cd ~/.oh-my-zsh/plugins/
mkdir zsh-autosuggestions
wget https://github.com/zsh-users/zsh-autosuggestions/archive/v0.4.3.tar.gz
tar xf v0.4.3.tar.gz
mv zsh-autosuggestions-0.4.3  zsh-autosuggestions
vim ~/.zshrc
plugins=(
  zsh-autosuggestions
)
刷新配置
source ~/.zshrc

建议重启终端

提示:
安装插件流程就是把git压缩包解压到~/.oh-my-zsh/plugins/目录下。
目录名字改为与plugins=(pluginName) 一致就能够。
注意目录下面不能再有目录,在二级目录下插件不生效。
若是要求插件包最新状态,能够到git源仓库下复制下载连接,更换 wget xxxxx.tar.gz

示例



2018年10月28日 写

相关文章
相关标签/搜索