Q:

How to get git repo from url

I have repo git@gitlab.com:alex93ushakov-mail/test.git. 
In Bash, I'd like to write a function which takes the git url as an argument and returns the repository name 'test'.  How to do this? 

A:

function foo() {
  local a="$1"          # copy first argument to local variable a
  a="${a##*/}"          # strip left part including /
  echo "${a%.git*}"     # strip trailing .git
}

foo "git@gitlab.com:alex93ushakov-mail/test.git"

Output:

test

To avoid trailing newline: add option -n to echo

