只有累積,沒有奇蹟

顯示具有 Windows Terminal 標籤的文章。 顯示所有文章
顯示具有 Windows Terminal 標籤的文章。 顯示所有文章

2019年7月22日 星期一

[Windows] 在 Windows Terminal 新增 Linux Bash Commnadline

前言
在上一篇文章 [Windows] Windows Terminal Preview 初體驗 介紹了 Windows Terminal 的基本操作與使用,其中提到在安裝完預設提供 command 為 powershell 和 cmd 命令提示字元兩種,其實在 Windows Terminal 支援多種 command line,這一篇文章就來介紹如何在 Windows Terminal Preview 新增 Bash command line 的方法。

啟用 Linux Bash Shell
如果要在 Windows Terminal 使用 Bash.exe 需要先啟用 Window OS 的 Linux Bash Shell 功能,公司筆電是使用最新版 Windows 10,因此以下就簡單介紹在 Windows 10 中如何啟用 Linux Bash 

安裝 Windows Subsystem for Linux
首先使用管理者 admin 權限開啟 powershell
接著在 powershell 輸入下列指令
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
安裝完畢之後會詢問是否要重新啟動電腦,選擇 y 就會進行立即重啟的動作

安裝 Ubuntu
下一步到 Windows 商店下載 Linux 子系統,在 Microsoft Store 提供多個 Linux 子系統像是 Ubuntu、OpenSUSE、SLES 可以下載,可以在 Store 輸入 Linux 就可以輕易地找到 Ubuntu,下載完畢後可以點選啟用
第一次啟用 ubuntu 會需要一點時間進行初始化設定與安裝,完畢之後會要求你輸入帳號密碼的動作
透過以上步驟,順利的完成啟用 Windows Subsystem for Linux 與 安裝 Ubuntu 的動作

新增 Command Line
在 Windows Terminal 中的設定可以透過  ⬇  中的 settings 來進行設定,按下後會請使用者選擇想要開啟設定檔的編輯器工具
在 Windows Terminal 設定檔名為 Profiles.json,要調整可以到下列路徑進行調整
userName\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState
找到設定檔後可以透過文字編輯器進行編輯,用 Visual Studo Code 開啟後可以看到  profiles  區塊,在 Windows Terminal 安裝完成之後 profiles 一共有兩個區塊,內容分別定義 powershell 與 cmd 兩種設定,以 powershell 為例配置設定如下
{
    "acrylicOpacity" : 0.5,
    "background" : "#012456",
    "backgroundImage" : "D:/Marcus/iron_man.jpg",
    "closeOnExit" : true,
    "colorScheme" : "Campbell",
    "commandline" : "powershell.exe",
    "cursorColor" : "#FFFFFF",
    "cursorShape" : "bar",
    "fontFace" : "Fira Code",
    "fontSize" : 14,
    "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
} 
重要的項目為 name、guid、commandline 等設定,說明如下
  • guid : 每組 commandline 定義屬於自己專用且不能重複的 guid 
  • name : 顯示在 Windows Terminal  +  中顯示的名字
  • commandline  : 執行的 commandline
其餘像是 font 字型、字體大小、背景圖都可以針對各自 commandline 需求做調整,另外在 Windows Terminal 中修改是即時的,調整完 json 內容會即時更新正在使用的 Windows Terminal 視窗,透過以上得知在 Windows Terminal 如何定義 commandline 之後,如果要新增新的 commandline 就可以複製一份來調整,在調整上述提到的 guid、name、commandline 等值即可完成,以新增 Linux Bash 為例配置文件如下
{
    "acrylicOpacity" : 0.75,
    "closeOnExit" : true,
    "colorScheme" : "Campbell",
    "commandline" : "bash.exe",
    "cursorColor" : "#FFFFFF",
    "cursorShape" : "bar",
    "fontFace" : "Consolas",
    "fontSize" : 10,
    "guid" : "{9acb9455-ca41-5af7-950f-6bca1bc9722f}",
    "historySize" : 9001,
    "icon" : "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.scale-100.png",
    "name" : "Linux Bash Shell",
    "padding" : "0, 0, 0, 0",
    "snapOnInput" : true,
    "startingDirectory" : "%USERPROFILE%",
    "useAcrylic" : true
} 
新增 Python
{
    "acrylicOpacity" : 0.75,
    "closeOnExit" : true,
    "colorScheme" : "Campbell",
    "commandline" : "py.exe",
    "cursorColor" : "#FFFFFF",
    "cursorShape" : "bar",
    "fontFace" : "Consolas",
    "fontSize" : 10,
    "guid" : "{1850e97f-16dc-4281-9ea9-0100c4e852c5}",
    "historySize" : 9001,
    "icon" : "C:/Users/marcus/AppData/Local/Programs/Python/Python37/Lib/test/imghdrdata/python.png",
    "name" : "Python",
    "padding" : "0, 0, 0, 0",
    "snapOnInput" : true,
    "startingDirectory" : "%USERPROFILE%",
    "useAcrylic" : true
} 
最後要小小提醒的是在編輯 Profiles.json 檔時需多加留意格式,如果對於 json 格式不熟悉可以到現在 json 格式檢查網站進行確認後再貼上,如果格式錯誤會造成讀取異常,可以看到下列畫面
在重新開啟 Windows Terminal,在點擊右上方的  +  後就可以透過看到新增的 commandline 
透過以上簡單的幾個步驟就完成在 在 Windows Terminal 新增 Linux Bash,希望有幫助到有需要的朋友 :)

參考
終於來了!實測 Windows 10 更新後,安裝使用Bash on Ubuntu on Windows
How to Install Linux Bash Shell on Windows 10

2019年6月27日 星期四

[Windows] Windows Terminal Preview 初體驗

前言
自從 Build 2019 亮相之後一直對於 Windows Terminal 頗有興趣,終於在六月下旬官方 Blog 公布 Windows Terminal Preview 可以開放下載使用,根據官方 Blog 介紹如下
Windows Terminal! Windows Terminal is a new, modern, fast, efficient, powerful, and productive terminal application for users of command-line tools and shells like Command Prompt, PowerShell, and WSL.
這邊就簡單分享 升級到 Windows 1903 與 安裝Windows Terminal 過程。

前言
在安裝 Windows Terminal 前可以說是挑戰重重,首先要求系統最低標必須是 Windows 1903 以上才能執行,升級版本需要 11G 的空間大小,因此小弟在安裝時第一步是先升級系統版本

升級 Windows 10 版本 1903
公司筆電的硬碟只有 128G 硬碟空間一直處於不夠用的情況,後來是透過 WizTree 硬碟空間分析軟體才擠出本次 Windows 10 升級的空間,確定硬碟足夠之後可以透過上圖中的更新,會到官網下載 Windows 10 更新軟體,在進行 Windows 10 1903 版本的升級動作,整個過程需要約一小時左右
更新完畢後會重開機,重開機時會在進行基本設定並看到熟悉的您好 :)

安裝 Windows Terminal Preview
可以在 Microsoft Store 進行下載的動作 : 傳送門
安裝完畢之後可以透過左下角搜尋 Windows Terminal 開啟
開啟之後畫面如下,內建有 cmd 與 powershell 功能,預設是使用 powershell 

基本操作
可以使用  +  來開啟新的 Terminal 視窗,預設有提供 cmd 以及 powershell 兩種 Terminal (預設是 powershell ),在 Windows Terminal 中的設定則可以透過  ⬇  中的 settings 來進行設定
設定檔的預設位置存放在
userName\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState
設定檔中可以依據你的喜好調整個人設定,透過 Visual Studo Code 開啟後找到  profiles  區塊,在 profiles 的每個區塊分別定義了 commandline 各別的設定,也就是說你可以 powershell 與 cmd 設定不同的喜好設定
另外很方便的一點是在其中調整 json 內容會即時更新,舉例來說調整字形或是背景圖示時,Windows Terminal 會即時的顯示調整的內容,舉例來說下列是修改 powershell 文字與背景圖片,在修改時都會立即顯示在 Terminal 視窗中,且不會影響到 cmd 的設定
另外也提供設定快捷鍵 keybindings,也可以自定義字形的字體部分,如果想了解更多可以參考官網網站說明,以下為分享初步研究調整字形 (Fira Code) 與背景圖片的 Windows Terminal 畫面
在微軟官方 Blog 中有關於 Windows Terminal 的文章與介紹,有興趣可以參考了解更多細節

參考
Windows Terminal Microsoft Store Preview Release
Introducing Windows Terminal
How to customize the new Windows Terminal with Visual Studio Code

Copyright © m@rcus 學習筆記 | Powered by Blogger

Design by Anders Noren | Blogger Theme by NewBloggerThemes.com