Skip to content

Instantly share code, notes, and snippets.

@mechairoi
Created December 26, 2017 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mechairoi/41201c4579d17253b7bd26e699c6dccb to your computer and use it in GitHub Desktop.
Save mechairoi/41201c4579d17253b7bd26e699c6dccb to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Put followings your .tmux.conf
#
# bind ^T run-shell tmux-ghq
#
set -e
fzfcmd="fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} -e +s"
tmux start-server
selected=$( (tmux list-sessions; ghq list --full-path) | $fzfcmd) && true
status=$?
if [ $status -eq 0 ]; then
if echo "$selected" | grep ': ' > /dev/null; then
session_name=$(echo "$selected" | cut -f 1 -d ':')
else
repo=$(basename "$selected")
owner=$(basename "$(dirname "$selected")")
session_name=$(echo "${owner}/${repo}" | sed -e 's/[^A-Za-z0-9_/-]/_/g')
tmux new-session -d -c "$selected" -s "$session_name" 2> /dev/null || true
fi
if [[ -z "$TMUX" ]]; then
exec tmux attach-session -t "$session_name"
else
tmux switch-client -t "$session_name"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment