Improve handling of directory options
This commit is contained in:
parent
c631528c6a
commit
b18cff3ee5
@ -6,7 +6,8 @@ trap 'exit 1' SIGINT
|
|||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
VERSION=2.0.0
|
VERSION=2.0.0
|
||||||
DEFAULT_TEMPLATE_DIR="$HOME/Templates"
|
template_dir="$HOME/Templates"
|
||||||
|
fd_opts=(--type f --threads "$(nproc)")
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
function help() {
|
function help() {
|
||||||
@ -29,7 +30,7 @@ HELPMESSAGE
|
|||||||
while true; do
|
while true; do
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
'-d' | '--dir')
|
'-d' | '--dir')
|
||||||
DIR="${2}"
|
template_dir="${2}"
|
||||||
case "${DIR}" in
|
case "${DIR}" in
|
||||||
"")
|
"")
|
||||||
exit 1
|
exit 1
|
||||||
@ -42,7 +43,7 @@ while true; do
|
|||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
--dir=*)
|
--dir=*)
|
||||||
DIR="${1#*=}"
|
template_dir="${1#*=}"
|
||||||
case "${DIR}" in
|
case "${DIR}" in
|
||||||
"")
|
"")
|
||||||
exit 1
|
exit 1
|
||||||
@ -77,19 +78,14 @@ while true; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# If directory wasn't overridden
|
|
||||||
if [[ -z "$DIR" ]]; then
|
|
||||||
DIR="$DEFAULT_TEMPLATE_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If no target specified
|
# If no target specified
|
||||||
if [[ -z "$1" ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
printf '%s\n' 'Please specify target name'
|
printf '%s\n' 'Please specify target name'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if default template directory exists
|
# Check if template directory exists
|
||||||
if ! [[ -d "$DIR" ]]; then
|
if ! [[ -d "$template_dir" ]]; then
|
||||||
printf '%s\n' "Template directory doesn't exist, exiting."
|
printf '%s\n' "Template directory doesn't exist, exiting."
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user