Max Mahn

aboutsummaryrefslogtreecommitdiff
path: root/src/main.sh
diff options
context:
space:
mode:
authorMax Mahn <mahn.maxwell@proton.me>2026-05-20 09:23:50 -0400
committerMax Mahn <mahn.maxwell@proton.me>2026-05-20 09:23:50 -0400
commit137e4ed9d74891349de1b0da1e0cf2653ea92c5e (patch)
tree29f913c45c081ec52269362eb2ce7f6f18d09070 /src/main.sh
initial commit
Diffstat (limited to 'src/main.sh')
-rw-r--r--src/main.sh111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/main.sh b/src/main.sh
new file mode 100644
index 0000000..1b38eab
--- /dev/null
+++ b/src/main.sh
@@ -0,0 +1,111 @@
+#!/bin/sh
+
+##########################################
+## { mktree } ##
+## Copyright(C) 2026 Maxwell Mahn ##
+## see LICENSE file for license details ##
+## - -- - -- - -- - -- - -- - -- - -- - ##
+## just a shell script for automating ##
+## the creation of repetative directory ##
+## structures. (like everytime you want ##
+## to start a new project; now you can ##
+## eliminate the setup time; surely ##
+## you'll finish the project this time) ##
+##########################################
+
+
+# default program configuration
+SETUP_SCRIPT=".setup.sh"
+
+cfg_dir="${MKTREE_CONFIGDIR:-${HOME}/.config/mktree}"
+
+USER_TEMPLATES="$cfg_dir/skel"
+SYSTEM_TEMPLATES="/etc/mktree/skel"
+
+##include src/util.sh
+
+
+GetTemplate() {
+ [ -z "$1" ] && return 1
+
+ for prefix in "${CUSTOM_TEMPLATES}" "${USER_TEMPLATES}" "${SYSTEM_TEMPLATES}"
+ do
+ [ -z "${prefix}" ] && continue
+ temp_path="${prefix}/$1"
+ Debug 2 "Checking template path '${temp_path}'..."
+ [ -d "${temp_path}" ] && echo "${temp_path}" && return 0
+ done
+ return 1
+}
+
+
+MakeProject() { # format_path, project_name
+ [ -z "$1" ] && Error "Project format not defined!" && return 1
+ [ -z "$2" ] && Error "Project name not defined!" && return 1
+
+ [ -d "$2" ] && Error "Can't make project in $2. Directory already exists." && return 1
+
+ # copy skeleton
+ Debug 1 "Copying template skeleton..."
+ cp -r "$1" "./$2" && cd "./$2"
+
+ # run hooks
+ Debug 1 "Running setup hooks..."
+ shift 2
+ setup="./${SETUP_SCRIPT}"
+ [ -f "${setup}" ] && sh "${setup}" $@
+
+ if [ $? -eq 0 ]
+ then
+ Debug 2 "Removing setup script..."
+ rm -f "${setup}"
+ else
+ Error "Failed to run setup hooks!"
+ fi
+
+ Debug 1 "Done."
+ return 0
+}
+
+
+ListTemplates() {
+ [ -d ${USER_TEMPLATES} ] && echo "User Templates:" && \
+ for template in ${USER_TEMPLATES}/*
+ do
+ echo " $(basename ${template})"
+ done
+ [ -d ${SYSTEM_TEMPLATES} ] && echo "System Templates:" && \
+ for template in ${SYSTEM_TEMPLATES}/*
+ do
+ echo " $(basename ${template})"
+ done
+ exit 0
+}
+
+
+SetSystemDir() {
+ [ -d "$1" ] && SYSTEM_TEMPLATES="$1" return 0 || return 1;
+}
+
+SetUserDir() {
+ [ -d "$1" ] && USER_TEMPLATES="$1" return 0 || return 1;
+}
+
+SetFormatPath() {
+ [ -d "$1" ] && FMT_PATH="$1" return 0 || return 1;
+}
+
+SetVerbose() {
+ VERBOSITY+=1
+}
+
+
+##insert awk -v OUTPUT=shell -f args.awk res/args
+
+##include src/args.sh
+
+
+# parsing options
+options=$(${GETOPT_CMD}) && ParseOpts ${options} \
+ || Error "Run '$(basename $0) -h' for usage information." && exit 1
+