fish shell から ghq 内のプロジェクトを VSCode で開く

Shell

環境

  • macOS Catalina 10.15.5
  • fish 3.1.2
  • VSCode 1.47.0 x64

必要なもの

decors/fish-ghq と oh-my-fish/plugin-peco が必要。

shell

brew install ghq
fisher add decors/fish-ghq

brew install peco
fisher add peco

VSCode の CLI も必要。エディター内でコマンドパレットを開き、Shell Command: Install 'code' command in PATH (PATH 内に 'code' コマンドをインストールします)でインストールできる。
https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line

スクリプト

.config/fish/config.fish を編集する。
function 名、fish_user_key_bindings の有無やキーはお好みで。
code コマンド単体でも VSCode が開くので、peco の操作をキャンセルした時は実行しないようにする。

.config/fish/config.fish

function ghqcode
  set repo (ghq list | peco)
  if test -n "$repo" 
    code (ghq root)/(echo $repo)
  end
end

function fish_user_key_bindings
  bind \ce ghqcode
end