#!/bin/bash

if [ -z "$1" ]
then
	printf 'Repository: '
	read
	set "$REPLY"
fi

if [ ! -f "$1/HEAD" ]
then
	echo 'Repository has been deleted or moved!'
fi

set "${1##/}"

if echo -e "?^$1\$?" | ed -s /public_repos >/dev/null 2>&1
then
	echo -e "g|^$1$|d\nw" | ed -s /public_repos
	echo "'$1' is now private!"
elif [ -f "$1/HEAD" ]
then
	echo "Already private!"
else
	clue="$(echo -e "?$1?" | ed -s /public_repos 2>/dev/null)"
	[ "$clue" != '?' ] && echo "Perhaps you wanted: $clue"
	exit 1
fi
