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 出现「进程无法访问文件,因为文件正由另一个进程使用」,重开机后再次删除。