LoginSignup
4
0

More than 3 years have passed since last update.

GitHubリポジトリ毎に tmux のセッション作ったり ghq で自動で取得してくれたりするスクリプト

Last updated at Posted at 2017-05-20

GitHubリポジトリを取ってきてtmuxの別セッションでそのコードを見たいとか、作業しててリポジトリ毎にtmuxのセッション分けたい、みたいな気持ちがよくあって、以下のような関数を ~/.zshrc に入れて使っている。

function tmux-look {
  local ghq_get_query="$(echo $1 | sed -e 's/^github\.com\///')"
  local ghq_look_query="$(echo $1 | sed -e 's/^https:\/\///' -e 's/^git@github\.com://' -e 's/^github\.com\///' -e 's/\.git$//')"
  ghq get $ghq_get_query || return 1

  local tmux_dir="$(ghq list -p -e $ghq_look_query)"
  local tmux_name="$(ghq list -e $ghq_look_query | sed -e 's/^github\.com\///')"
  [ -n "$tmux_dir" ] || return 1

  if [ -n "$TMUX" ]; then
    tmux -2 new-session -d -c $tmux_dir -s $tmux_name
    tmux switch-client -t $tmux_name
  else
    tmux -2 new-session -A -c $tmux_dir -s $tmux_name
  fi
}

上の関数は下記のコマンドをtmux内にいる場合とかの空気を読んでやってくれるようになっている。

ghq get https://github.com/tootsuite/mastodon
ghq get --look tootsuite/mastodon
tmux new-session -s tootsuite/mastodon

URLとかを与えた場合も適当に正規化するように書いているので、下のどのパターン渡しても上手くやってくれるようになっている。

tmux-look https://github.com/tootsuite/mastodon
tmux-look git@github.com:tootsuite/mastodon
tmux-look tootsuite/mastodon

(bitbucket.org とかは面倒くさくて対応していない)

4
0
0

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
4
0