diff mbox

dim: allow setup to work with different usernames

Message ID 20170615154313.7768-1-lionel.g.landwerlin@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lionel Landwerlin June 15, 2017, 3:43 p.m. UTC
If your username on fd.o differs from your local username, you'll run
into issues while setting up dim.

Let's use regexp to filter remotes so it doesn't fail.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 dim | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/dim b/dim
index 89378033f472..a812320581c2 100755
--- a/dim
+++ b/dim
@@ -228,21 +228,22 @@  function url_to_remote # url
 {
 	local url remote
 
-	url="$1"
+	url=$1
+	login_url=$(echo $url | sed -e 's,ssh://,ssh://[a-zA-Z0-9]+@?,')
 
 	if [[ -z "$url" ]]; then
 		echoerr "$0 without url"
 		return 1
 	fi
 
-	remote=$(git remote -v | grep -m 1 "$url" | cut -f 1)
+	remote=$(git remote -v | grep -m 1 -E "$login_url" | cut -f 1)
 
 	if [[ -z "$remote" ]]; then
-		git_url=$(echo $url | sed -e 's/git\./anongit./' -e 's/ssh:/git:/')
-		remote=$(git remote -v | grep -m 1 "$git_url" | cut -f 1)
+		git_url=$(echo $url | sed -e 's/git\./anongit./' -e 's,ssh://[a-zA-Z0-9]+@?,git://,')
+		remote=$(git remote -v | grep -m 1 -E "$git_url" | cut -f 1)
 
 		if [[ -z "$remote" ]]; then
-			echoerr "No git remote for url $url or $git_url found in $(pwd)"
+			echoerr "No git remote for url $url, $login_url or $git_url found in $(pwd)"
 			echoerr "Please set it up using:"
 			echoerr "    $ git remote add <name> $url"
 			echoerr "with a name of your choice."