From 29ebc7bd0a510e056dc7b5eb176a1dbb817d645d Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 22 Sep 2024 19:04:20 -0300 Subject: [PATCH] Polish 'new' command --- bin/webskel | 2 +- libexec/webskel/commands/new | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/bin/webskel b/bin/webskel index 7df7eac..cfac6e4 100755 --- a/bin/webskel +++ b/bin/webskel @@ -15,7 +15,7 @@ libexec="${localbase}"/libexec/webskel # main case $1 in "new") - "${libexec}"/commands/new + "${libexec}"/commands/new "${2}" "${3}" ;; "ls") "${libexec}"/commands/ls diff --git a/libexec/webskel/commands/new b/libexec/webskel/commands/new index e69de29..aad1231 100755 --- a/libexec/webskel/commands/new +++ b/libexec/webskel/commands/new @@ -0,0 +1,44 @@ +#!/bin/sh +set -e + +## +# variables +localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} +sharebase="${localbase}"/share/webskel +libexec="${localbase}"/libexec/webskel +appname="${1}" +skel="${2}" + +## +# functions +. "${libexec}"/functions/print.sh + +## +# main +if [ -z "${appname}" ]; then + printerr "provide an application name" + exit 1 +fi +if [ -z "${skel}" ]; then + printerr "provide a skeleton name" + exit 1 +fi +if [ -e "${sharebase}"/"${skel}".skeleton ]; then + target="${sharebase}"/"${skel}".skeleton + cwd=$(pwd) + cd ${target} + find . \ + -type d \ + -exec install -d -m u=rwx,g=rx,o= "${cwd}"/"${appname}"/"{}" \; \ + -exec echo -n . \; + echo + find . \ + -type f \ + -exec install -m u=rwx,g=rx,o= {} "${cwd}"/"${appname}"/"{}" \; \ + -exec echo -n . \; + echo + printok "initialized ${app}" +else + printerr "skeleton ${skel} was not found" + exit 1 +fi