Skip to content

Commit

Permalink
Use readlink, format help, bump version to 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
remino committed Oct 4, 2022
1 parent 15aa5b4 commit 8b89c94
Showing 1 changed file with 8 additions and 52 deletions.
60 changes: 8 additions & 52 deletions mkx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
# mkx
# Make new shell script executable file from template.

VERSION='2.0.0'
VERSION='2.1.0'

mkx_main() {
trap _exit INT TERM

e_args=16
e_exists=17
e_missing_app=18

_require realpath

scriptpath="$( realpath "$0" )"
scriptpath="$( readlink -f "$0" )"
scriptname="$( basename "$scriptpath" )"
scriptdir="$( dirname "$scriptpath" )"

bare=0
interpreter='/bin/sh'
Expand Down Expand Up @@ -65,11 +61,11 @@ mkx_help() {
cat <<USAGE
$scriptname $VERSION
Usage: $scriptname [-bhvx] [-i interpreter] scriptfile
USAGE: $scriptname [-bhvx] [-i interpreter] scriptfile
Make new shell script executable file from template.
Options:
OPTIONS:
-b Only write a bare script with only the shebang line, without template.
If output file already exists, make it executable.
Expand Down Expand Up @@ -129,24 +125,6 @@ _invalid_opt() {
exit $e_args
}

_require() {
missing_bin=0

for bin in "$@"
do
if ! which "$bin" > /dev/null 2>&1
then
missing_bin=1
_error "Required: $bin"
fi
done

if [ $missing_bin -ne 0 ]
then
_fatal $e_missing_app "One or more executables or apps are missing."
fi
}

mkx_main "$@"
exit

Expand All @@ -160,14 +138,10 @@ __SCRIPTNAMESC___main() {
trap _exit INT TERM

e_args=16
e_missing_app=17

_require realpath

scriptinv="$( basename "$0" )"
scriptpath="$( realpath "$0" )"
scriptpath="$( readlink -f "$0" )"
scriptname="$( basename "$scriptpath" )"
scriptdir="$( dirname "$scriptpath" )"

while getopts hv opt
do
Expand Down Expand Up @@ -198,14 +172,14 @@ __SCRIPTNAMESC___help() {
cat <<USAGE
$scriptname $VERSION
Usage: $scriptinv [-hv] command
USAGE: $scriptinv [<options>] <command> [<args>]
Commands:
COMMANDS:
help Show this help screen.
version Show script name and version number.
Options:
OPTIONS:
-h Show this help screen.
-v Show script name and version number.
Expand Down Expand Up @@ -255,22 +229,4 @@ _invalid_opt() {
exit $e_args
}

_require() {
missing_bin=0

for bin in "$@"
do
if ! which "$bin" > /dev/null 2>&1
then
missing_bin=1
_error "Required: $bin"
fi
done

if [ $missing_bin -ne 0 ]
then
_fatal $e_missing_app "One or more executables or apps are missing."
fi
}

__SCRIPTNAMESC___main "$@"

0 comments on commit 8b89c94

Please sign in to comment.