commit - 22158a1d7c0529bdf391f4bf99a930dc6145819d
commit + 15169311c502349645c62e8b2961ee8eab25a48e
blob - 033632179f42858930bec935d5f26b75646d1c61
blob + c65b07d9eebb9a884306d10e4972ceb7a235685c
--- nwpg.sh
+++ nwpg.sh
-#!/bin/sh
+#!/bin/zsh
# nwpg (NeW ProGram)
# Simple script that initiates a new project
# the algorithm, the code, the documentation,
# i.e. main.algo, main.c, main.doc
#
-# syntax: nwpg [language] project_title
+# syntax: nwpg [-h] [-d directory] [-l language] project_title
+# see EOF for TODO
+DEFAULT_DIR="$HOME/hack/" ;
+DEFAULT_LANG="C" ;
+USAGE="usage: nwpg [-h] [-l language] [-d directory] project_title" ;
+
case $# in
- 0)
- echo "Usage: nwpg [language] project_title" ;
- error=1 ;;
1)
- project_title="$1" ;;
- 2)
- project_title="$2" ;
- case $1 in
- C | c )
- file_ext="c" ;;
- Python | Py | py )
- file_ext="py" ;;
- Rust )
- file_ext=""
- echo "Rust project" ;;
- * )
- file_ext="" ;;
+ if [ $1 == '-h' ] || [ $1 == '--help' ]
+ then
+ error=1
+ fi
+ language="$DEFAULT_LANG" ;
+ project_title="$1" ;
+ directory="$DEFAULT_DIR$project_title" ;;
+ 3 | 5)
+ #which_shell= ps -p $$ | awk '{if(NR>1)print}' | awk '$0=$NF' | tr -d - ;
+ #echo $which_shell ;
+ #case $which_shell in
+ # "zsh" )
+ # echo "using zsh" ;
+ project_title="${@[-1]}" ;
+ # "ksh" | "bash" )
+ # echo "using ksh or bash" ;
+ # project_title="$!#" ;#;
+ #esac
+ #echo "Project title: $project_title" ;
+ case $1 in
+ -l )
+ language="$2" ;
+ directory="$DEFAULT_DIR$project_title" ;;
+ -d )
+ language="$DEFAULT_LANG" ;
+ directory="$2/$project_title" ;;
+ esac
+ case $3 in
+ -l )
+ language="$4" ;;
+ -d )
+ directory="$4/$project_title" ;;
esac ;;
*)
- echo "Too many arguments" ;
error=1 ;;
esac
if [ -n $error ]
then
- mkdir -p $HOME/hack/$project_title ;
- touch $HOME/hack/$project_title/main.{$file_ext,doc,algo} ;
+ mkdir -p $directory ;
+ #echo "Arguments:\n\t\$1 $1\n\t\$2 $2\n\t\$3 $3" ;
+ case $language in
+ C | c )
+ #echo "programming in C" ;
+ file_ext="c" ;;
+ Python | Py | py )
+ file_ext="py" ;;
+ Rust )
+ #echo "Rust project" ;
+ file_ext="" ;;
+ * )
+ file_ext="" ;
+ echo $USAGE ;;
+ esac
+ touch $directory/main.{$file_ext,doc,algo} ; #&& echo "files created : $directory/main.{$file_ext,doc,algo}" ;
+else
+ echo $USAGE ;
fi
#
# TODO
-# Add help displayed using -h
-# or when no argument is provided
#
+# Use getopts for a cleaner ksh script
+# Separate linux, macos and openbsd versions
+# Clean commented debugging features
+#