CLOVER🍀

That was when it all began.

inshellisense 0.0.1-rc.4を試す

これは、なにをしたくて書いたもの?

MicrosoftGitHubリポジトリに、inshellisenseというIDEスタイルでシェルを補完するツールがあることを知りまして。

Microsoft、各種シェルに600を超えるコマンド補完を掲げる「inshellisense」:マピオンニュース

ちょっと試してみようかなと。

inshellisense

inshellisenseのGitHubリポジトリはこちらです。

GitHub - microsoft/inshellisense: IDE style command line auto complete

inshellisenseはIDEスタイルでシェルを補完できるツールで、以下のシェルに対応しているようです。

TypeScriptで書かれていて、npm installで導入します。Node.js v16以上が必要です。

内部的にはこちらを使っているようです。

GitHub - withfig/autocomplete: IDE-style autocomplete for your existing terminal & shell

現在のバージョンは0.0.1-rc.4で、Linux環境で使ってみたのですがちょっとまだまだ使えそうにない感じでした…。

ですが、完成度が上がると便利そうなので期待したいですね。

簡単に試してみたので、メモを残しておきます。

環境

今回の環境はこちら。

$ node --version
v18.18.2


$ npm --version
9.8.1

Ubuntu Linux 22.04 LTSへ導入してみました。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy


$ uname -srvmpio
Linux 5.15.0-88-generic #98-Ubuntu SMP Mon Oct 2 15:18:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

inshellisenseをインストールしてみる

inshellisenseのインストール。

$ npm i -g @microsoft/inshellisense

バージョン確認。

$ inshellisense --version
0.0.1-rc.4

ヘルプ。

$ inshellisense --help
Usage: inshellisense [options] [command]

IDE style command line auto complete

Options:
  -v, --version              output the current version
  -s, --shell <shell>        shell to use for command execution, supported shells: bash, pwsh, zsh, fish
  -c, --command <commmand>   command to use as initial input
  --history                  get the last command execute
  -d, --duration <duration>  duration of the autocomplete session, supported durations: single, session (default: "session")
  -h, --help                 display help for command

Commands:
  bind                       adds keybindings to the selected shell: bash, pwsh, zsh, fish
  uninstall                  removes all bindings and configuration for inshellisense

bash向けに起動してみます。

$ inshellisense --shell bash
>

専用のモードに切り替わるようで、この中でいろいろ補完ができたりします。

bindで、ショートカットも定義できます。

$ inshellisense bind
Select your desired shell for keybinding creation
> bash
  zsh
  fish
  pwsh

対象のシェルを選択します。今回はbashを選びました。

✓ successfully created new bindings

こんなファイルができます。

$HOME/.inshellisense/key-bindings.bash

__inshellisense__() {
    inshellisense -c "$READLINE_LINE" -s bash
    history -s $(inshellisense --history)
    READLINE_LINE=
}

bind -x '"\C-a": __inshellisense__'

また、.bashrcにロードが差し込まれます。

.bashrc

[ -f ~/.inshellisense/key-bindings.bash ] && source ~/.inshellisense/key-bindings.bash

この状態で、Ctrl-aを押すとinshellisenseが起動するようになります。ショートカットですね。

なのですが、Ctrl-cで終了してしますし、cdディレクトリ移動できませんし、Ctrl-aCtrl-eなどのbashでよく使うキーバインド
機能しなくなるので、ちょっと今のままだと導入できないですね…。

ただ、補完動作自体は良い感じだったので、バージョンが上がった時にまた試してみたいですね。