#!/usr/bin/env bash die () { echo "$1" exit 1 } ## Generate one time user login link. Add -s to use https in url. ## Usage fin uli @drushalias -s ## The drush alias and -s flags are optional. cd "$PROJECT_ROOT/$DOCROOT" || die "Could not change dir to $PROJECT_ROOT/$DOCROOT" https=0 # Default to not use https # Check the first two options / arguments given on the the command line for # what looks like a Drush site alias or the -s option to use https in the url. count=2 while [ $count -ne 0 ]; do if [[ $1 == @* ]]; then drushalias=$1 shift 1 elif [[ $1 == "-s" ]]; then https=1 shift 1 fi count=$[$count-1] done if [ $https -eq 0 ]; then uli=$(fin drush $drushalias uli "$@" 2>&1 | sed "s/default/$VIRTUAL_HOST/") elif [ $https -eq 1 ]; then uli=$(fin drush $drushalias uli "$@" 2>&1 | sed "s/default/$VIRTUAL_HOST/" | sed "s/http\:/https:/") else exit 2 fi echo "$uli" [[ "$uli" == *"Error"* ]] && exit 1 # Mac OSX copy uli to clipboard with pbcopy ( which pbcopy >/dev/null 2>&1 ) && echo "$uli" | pbcopy && echo "[+] Copied to clipboard" # Linux copy uli to both the selection buffer and clipboard with xclip. ( which xclip >/dev/null 2>&1 ) && echo "$uli" | xclip -i -sel c -f |xclip -i -sel p && echo "[+] Copied to clipboard and selection buffer"