最近在win10下面搭建了一個 WSL+cmder+oh-my-zsh 的程序員命令行環境,爲何呢?還不是買不起mac,加上本身的黑蘋果癱了,全部又回到了win10上面。不過上面無論是Cmd仍是PowerShell都是難看的要死要死的,並且不少命令不支持,因此有了這一次的實踐。前端
以前咱們使用的是 cmder
這個工具。node
在 windows 1903 以及之後的版本中,能夠直接使用windows自帶的 windows terminal
,能夠直接從windwos 10 的應用商店裏面下載。這個比 cmder 用起來更加的便捷。linux
檢查window版本: windows + R 後 輸入 winvergit
安裝 windows terminal 之後咱們能夠本身去配置 terminal 的樣式。 程序員
修改配置以下,其中 #XXX
爲註釋github
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"globals" :
{
"alwaysShowTabs" : true,
"copyOnSelect" : true,
"defaultProfile" : "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}", #默認的終端,點擊+號
"initialCols" : 120,
"initialRows" : 30,
"keybindings" :
[
{
"command" : "closePane",
"keys" :
[
"ctrl+shift+w"
]
},
{
"command" : "copy",
"keys" :
[
"ctrl+shift+c"
]
},
{
"command" : "duplicateTab",
"keys" :
[
"ctrl+shift+d"
]
},
{
"command" : "newTab",
"keys" :
[
"ctrl+shift+t"
]
},
{
"command" : "newTabProfile0",
"keys" :
[
"ctrl+shift+1"
]
},
{
"command" : "newTabProfile1",
"keys" :
[
"ctrl+shift+2"
]
},
{
"command" : "newTabProfile2",
"keys" :
[
"ctrl+shift+3"
]
},
{
"command" : "newTabProfile3",
"keys" :
[
"ctrl+shift+4"
]
},
{
"command" : "newTabProfile4",
"keys" :
[
"ctrl+shift+5"
]
},
{
"command" : "newTabProfile5",
"keys" :
[
"ctrl+shift+6"
]
},
{
"command" : "newTabProfile6",
"keys" :
[
"ctrl+shift+7"
]
},
{
"command" : "newTabProfile7",
"keys" :
[
"ctrl+shift+8"
]
},
{
"command" : "newTabProfile8",
"keys" :
[
"ctrl+shift+9"
]
},
{
"command" : "nextTab",
"keys" :
[
"ctrl+tab"
]
},
{
"command" : "openNewTabDropdown",
"keys" :
[
"ctrl+shift+space"
]
},
{
"command" : "openSettings",
"keys" :
[
"ctrl+,"
]
},
{
"command" : "paste",
"keys" :
[
"ctrl+shift+v"
]
},
{
"command" : "prevTab",
"keys" :
[
"ctrl+shift+tab"
]
},
{
"command" : "scrollDown",
"keys" :
[
"ctrl+shift+down"
]
},
{
"command" : "scrollDownPage",
"keys" :
[
"ctrl+shift+pgdn"
]
},
{
"command" : "scrollUp",
"keys" :
[
"ctrl+shift+up"
]
},
{
"command" : "scrollUpPage",
"keys" :
[
"ctrl+shift+pgup"
]
},
{
"command" : "switchToTab0",
"keys" :
[
"ctrl+alt+1"
]
},
{
"command" : "switchToTab1",
"keys" :
[
"ctrl+alt+2"
]
},
{
"command" : "switchToTab2",
"keys" :
[
"ctrl+alt+3"
]
},
{
"command" : "switchToTab3",
"keys" :
[
"ctrl+alt+4"
]
},
{
"command" : "switchToTab4",
"keys" :
[
"ctrl+alt+5"
]
},
{
"command" : "switchToTab5",
"keys" :
[
"ctrl+alt+6"
]
},
{
"command" : "switchToTab6",
"keys" :
[
"ctrl+alt+7"
]
},
{
"command" : "switchToTab7",
"keys" :
[
"ctrl+alt+8"
]
},
{
"command" : "switchToTab8",
"keys" :
[
"ctrl+alt+9"
]
}
],
"requestedTheme" : "system",
"showTabsInTitlebar" : true,
"showTerminalTitleInTitlebar" : true,
"wordDelimiters" : " ./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}~?\u2502"
},
"profiles" :
[
{
"acrylicOpacity" : 0.5,
"backgroundImage": "C://Users//Administrator//Pictures//Saved Pictures//2.jpg", #背景圖片
"backgroundImageOpacity" : 0.6, #背景透明度
"background" : "#012456",
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "powershell.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Cascadia Code", #字體
"fontSize" : 12,
"guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", #終端惟一編號
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
"name" : "Windows PowerShell", #啓動的終端
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false,
"tabTitle" : "Powershell"
},
{
"acrylicOpacity" : 0.75,
"backgroundImage": "C://Users//Administrator//Pictures//Saved Pictures//1.jpg",
"backgroundImageOpacity" : 0.6,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "cmd.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Cascadia Code",
"fontSize" : 12,
"guid" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"name" : "cmd",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
},
{
"acrylicOpacity" : 0.59999999999999998,
"closeOnExit" : false,
"colorScheme" : "Vintage",
"commandline" : "Azure",
"connectionType" : "{d9fcfdfa-a479-412c-83b7-c5640e61cd62}",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Cascadia Code",
"fontSize" : 12,
"guid" : "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{b453ae62-4e3d-5e58-b989-0a998ec441b8}.png",
"name" : "Azure Cloud Shell",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
},
{
"acrylicOpacity" : 0.5,
"backgroundImage": "C://Users//Administrator//Pictures//Saved Pictures//3.jpg",
"backgroundImageOpacity" : 0.4,
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"name": "Ubuntu-18.04",
"closeOnExit" : true,
"colorScheme" : "Campbell",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Cascadia Code",
"fontSize" : 12,
"source": "Windows.Terminal.Wsl",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"historySize" : 9001,
"tabTitle" : "Ubuntu (WSL)",
"useAcrylic" : false
}
],
"schemes" :
[
{
"background" : "#0C0C0C",
"black" : "#0C0C0C",
"blue" : "#0037DA",
"brightBlack" : "#767676",
"brightBlue" : "#3B78FF",
"brightCyan" : "#61D6D6",
"brightGreen" : "#16C60C",
"brightPurple" : "#B4009E",
"brightRed" : "#E74856",
"brightWhite" : "#F2F2F2",
"brightYellow" : "#F9F1A5",
"cyan" : "#3A96DD",
"foreground" : "#CCCCCC",
"green" : "#13A10E",
"name" : "Campbell",
"purple" : "#881798",
"red" : "#C50F1F",
"white" : "#CCCCCC",
"yellow" : "#C19C00"
},
{
"background" : "#000000",
"black" : "#000000",
"blue" : "#000080",
"brightBlack" : "#808080",
"brightBlue" : "#0000FF",
"brightCyan" : "#00FFFF",
"brightGreen" : "#00FF00",
"brightPurple" : "#FF00FF",
"brightRed" : "#FF0000",
"brightWhite" : "#FFFFFF",
"brightYellow" : "#FFFF00",
"cyan" : "#008080",
"foreground" : "#C0C0C0",
"green" : "#008000",
"name" : "Vintage",
"purple" : "#800080",
"red" : "#800000",
"white" : "#C0C0C0",
"yellow" : "#808000"
},
{
"background" : "#282C34",
"black" : "#282C34",
"blue" : "#61AFEF",
"brightBlack" : "#5A6374",
"brightBlue" : "#61AFEF",
"brightCyan" : "#56B6C2",
"brightGreen" : "#98C379",
"brightPurple" : "#C678DD",
"brightRed" : "#E06C75",
"brightWhite" : "#DCDFE4",
"brightYellow" : "#E5C07B",
"cyan" : "#56B6C2",
"foreground" : "#DCDFE4",
"green" : "#98C379",
"name" : "One Half Dark",
"purple" : "#C678DD",
"red" : "#E06C75",
"white" : "#DCDFE4",
"yellow" : "#E5C07B"
},
{
"background" : "#FAFAFA",
"black" : "#383A42",
"blue" : "#0184BC",
"brightBlack" : "#4F525D",
"brightBlue" : "#61AFEF",
"brightCyan" : "#56B5C1",
"brightGreen" : "#98C379",
"brightPurple" : "#C577DD",
"brightRed" : "#DF6C75",
"brightWhite" : "#FFFFFF",
"brightYellow" : "#E4C07A",
"cyan" : "#0997B3",
"foreground" : "#383A42",
"green" : "#50A14F",
"name" : "One Half Light",
"purple" : "#A626A4",
"red" : "#E45649",
"white" : "#FAFAFA",
"yellow" : "#C18301"
},
{
"background" : "#002B36",
"black" : "#073642",
"blue" : "#268BD2",
"brightBlack" : "#002B36",
"brightBlue" : "#839496",
"brightCyan" : "#93A1A1",
"brightGreen" : "#586E75",
"brightPurple" : "#6C71C4",
"brightRed" : "#CB4B16",
"brightWhite" : "#FDF6E3",
"brightYellow" : "#657B83",
"cyan" : "#2AA198",
"foreground" : "#839496",
"green" : "#859900",
"name" : "Solarized Dark",
"purple" : "#D33682",
"red" : "#DC322F",
"white" : "#EEE8D5",
"yellow" : "#B58900"
},
{
"background" : "#FDF6E3",
"black" : "#073642",
"blue" : "#268BD2",
"brightBlack" : "#002B36",
"brightBlue" : "#839496",
"brightCyan" : "#93A1A1",
"brightGreen" : "#586E75",
"brightPurple" : "#6C71C4",
"brightRed" : "#CB4B16",
"brightWhite" : "#FDF6E3",
"brightYellow" : "#657B83",
"cyan" : "#2AA198",
"foreground" : "#657B83",
"green" : "#859900",
"name" : "Solarized Light",
"purple" : "#D33682",
"red" : "#DC322F",
"white" : "#EEE8D5",
"yellow" : "#B58900"
}
]
}
複製代碼
上面咱們用到了 Cascadia Code
字體。這裏在推薦一下這個字體,這個月微軟爲編程人員出的一款字體,用起來簡直舒服。 下載地址shell
win10系統須要更新到1067及其之後的版本,而且是64位的系統才能夠安裝。相信作開發的都是64位系統吧。npm
win10打開程序和功能 編程
勾選適用於系統的Linux的子系統,而後重啓系統。 重啓之後,此時咱們已經可使用Linux系統,可是咱們還差一個系統,因此須要安裝一個咱們在win10應用商店裏面搜索linux,安裝Ubuntu。 json
安裝完成後在開始菜單裏面找到程序,啓動。
剛開始的時候須要等一下,在配置環境。完成後須要設置用戶名以及密碼。
cmder有兩個版本,Mini版與完整版(包含了git以及一些其餘的命令)。推薦安裝完整版。 安裝完成後打開,咱們須要進行配置一下
如上圖,在tasks中添加一個taskset "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl --distro-guid={9df562ee-848c-4af4-ab4e-aedad54ceba9} -cur_console:pm:/mnt
。這裏面的9df562ee-848c-4af4-ab4e-aedad54ceba9
指的是Ubuntu的惟一標識符,若是重裝了子系統,那麼這個標識符實惠變得。能夠在在註冊表(regedit)中查找 計算機\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss
。win+R搜索regedit
。+
,裏面有全部的配置。
在Ubuntu系統中使用命令行而不是win中
安裝任何包以前必定要先更新! sudo apt-get update
安裝zsh sudo apt-get install zsh
安裝oh-my-zsh sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
安裝成功
若是 遇到證書相似問題 apt-get install ca-certificates
自動啓動zsh vim ~/.bashrc
或者nano ~/.bashrc
(推薦使用)打開編輯.bashrc
文件,添加如下內容:
if test -t 1; then
exec zsh
fi
複製代碼
若是你使用的是vim ~/.bashrc
,編輯後使用:wq
退出。
若是你使用的是nano ~/.bashrc
,使用Ctrl+Shift+X
保存並退出。
修改主題:
nano ~/.zshrc
# 主題名字ys,你能夠搜索其餘的主題使用,ys挺好的
ZSH_THEME="ys"
複製代碼
修改之後保存。
終端字體補全 sudo apt-get install fonts-powerline
客戶端字體補全 注意: 有些字符在windows 上沒法顯示,因此須要安裝字體 nerdfonts.com,選擇 Hack
修改cmder字體爲
固然,你也能夠設置爲其餘你認爲好看的字體。 這個是個人配置的最後的效果,還設置了透明度以及背景什麼的,大家也能夠本身進行配置。因爲博主是作前端開發的,用的是VSCode因此這裏說一下,怎麼在VSCode上面使用。
在VSCode的設置文件中添加這一句
"terminal.integrated.shell.windows": "C:\\\\Windows\\\\System32\\\\wsl.exe",
複製代碼
若是須要使用node,npm等工具,WSL裏面是不可以直接使用windows自帶的這些環境變量的,咱們須要在WSL中安裝,具體的安裝方法能夠google--Ubuntu安裝軟件
以前說的字體fonts-powerline
,Hack Nerd Font Mono
這個字體,其實仍是挺好看的,你們可使用,包括在PC上面也能夠。這個字體可使用Git下載https://github.com/powerline/fonts
,不過這個實在是有點慢,這裏我已經下載下來放在了這裏。
下載下來之後使用PowerShell
,到字體目錄下,運行如下命令
.\install.ps1
複製代碼
可能會遇到報錯,此時先執行set-Executionpolicy Remotesigned
關於啓動時候報錯 有時候咱們啓動子系統的時候會報錯,錯誤代碼:0x800703fa
具體錯誤內容:WslRegisterDistribution failed with error: 0x800703fa
此時win+R
在運行窗口中執行「services.msc」指令,在本地服務中重啓 LxssManager 服務便可
[1]. segmentfault.com/a/119000001… [2]. blog.joaograssi.com/windows-sub…