#!/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