Skip to content

Instantly share code, notes, and snippets.

@mumoshu
Forked from mechairoi/tmux-ghq
Last active December 27, 2017 02:48
Show Gist options
  • Save mumoshu/7b9d2d579c9c8dfd8f0b834da139063d to your computer and use it in GitHub Desktop.
Save mumoshu/7b9d2d579c9c8dfd8f0b834da139063d 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; find ~/Repositories -depth 1; find "$GOPATH/src" -depth 1 ) | $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