#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG					#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2020 Christopher Bratusek		#
#							#
#########################################################

. gettext.sh
export TEXTDOMAIN="bashstyle-rc"

case ${1} in
	--help | -h | "")
		bashstyle-help -a "Christopher Roy Bratusek" -e "nano@jpberlin.de" -h "https://www.nanolx.org/"\
				-l "GNU GPL v3" -n "random" -s "$(eval_gettext "print random numbers or strings")"\
				-v "${BSNG_VERSION}" -y "${BSNG_YEAR}"\
				-o "$(eval_gettext "-s:length|print string containing all printable chars except space")"\
				-o "$(eval_gettext "-0:length|print random number of given length")"\
				-o "$(eval_gettext "-r:(lowest) highest|print random number in range lowest (or 0) and highest")"\
				-o "$(eval_gettext "-a:length|print string containing only mixed-case letters")"\
				-o "$(eval_gettext "-l:length|print string containing only lower-case letters")"\
				-o "$(eval_gettext "-u:length|print string containing only upper-case letters")"\
				-o "$(eval_gettext "-x:length|print string of hexadecimal numbers")"\
				-o "$(eval_gettext "-a0:length|print alpha-numeric string (mixed-case)")"
	;;

	--special | -s )
		echo -e "$(tr -cd '[:graph:]' < /dev/urandom | head -c "${2:-16}")\n"
	;;

	--numerical | -0 )
		echo -e "$(tr -cd '[:digit:]' < /dev/urandom | head -c "${2:-16}")\n"
	;;

	--numericalrange | -r )
		if [[ ${3} ]]; then
			shuf -i "${2}-${3}" -n 1
		else	shuf -i "0-${2}" -n 1
		fi
	;;

	--alpha | -a )
		echo -e "$(tr -cd '[:alpha:]' < /dev/urandom | head -c "${2:-16}")\n"
	;;

	--alphalow | -l )
		echo -e "$(tr -cd '[:lower:]' < /dev/urandom | head -c "${2:-16}")\n"
	;;

	--alphaup | -u )
		echo -e "$(tr -cd '[:upper:]' < /dev/urandom | head -c "${2:-16}")\n"
	;;

	--hexadecimal | -x )
		echo -e "$(tr -cd '[:xdigit:]' < /dev/urandom | head -c "${2:-16}")\n"
	;;

	--alphanumerical | -a0 )
		echo -e "$(tr -cd '[:alnum:]' < /dev/urandom | head -c "${2:-16}")\n"
	;;
esac
