Skip to content

Instantly share code, notes, and snippets.

@hansode
Created January 18, 2013 04:46
Show Gist options
  • Select an option

  • Save hansode/4562398 to your computer and use it in GitHub Desktop.

Select an option

Save hansode/4562398 to your computer and use it in GitHub Desktop.
generate 'git clone' command using git protocol.
#!/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