Arch Linux on WSLで日本語入力可能なXの環境を作る

by mohemohe 2018-04-26 01:00

たぶんArchじゃなくても日本語入力できると思う

Arch Linuxをインストールする

yuk7/ArchWSL: Install ArchLinux as a WSL Instance and Launch it (for Windows 10 FCU 64bit or later)

べんり

Hyperをインストールする

Windowsでも比較的マシな品質のターミナルが使える

WindowsからWSLを触らないなら無くてもいい

👇オススメ設定(カラースキームはArgonaut準拠)

// -- hyper-stylesheet-hash:5a843a19b2f591c89623dca08a5fa929 --
module.exports = {
  config: {
    // default font size in pixels for all tabs
    fontSize: 18,

    // font family with optional fallbacks
    fontFamily: 'Cica',

    // terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
    cursorColor: 'rgba(248,28,229,0.6)',

    // `BEAM` for |, `UNDERLINE` for _, `BLOCK` for █
    cursorShape: 'BLOCK',

    // color of the text
    foregroundColor: '#fffaf4',

    // terminal background color
    backgroundColor: '#232323',

    // border color (window, tabs)
    borderColor: '#333',

    // custom css to embed in the main window
    css: '.unicode-node {width: 18px !important;}',

    // custom css to embed in the terminal window
    termCSS: '',

    // set to `true` (without backticks) if you're using a Linux setup that doesn't show native menus
    // default: `false` on Linux, `true` on Windows (ignored on macOS)
    showHamburgerMenu: '',

    // set to `false` if you want to hide the minimize, maximize and close buttons
    // additionally, set to `'left'` if you want them on the left, like in Ubuntu
    // default: `true` on windows and Linux (ignored on macOS)
    showWindowControls: '',

    // custom padding (css format, i.e.: `top right bottom left`)
    padding: '12px 14px',

    // the full list. if you're going to provide the full color palette,
    // including the 6 x 6 color cubes and the grayscale map, just provide
    // an array here instead of a color map object
    colors: {
      black: '#232323',
      red: '#ff000f',
      green: '#8ce10b',
      yellow: '#ffb900',
      blue: '#008df8',
      magenta: '#6d43a6',
      cyan: '#00d8eb',
      white: '#d0d0d0',
      lightBlack: '#444444',
      lightRed: '#ff2740',
      lightGreen: '#abe15b',
      lightYellow: '#ffd242',
      lightBlue: '#0092ff',
      lightMagenta: '#9a5feb',
      lightCyan: '#67fff0',
      lightWhite: '#ffffff'
    },

    // the shell to run when spawning a new session (i.e. /usr/local/bin/fish)
    // if left empty, your system's login shell will be used by default
    // make sure to use a full path if the binary name doesn't work
    // (e.g `C:\\Windows\\System32\\bash.exe` instad of just `bash.exe`)
    // if you're using powershell, make sure to remove the `--login` below
    shell: 'C:\\Windows\\System32\\bash.exe',

    // for setting shell arguments (i.e. for using interactive shellArgs: ['-i'])
    // by default ['--login'] will be used
    shellArgs: ['--login'],

    // for environment variables
    env: {},

    // set to false for no bell
    bell: false,

    // if true, selected text will automatically be copied to the clipboard
    copyOnSelect: false

    // if true, on right click selected text will be copied or pasted if no
    // selection is present (true by default on Windows)
    // quickEdit: true

    // URL to custom bell
    // bellSoundURL: 'http://example.com/bell.mp3',

    // for advanced config flags please refer to https://hyper.is/#cfg
  },

  // a list of plugins to fetch and install from npm
  // format: [@org/]project[#version]
  // examples:
  //   `hyperpower`
  //   `@company/project`
  //   `project#1.0.1`
  plugins: [
    'hyper-stylesheet',
  ],

  // in development, you can create a directory under
  // `~/.hyper_plugins/local/` and include it here
  // to load it and avoid it being `npm install`ed
  localPlugins: []
};

WindowsにXサーバーをインストールする

  • VcXsrvをインストールする
  • C:\Program Files\VcXsrv\run-linux.jsを作成

C:\Program Files\VcXsrv\run-linux.js

var shell = new ActiveXObject("WScript.Shell");
var args = WScript.Arguments;
var cmd = [];
var i;

for (i = 0; i < args.length; i++) {
  cmd.push(args(i));
}

shell.Run("bash -lc '" + cmd.join(' ') + "'", 0, true);

※ JScriptなのでletとかconstを使うのは、たぶんダメ

  • start.xlaunchを(デスクトップとかに)作成
<?xml version="1.0" encoding="UTF-8"?>
<XLaunch
  WindowMode="MultiWindow"
  ClientMode="StartProgram"
  LocalClient="True"
  Display="-1"
  LocalProgram="wscript run-linux.js cd; lxpanel --profile LXDE"
  RemoteProgram=""
  RemotePassword=""
  PrivateKey=""
  RemoteHost=""
  RemoteUser=""
  XDMCPHost=""
  XDMCPBroadcast="False"
  XDMCPIndirect="False"
  Clipboard="True"
  ClipboardPrimary="True"
  ExtraParams="-dpi 96"
  Wgl="True"
  DisableAC="False"
  XDMCPTerminate="False"
/>

参考
Windows Subsystem for Linux + X Windowを1.024倍くらい使いこなすための方法 - Qiita

Hyper(bash.exe)で環境を整える

パッケージインストール

sudo pacman -S fcitx-im fcitx-configtool firefox-developer-edition firefox-developer-edition-i18n-ja gedit neofetch noto-fonts noto-fonts-cjk lxde zsh

.bashrc

ログインシェル($- != *i*)ではない場合は、必要な環境変数をexportしたりスタートアップアプリを準備する

  • DISPLAY: Windows上のXサーバーを指定
  • GTK_IM_MODULE, XMODIFIERS, QT_IM_MODULE: インプットメソッドを指定(fcitxとかuimとか)
  • fcitxを起動
  • 早期リターン

ログインシェルの場合はzshを起動
※ WSLはchshをしても強制的にbashが起動するので.bashrcに全部書く

export LANG='ja_JP.UTF-8'
export SHELL=$(which zsh)

if [[ $- != *i* ]]; then {
  export DISPLAY=localhost:0.0
  export GTK_IM_MODULE=fcitx
  export XMODIFIERS=@im=fcitx
  export QT_IM_MODULE=fcitx
  fcitx
  return
} fi

exec zsh

参考
Fcitx - ArchWiki

GUIで環境を整える

startx.xlaunchをダブルクリックするとLXDE(のパネルとウィンドウマネージャー)が起動する
LXDEのパネルを右クリック👉高度な設定👉ログアウトのコマンド にlxpanelctl exitと入れておくと、LXDEでログアウトをクリックしたときにVcXsrvも終了してくれる

参考
Windows Subsystem for Linux + X Windowを1.024倍くらい使いこなすための方法 - Qiita

遊ぶ

左はWindowsのChrome
右はArch LinuxのChrome