citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

srht-clone (559B)


      1 #!/usr/bin/env bash
      2 
      3 set -e
      4 
      5 usage () {
      6   printf "usage: srht-clone <owner>[/]<repo>\n" >&2
      7   exit 1
      8 }
      9 
     10 already_exists () {
     11   printf "%s\n" "$2"
     12   exit 2
     13 }
     14 
     15 root=${SRHT_ROOT:-"$HOME/dev/srht"}
     16 owner="$1"
     17 
     18 shift
     19 
     20 [ -z "$owner" ] && usage
     21 
     22 IFS='/' read -ra parsed <<< "$owner"
     23 owner="${parsed[0]}"
     24 repo="${parsed[1]}"
     25 if [ -z "$owner" ] || [ -z "$repo" ]; then
     26     usage
     27 fi
     28 
     29 dest="$root/$owner"
     30 dir="$dest/$repo"
     31 
     32 [ -d "$dir" ] && already_exists "$owner/$repo" "$dir"
     33 
     34 mkdir -p "$dest"
     35 cd "$dest"
     36 git clone "$@" "srht:$owner/$repo"
     37 
     38 printf "%s\n" "$dest/$repo"