Windows 下的 Linux 環境

Cygwin

本文已移至 Cygwin

Windows 終端機 (Terminal)

Windows 終端機提供比 cmd 或 putty 更方便使用的終端機應用程式,以多頁面執行各種不同的終端機,可自訂快速鍵。

安裝 Chocolatey

https://chocolatey.org/install#id-individual 網頁中複製 Now run the following command 貼上 Windows PowerShell (系統管理員) 執行安裝。

choco 安裝 microsoft-windows-terminal

choco install microsoft-windows-terminal
參考: GitHub - microsoft/terminal
註:或採用 Windows 市集來安裝。

在 microsoft-windows-terminal 執行 設置 或按下 Ctrl+, 在下方 開啟 JSON 檔案 設定 settings.json。

settings.json
{
    "multiLinePasteWarning": false, (1)
    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", (2)
    "confirmCloseAllTabs" : false, (3)

    // You can add more global application settings here.
    // To learn more about global settings, visit https://aka.ms/terminal-global-settings

    // If enabled, selections are automatically copied to your clipboard.
    "copyOnSelect": false, (4)

    // If enabled, formatted data is also copied to your clipboard
    "copyFormatting": false,

    // A profile specifies a command to execute paired with information about how it should look and feel.
    // Each one of them will appear in the 'New Tab' dropdown,
    //   and can be invoked from the commandline with `wt.exe -p xxx`
    // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "命令提示字元",
                "commandline": "cmd.exe",
                "hidden": false
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false, (5)
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            { (6)
                "name" : "Cygwin",
                "commandline" : "c:/apps/cygwin/bin/bash --login -i",
                "icon" : "c:/apps/cygwin/Cygwin.ico",
                "hidden": false
            },
        ]
    },

    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [],

    // Add custom keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about keybindings, visit https://aka.ms/terminal-keybindings
    "keybindings": (7)
    [
        // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
        // These two lines additionally bind them to Ctrl+C and Ctrl+V.
        // To learn more about selection, visit https://aka.ms/terminal-selection
        { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+insert" },
        { "command": "paste", "keys": "shift+insert" },

        // Press Ctrl+Shift+F to open the search box
        { "command": "find", "keys": "ctrl+shift+f" },

        // Press Alt+Shift+D to open a new pane.
        // - "split": "auto" makes this pane open in the direction that provides the most surface area.
        // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
        // To learn more about panes, visit https://aka.ms/terminal-panes
        { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" },
        { "command": { "action": "splitPane", "split": "vertical", "splitMode": "duplicate" }, "keys": "alt+shift+plus" },
        { "command": { "action": "splitPane", "split": "horizontal", "splitMode": "duplicate" }, "keys": "alt+shift+-" },
        { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+|" }
    ]
}
1 某些版本,在貼上多行時會出現警告。
2 預設的終端機改為 0caa0dad-35be-5f56-a8ff-afceeeaa6101 命令提示字元
3 confirmCloseAllTabs : false 關閉所有分頁不詢問
4 將選擇自動複製到剪貼簿,該功能還不錯,可設為 true。
5 hidden 可改為 true,表示在選單中不顯示 Azure Cloud Shell
6 加入 Cygwin,如果 menu 要在前面,自行決定位置。
7 keybindings 全部取代

下列是指已取代了 keybindings 區段,並非預設功能。

一般快速鍵

Copy (Ctrl+Insert) Paste (Shift+Insert) Find (Ctrl+Shift+F)

分割視窗快速鍵

Split auto (Alt+Shift+D) 或 (Alt+Shift+|) Split vertical (Alt+Shift++) Split horizontal (Alt+Shift+-)
Close (Alt+Shift+W) 實測結果無作用,一般是執行 exit 來關閉。

參考網站

Windows 終端機概觀
Windows Terminal: The Complete Guide - SitePoint

編譯 OpenCC

Download · BYVoid/OpenCC Wiki 已提供 Windows 的預編譯執行檔,已不需要自行編譯。

編譯 OpenCC 只能採用 gcc 9.3。

採用更新方式安裝必要套件,進入 Select Packages 後找出 gcc-g++,如果 Current 有版號 (如 10.2.0-1) 改為 9.3.0-2。
cygpkg update git,make,cmake,gcc-g++,doxygen,python
進入 Cygwin 編譯並安裝 OpenCC
gcc --version
# gcc (GCC) 9.3.0 (1)
cd /var/tmp
git clone https://github.com/BYVoid/OpenCC.git

cd /var/tmp/OpenCC
export CMAKE_LEGACY_CYGWIN_WIN32=0
make
make install

which opencc
# /usr/bin/opencc

opencc --version
# Open Chinese Convert (OpenCC) Command Line Tool
# Version: 1.1.1
1 確定版本為 9.3 如果為 10.2 在編譯的過程中會出錯。
-- The CXX compiler identification is GNU 10.2.0
...
[ 67%] Building STPhrases.ocd2
make[3]: *** [data/CMakeFiles/Dictionaries.dir/build.make:104: data/STPhrases.ocd2] Segmentation fault (core dumped)
make[3]: Leaving directory '/var/tmp/opencc/build/rel'
make[2]: *** [CMakeFiles/Makefile2:1172: data/CMakeFiles/Dictionaries.dir/all] Error 2
make[2]: Leaving directory '/var/tmp/opencc/build/rel'
make[1]: *** [Makefile:183: all] Error 2
make[1]: Leaving directory '/var/tmp/opencc/build/rel'
make: *** [Makefile:26: build] Error 2

OpenCC 如何自訂翻譯詞彙

c:\apps\cygwin\usr\share\opencc\tw2spCust.json (由 tw2sp.json 複製而來)
"conversion_chain": [{
    "dict": {
      "type": "group",
      "dicts": [
      { (1)
        "type": "text",
        "file": "TWCustRev.txt"
      }, (1)
      {
        "type": "ocd2",
        "file": "TWPhrasesRev.ocd2"
      },
1 加入TWCustRev.txt
增加詞彙對照 c:\apps\cygwin\usr\share\opencc\TWCustRev.txt
本機群組原則編輯器	本地組策略編輯器 (1)
1 每行以 Tab 鍵分開,前方是正體中文,後方為簡體中文。
注意:Windows ATOM 的 Tab 可能不如預期,需在「記事本」輸入後再貼上。
OpenCC 採用 tw2spCust.json 執行
opencc -c /usr/share/opencc/tw2spCust.json -i $InputFile -o $OutputFile

ATOM 套件收集及設定

一般快速鍵

Ctrl+Shift+P 打開命令面板 View  Toggle Command Palette
Ctrl+K+U 標示文字轉大寫
Ctrl+K+L 標示文字轉小寫

Ctrl+Alt+F2 增加或刪除書籤
F2 至下一個書籤
Ctrl+F2 打開書籤列表

project-view

Show project details in the Atom tree-view

project-viewer

A project manager that lets you add, edit and remove groups and projects as well as switching between them.

atom-beautify

Beautify HTML, CSS, JavaScript, PHP, Python, Ruby, Java, C, C++, C#, Objective-C, CoffeeScript, TypeScript, Coldfusion, SQL, and more in Atom

Beautify PHP
Settings  Executables
PHP

Binaly/Script path: C:\apps\php-7.4\php.exe

PHP-CS-Fixer

Binaly/Script path: C:\apps\atom.bin\php-cs-fixer.phar

PHPCBF

Binaly/Script path: C:\apps\atom.bin\phpcbf.phar

file-icons

Assign file extension icons and colours for improved visual grepping

open-in-app

Open your file within any of your external application instantly

sublime-style-column-selection

Enable Sublime style 'Column Selection'. Just hold 'alt' while you select, or select using your middle mouse button. Also similar to Texmate’s 'Multiple Carets', or BBEdit’s 'Block Select'

fuzzy-finder (Core)

Open an editor to a file in the project with cmd-t.
atom 內建,可在專案內搜尋檔案,需要建立索引,如果專案內的檔案太多,根本不能用。

advanced-open-file

Open and create files and directories easily. Type in a path (with autocomplete) and view directory contents.
開啟專案內的檔案,在輸入的路徑中搜尋目錄或檔案速度快,Ctrl+Alt+O

whitespace (Core)

Strips trailing whitespace and adds a trailing newline when an editor is saved. (atom 內建)

Settings

  • Remove Trailling Whitespace (ATOM 編輯器在存檔時刪除結尾空白)

svg-preview

Live SVG preview

ascii-tree

Generate ASCII trees with ease!

Asciidoctor 套件

language-asciidoc

Syntax highlighting and snippets for AsciiDoc (with Asciidoctor flavor).
Asciidoctor 語法高亮度,安裝後 .ad .adoc 檔案的 scope name 為 source.asciidoc。

atom-timestamp

Update timestamp comment
存檔時更新時間戳記。

Settings

Timestamp Prefix: :docdatetime:[ \t]+["<]?
Scope Selector: source.asciidoc

怎麼知道 source.asciidoc?
在 Settings 中已經說明 use Editor: Log Cursor Scope command to get scope names on current cursor.
按下 Ctrl+Shift+P 打開命令面板,輸入 scope (註:原始說明檔有誤多了一個空白,只輸入部份文字也可,如 scope。) 會顯示一個 Scopes at Cursor 視窗,內容即為 scope name。

document-outline

Show a hierarchical outline of a text document
顯示文件大綱 (目錄),Asciidoctor 檔案的 scope name 需為 source.asciidoc 才能運作。
不過有點問題,在 bash source block 往往會有 # 字元,會被解讀成標題,可按應用程式設定修正

plantuml-toolkit

A toolkit with multiple tools to handle PlantUML diagrams. Includes creating and displaying rendered uml diagrams and syntax highlighting.
需先安裝 jre,進入 Java SE Runtime Environment 8 - Downloads 網頁下載 Windows x64 如版本為 8u271 檔案為 jre-8u271-windows-x64.exe。 如果沒有 jre,在安裝 plantuml-toolkit 會出錯 Installing “plantuml-toolkit@0.2.0” failed

Settings
Settings  Preview
Java Executable

java (default)

Additional Java Arguments

-Dfile.encoding=UTF-8

Additional PlantUML Arguments

-nometadata

ATOM 設置

File  Settings Ctrl+逗號 進入設置 (由於輸入法的原因無法輸入,只好用 Menu)

Settings
Editor
  • Atomic Soft Tabs (移動游標時跳過定位字元,包含空白)

  • Show Indent Guide (啟用 atom-beautify 豎線對齊)

    Tab Length

    2 (2:很難分辨到底是定位字元 (Tab) 還是 2 個空白。8:Beautify 會空格 8)

    Tab Type

    auto (soft 輸入為空白字元,hard 為定位字元)

System
  • Show in file content menus (在檔案的右鍵選單可執行 Open with Atom)

  • Show in folder content menus (在資料夾中的右鍵選單可執行 Open with Atom)

Editor
  • Show Indent Guide (啟用 atom-beautify 豎線對齊)

apm 命令
rem 列出安裝的套件
apm list --installed --bare (1)

rem 安裝套件 (套件名稱全小寫沒有空白字元)
apm install <Package-Name>
1 檔案位置在 %LOCALAPPDATA%\atom\bin\apm.cmd
ATOM 已知問題

%LOCALAPPDATA%\atom 有舊版

├── app-1.50.0    545 MB 不會刪除舊版
├── app-1.51.0    545 MB (1)
├── app-1.52.0    562 MB (2)
├── app-1.53.0    618 MB (3)
└── Update.exe
1 關閉 ATOM 1.51,1.50 改名後再重開 ATOM,如果沒有問題可以刪除,也可留著改天再刪。
2 關閉 ATOM 1.52,1.51 改名後,ATOM 無法啟動,就留著吧!改天有空再重新安裝。
ATOM 1.52 執行 Show in Explorer 出現 atom unable to show …​ in explorer。
安裝 1.51,啟動 ATOM 會執行更新又回到了 1.52,在該階段運作可能不正常。
開啟 ATOM 1.52,先取消更新,再安裝舊版,啟動舊版的 ATOM 1.51 在之前安裝的套件及設置並不會消失。
3 ATOM 1.53 沒有舊版,執行 Show in Explorer 出現 atom unable to show …​ in explorer。
完全解除安裝 ATOM

執行 Windows 的解除安裝,並不能完全刪除 ATOM。

刪除 .atom 資料夾
rd %USERPROFILE%\.atom /s /q
rd %LOCALAPPDATA%\atom /s /q (1)
1 出現「程序無法存取檔案,因為檔案正由另一個程序使用」,重開機後再次刪除。