Mac + ghq + peco — GithubのURLをショートカットで開けるようにする例


動作例

選ぶと

開く

動作環境

Mac + zsh + ghq + peco

手順

  • ghq で リモートレポジトリを管理しておく
    • こんな感じでレポジトリを ghq 管理に入れるだけ ( ghq get https://github.com/YumaInaura/zsh/)
  • peco で インクリメンタルサーチする
  • zsh の bindkey でショートカットを作る

~.zshrc に以下を追加

_ghq_open() {
  if [ ! $(which peco) ]; then echo "You need peco" && exit 1; fi

  local remote_repository_web_url=$(ghq list | sed -e 's/^/https:\/\//g' | peco --query="$BUFFER")

  if [ ! -z "$remote_repository_web_url" ]; then
    BUFFER="open $remote_repository_web_url"
    zle accept-line
  fi
}

zle -N ghq-open _ghq_open

bindkey '^G^O' ghq-open

ghq list で得られる一覧の先頭に https:// を付けているだけ

Versions

  • Mac OS High Sierra
  • zsh 5.5.1 (x86_64-apple-darwin17.5.0)
  • ghq version 0.8.0
  • peco version v0.5.3 (built with go1.10)

Links