LoginSignup
14
10

Windows Terminal で Cygwin Bash を表示したい

Last updated at Posted at 2020-02-24

Windows Terminal は Build 2019 で発表された Windows 向けの新たなターミナルです。マルチタブが導入されており、複数の PowerShell やコマンドプロンプトなどを切り替えながら利用できます。また、Windows10 v1809 から UNIX / Linux 互換の擬似コンソール ConPTY が導入されたため Bash などの Linux シェルを表示できます。せっかくなので Cygwin も利用できるように設定してみました。1

cygwin-bash-on-windows-terminal.png

設定手順

Cygwin での準備

setup-x86_64.exe もしくは apt-cyg を利用して Cygwin に chere をインストールします。Mintty で chere -h を実行できればOKです:

$ chere -h
/usr/bin/chere version 1.4

Usage:
/usr/bin/chere -<iuxlrhv> [-lracnmpf12] [-t <term>] [-s <shell>]
        [-d <display> ] [-o <options>] [-e <menutext>]

Adds the stated terminal/shell combination to the folder context menu
This allows you to right click a folder in Windows Explorer and open
a Cygwin shell in that folder.

Options:
  i - Install
  u - Uninstall
  x - Freshen eXisting entries
  l - List currently installed chere items
  r - Read all chere registry entries to stdout
  a - All users
  c - Current user only
  n - Be Nice and provide Control Panel uninstall option (Default)
  m - Minimal, no Control Panel uninstall
  p - Print regtool commands to stdout rather than running them
  f - Force write (overwrite existing, ignore missing files)
  1 - Start using registry one-liners. This doesn\'t work with ash,
      tcsh or network shares.
  2 - Start via bash script. Relies on windows to change directory,
      and login scripts avoiding doing a cd /home/<username>
  h - Help
  v - Version

  t <term> - Use terminal term. Supported terminals are:
        cmd rxvt mintty xterm urxvt

  s <shell> - Use the named shell. Supported shells are:
        ash bash cmd dash fish mksh pdksh posh tcsh zsh passwd

  d <display> - DISPLAY to use (xterm, urxvt). Defaults to :0.
      Set to env to use the runtime environment variable.

  o <options> - Add <options> to the terminal startup command.
      If more than one option is specified, they should all be
      contained within a single set of quotes.

  e <menutext> - Use <menutext> as the context menu text.

See the man page for more detail.

読んでの通り、特定のフォルダで Cygwin ターミナルを開始するためのユーティリティです。bash.exe を起動するだけでは Cygwin の機能を利用できないため、このツールをインストールしています。

Windows Terminal での設定

  1. PowerShell を起動して適当な GUID を取得します。

        [guid]::NewGuid()
    
  2. Windows Terminal を起動し、[Settings] から settings.json を開きます。

  3. "profiles" : [ { ... } ] の末尾に以下のオブジェクトを追記して保存します。"guid" の値は先ほど取得した GUID に差し替えてください:

    profiles.json
    {
        "guid": "{22cbae05-ab97-4c97-a2ea-6feaa2494f7a}",
        "name": "Cygwin",
        "suppressApplicationTitle": true,
        "commandline": "C:\\cygwin64\\bin\\bash.exe /bin/xhere /bin/bash ~",
        "icon": "C:\\cygwin64\\Cygwin-Terminal.ico",
        "useAcrylic" : true,
        "acrylicOpacity" : 0.6
    }
    
  4. 新規タブの選択肢に Cygwin が追加されました!

    cygwin-bash-added-selection.png

※ここでは同様の手順で Git Bash も 追加しています。

参考リンク

  1. ちなみに Ansible は Python-pip 導入後に pip からインストールできるほか、setup-x86_46.exe からでもインストール可能です。

14
10
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
10