Created
January 18, 2013 04:46
-
-
Save hansode/4562398 to your computer and use it in GitHub Desktop.
generate 'git clone' command using git protocol.
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
| #!/bin/bash | |
| # | |
| # requires: | |
| # bash | |
| # | |
| # description: | |
| # | |
| # https://gist.github.com/012345678abcdefgh.git | |
| # git@gist.github.com:012345678.git | |
| # | |
| set -e | |
| ## functions | |
| function usage() { | |
| cat <<-EOS | |
| SYNOPSIS: | |
| ${0##*/} [ gist-uri ] | |
| EXAMPLES: | |
| ${0##*/} https://gist.github.com/012345678abcdefgh.git | |
| EOS | |
| } | |
| function validate_parameter() { | |
| [[ -n "${git_uri}" ]] || return 1 | |
| } | |
| ## variables | |
| declare git_uri=$1 | |
| declare long_hash=${git_uri##*/}; long_hash=${long_hash%%.git} | |
| declare short_hash=${long_hash:0:7} | |
| ## validate | |
| validate_parameter || { | |
| usage | |
| exit 1 | |
| } | |
| ## main | |
| echo git clone git@gist.github.com:${long_hash}.git gist-${short_hash} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment