Created
May 22, 2025 18:24
-
-
Save selimhex/cdb3887a65d56cac8042654ecf83702f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rest is basically this one-liner with better fallbacks | |
# open $(git remote -v | grep "push" | fzf | awk '{print $2}' | sed -e "s/^.*@//" -e "s/\:/\//" -e "s/\.git$//" | sed -e "s/^/https:\/\//") | |
open_remote() { | |
_formatSshUrlToHttp() { | |
sshUrl="$1" | |
url=$(echo $sshUrl | sed -e "s/^.*@//" -e "s/\:/\//" -e "s/\.git$//" -e "s/^/https:\/\//") | |
echo $url | |
} | |
_remoteToUrl() { | |
chosen_remote="$@" | |
url=$(_formatSshUrlToHttp $(echo "$chosen_remote" | awk '{print $2}')) | |
echo $url | |
} | |
local filter="$@" | |
if [[ -n "$filter" ]]; then | |
local matching_remotes=$(git remote -v | grep "push" | grep -i "$filter") | |
[[ -z $matching_remotes ]] && echo "no remote found matching: $filter" && return | |
local chosen_remote=$(echo "$matching_remotes" | fzf) | |
[[ -z $chosen_remote ]] && return # quit silently | |
open $(_remoteToUrl $chosen_remote) | |
return | |
fi | |
local chosen_remote=$(git remote -v | grep "push" | fzf) | |
[[ -z $chosen_remote ]] && return # quit silently | |
open $(_remoteToUrl $chosen_remote) | |
} | |
open_remote $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment