rewrite complete #1

Merged
vx-clutch merged 20 commits from rewrite into main 2026-01-14 20:39:15 -05:00
Showing only changes of commit 4a0c8dd0c6 - Show all commits

128
bin/yait
View File

@@ -5,15 +5,15 @@ scriptversion="1"
#
#
# Copyright (C) 2025-2026 vx-clutch
# Copyright (C) 2025-2026 fSD
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
me=$0
version="$me v$scriptversion
me=$(basename "$0")
version="$me\/fSD v$scriptversion
Copyright (C) 2025-2026 fSD.
This is free software; you are free to change and redistribute it.
@@ -27,35 +27,122 @@ Options:
--help print this help and exit
--version output version information
-x <language> set project type
-S small project creation
-f overwrite existing files
-a <author> set project author
-r initialize Git repository for the project
-q surpress output"
-x <language> set project type
-d <description> set a description
-S small project creation
-f overwrite existing files
-a <author> set project author
-r initialize Git repository for the project
-q surpress output"
x=C # language
x=c # language
d="Does a thing" # package description
S= # small project creation (bool)
f= # force (bool)
a=$(git config user.name) # author
r= # initialize repository (bool)
q= # surpress output
format() {
say() {
if [ -z "$q" ]; then
echo "$me: $*"
fi
}
lsay() {
if [ -z "$q" ]; then
echo " => $*"
fi
}
create_project() {
name=$1
if ! echo "$name" | grep -qE '^[A-Za-z0-9_-]+$'; then
format "invalid name '$name'"
say "invalid name '$name'"
exit 1
fi
echo "invoke"
shell() {
if [ -z "$S" ]; then
mkdir "$name" || return
cd "$name" || return
touch COPYING Makefile README.md "$name.1" .gitignore
mkdir bin
else
cat <<EOF > "$name"
#! /bin/sh
# $d
scriptversion="1"
#
#
# Copyright (C) $(date "+%Y") $a
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
me=\$0
version="\$me/$a v\$scriptversion
Copyright (C) $(date "+%Y") $a.
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law."
usage="\
Usage: \$me [OPTION]... <arg1> <arg2>
$d
Options:
--help print this help and exit
--version output version information"
say() {
if [ -z "\$q" ]; then
echo "\$me: \$*"
fi
}
lsay() {
if [ -z "\$q" ]; then
echo " => \$*"
fi
}
if ! [ \$# -gt 0 ]; then
echo "\$usage"
exit 0
fi
while [ \$# -gt 0 ]; do
case \$1 in
--help) echo "\$usage"; exit 0 ;;
--version) echo "\$version"; exit 0 ;;
-*) echo "\$me: Unknown option '\$1'." >&2; exit 1 ;;
esac
done
say hello world
EOF
chmod +x "$name"
fi
}
c() {
lsay "sub routine: c"
}
case $x in
sh) say "using shell"; shell ;;
c) say "using C"; c ;;
*) say "defaulting to C"; c ;;
esac
say "made $name at $(realpath "$name")"
}
if ! [ $# -gt 0 ]; then
@@ -67,13 +154,14 @@ while [ $# -gt 0 ]; do
case $1 in
--help) echo "$usage"; exit 0 ;;
--version) echo "$version"; exit 0 ;;
-x) shift; x=$1; break ;;
-S) S=true; break ;;
-f) f=true; break ;;
-a) shift; a=$1; break ;;
-r) r=true; break ;;
-q) q=true; break ;;
-x) shift; x="$1"; shift ;;
-d) shift; d="$1"; shift ;;
-S) S=true; shift ;;
-f) f=true; shift ;;
-a) shift; a="$1"; shift ;;
-r) r=true; shift ;;
-q) q=true; shift ;;
-*) echo "$me: Unknown option '$1'." >&2; exit 1 ;;
*) create_project $1; shift ;;
*) create_project "$1"; shift ;;
esac
done