dotfiles/bin/tmux-open-git.sh (view raw)
| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | p="$(tmux run 'echo #{pane_current_path}')" |
| 4 | cd "$p" |
| 5 | url=$(git remote get-url origin 2>/dev/null) \ |
| 6 | || url=$(git remote get-url olexsmir 2>/dev/null) \ |
| 7 | || url=$(git remote get-url upstream 2>/dev/null) \ |
| 8 | || { echo "No remote 'origin', 'olexsmir', or 'upstream' found in $p"; exit 1; } |
| 9 | |
| 10 | if [[ $url == git@* ]]; then |
| 11 | url="${url#git@}" |
| 12 | url="${url/://}" |
| 13 | url="https://$url" |
| 14 | fi |
| 15 | |
| 16 | url="${url%.git}" |
| 17 | if [[ $url == https://* || $url == http://* ]]; then open "$url" |
| 18 | else echo "Cannot open: unrecognized remote format: $url: in $p" |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | if command -v xdg-open &>/dev/null; then xdg-open "$url" >/dev/null |
| 23 | elif command -v open &>/dev/null; then open "$url" >/dev/null |
| 24 | else tmux display-message "no opener found: $url" ; exit 1 |
| 25 | fi |
| 26 | |
| 27 | tmux display-message "opened: $url" |