Releases: zpiatt/gen
v2.0.4
Version 2 is here! Gen
has come a long way from a simple function in my bashrc
. I've probably learned more Bash than anyone needs to know in making this, and it's been a lot of fun. Thank you to everyone who helped get me this far!
This release contains a major functionality change, and several small bug fixes:
Bug Fixes/Improvements:
- Realigned templates with original design intent. Only shell script support is hard-coded into
gen
.- Custom templates continue to be 100% optional, however,
gen
installs several examples by default. - My goal is to make the main script as simple as possible with the intent for streamlined scripting; not a replacement for robust boilerplate solutions.
- Custom templates continue to be 100% optional, however,
- Complete overhaul of error codes and exit statuses.
Gen
will now exit on errors with statuses that reflect the nature of the error. Please check out theman
page for more details.
Man
page is now complete.- The
man
includes details on exit statuses, a thorough explanation on howgen
selects an editor, the thought process for changing file permissions, and descriptions for all arguments.
- The
- Removed all
HereDocs
.- This is purely a style choice, however, HereDocs require actual tab characters to maintain readability. In practice, HereDocs (IMHO) become unreadable easily, so I did away with them entirely.
- I made several other small changes in the name of readability.
- Complete rework of the
create_file
function to handle all error cases ( hopefully ). - Complete rework of file permission assignments.
gen
now automatically ensures at least read/write permissions are given to the user. In practice, this should catch anyumask
errors, orread-only
filesystems.Gen
relies on the robust error handling ofchmod
and allows error messages fromchmod
to be printed.
- Deprecated
-x
option.-c
now handles all possible custom file permissions. ( Must use octal mode bits [ i.e.754
, etc. ] ).- I also added input validation to
-c
that confirm a user enter3
digits from0-7
. I may revisit this and attempt to include symbolic mode bits (u+rw
) as well.
- I also added input validation to
Moving forward:
- I'm working on adding workflows for automated testing. I have almost no knowledge of how this works, so this is mostly for me to learn. My goal would be more reliable commits.
- No features will be pushed/pulled that cannot pass
shellcheck
ANDset -o nounset
.
v1.7.0-stable
This release contains a major bug fix and several small bug fixes:
Bug Fixes/Improvements:
- Added input validation for providing a directory path to
gen
.- Previously,
gen
would launch an editor into the directory ( same asvim <directory>
); now it provides an error message similar torm <directory>
( i.e without-rf
) and exits with error code 1. - Crucially, prior to this change,
gen
was attempting to make other changes to the directory. This could have unintended consequences especially in the case of selecting custom modes ( i.e.gen -c 777 <directory>
)
- Previously,
- Added additional input validation to the
create_file
function; allowing for users to answery
oryes
(regardless of capitalization) when overwriting an existing file. - Fixed bug with selection of custom mode. The
-c
option now sets the variable$cust_mode
and the mode is set accordingly:chmod "${cust_mode:-${mode}}" "$filename"
.- Previously, if a file extension was recognized in the
get_ext
function, and it called for the mode to be set, it would overwrite$mode
.
- Previously, if a file extension was recognized in the
- Additionally, I found a redirection error in the
which_ed
function wherestdout
/stderr
were being redirected, preventing$editor
being set by thestdout
of the command:editor="$(which "$ed" 2> /dev/null)"
- I also changed the verification of editors to the builtin
command -v
. In practice, this should be both faster and more portable. - In the
get_args
function, when an editor is being selected manually (gen -e nano
), I created an error message similar to the error output oftype
.
- I also changed the verification of editors to the builtin
Moving forward:
- I'm working on re-adding the
create_multi
function (or at least that feature). I removed it with the last release because I was unhappy with it's performance. My goal is to allow for creating multi files as you would withtouch
( i.e.gen test{00..99}.sh
) with minimum impacts to performance. - No features will be pushed/pulled that cannot pass
shellcheck
ANDset -o nounset
.
v1.6.4
This release contains several small bug fixes and two new features:
- Added
-f
option to overwrite existing file without prompting. This function is similar torm -f
- Added manual page. Man page installs automatically with
Makefile
installation. Ideally this file would be compressed, but I left it uncompressed so it can be reviewed prior to installation/download. - Removed
create_multi
function. In practice, this feature had limited applicability and unnecessarily complicated the program. If I find someone was relying on this feature I could consider rethinking how to implement it.
Bug Fixes/Improvements:
- Removed localization settings. Setting
LC_ALL=C
andLANG=C
did yield an improvement in the primary script's performance. However, an unintended consequence was this overrode the user's localization settings when the editor launched. - Removed error redirection to
/dev/null
when usingtouch
to create file. Full error messages fromtouch
are now displayed to account for all possible errors (permissions, file system fault, non-existent path, etc.). - The
create_file
function now prompts users to overwrite a file if it exists. Overwrite message appears similar to common commands (i.e.rm -i
ormv -i
) .
Moving forward:
- No features will be pushed/pulled that cannot pass
shellcheck
ANDset -o nounset
.
v1.6.0-stable
My first stable
version! This release contains several small bug fixes and one new feature:
- Added
-c
option for customization of file permissions. The default functionality ofgen
adds user-owner execute permissions for formats that are typically executable. Previously, the-x
option was added to assign user-owner execute permissions for any format (this was done with custom templates in mind). Now-c
allows for more granularity of file permissions. NOTE: both symbolic notation (gen -c ug+x test.sh
) and octal notation (gen -c 775 test.sh
) are valid. Gen
now checks environmental variables$VISUAL
and$EDITOR
. This is similar to common command line tools (git
,visudo
,less
, etc ). To ensure an editor launches,gen
also tests a user's$PATH
for:nano
,vi
, anded
. I added input validation when selecting an editor (gen -e emacs test.sh
) usingwhich
. I also clarified thatgen
effects only local variables by setting$editor
instead of$EDITOR
.- Removed
which_template
function. After realizing I tested[[ -z $template ]]
incheck_ext
only to again test[[ -n $template ]]
inwhich_template
I removed the latter. - Set
LC_ALL=C
andLANG=C
. In my testing, forcing ASCII in lieu of Unicode improved overall performance by ~8%. This improvement is perceivable when generating multiple files at once.
Moving forward:
- This is my first release labeled
stable
as I am now confidentgen
is consistent across common version of Linux, UNIX, and BSD. However, I will continue testing focused on improving portability and overall speed. - No features will be pushed/pulled that cannot pass
shellcheck
ANDset -o nounset
.
v1.5.6
This release contains several small bug fixes:
- Updated
which_ed
function to usewhich
to search$PATH
for installed editors. In practice, this should be both faster, and more portable. - Moved test for appropriate number of arguments to
check_args
function. This tests for a user inputting a valid option without a valid filename argument. - Corrected the regular expression used to validate user input for
create_multi
allowing for any positive integer to be input. - Standardized error reporting throughout. I'm now fairly confident error reporting, if not perfectly aligned with "best practices", is similar to common CLI tools.
- Removed instance of potentially unset variable from
check_ext
. - Clarified where parameter expansions were being used by removing superfluous curly braces.
- This is purely a style preference, and I may still use curly braces as delimiters where I think it improves readability.
Moving forward:
- Continues testing focused on improving portability.
- I'm working on an option to make the file permissions customizable (i.e.
gen -c 775 test.sh
orgen -c ug+x test.sh
) - No features will be pushed/pulled that cannot pass
shellcheck
ANDset -o nounset
.
v1.5.1
This release contains several small bug fixes and one major feature update as below:
Gen
now usesshift
within thegetopts
built-in function to assignfilename
withinget_args
using the positional argument$1
. In my testing, I found errors assigningfilename
dynamically to the last argument with a variety of methods. One portable solution I found was:for i in $@; do :; done
, however, I believe theshift
solution is more readable.- Added
-m
to generate multiple files at once. This feature mimics the behavior of brace expansions as in:touch test{1..3}.sh
to createtest1.sh
,test2.sh
, etc. I'm not completely happy with this as my goal was to allow brace expansions insidegen
( i.e.gen test{1..3}.sh
) so look for this feature to change/improve in the future. - Added
*sh
tocheck_ext
to catch several shell scripting languages (ksh, csh, zsh, etc).
Moving forward:
- I've added all the major features I had in mind when I started this project, so I will mostly be focused on improving portability.
- I will be still be welcoming new features/improvements ideas, so keep them coming!
- No features will be pushed/pulled that cannot pass
shellcheck
ANDset -o nounset
.
v1.4.0
The initial releases have been focused primarily on "proof of concept." However, this released was focused entirely on bug fixes. I tried to capture the many bug fixes below, but some may have been missed.
- Generate now passes
set -o nounset
testing in a variety of shell environments.- unset/unbound variables should be eliminated.
- Added
get_ext
function to further validate file extension.- function prevents an
ext
==filename
in the case of zero/multiple.
in filename.
- function prevents an
- Changed variable capitalization to differentiate between environmental variables.
- Added check preventing zero arguments passed to
gen
. - Clarified instances of
! -n
or! -z
with-z
or-n
respectively. - Reordered main function for improved logic and readability.
Big thanks to everyone who has helped!
Moving forward:
- Continued work on bug testing/compatibility testing.
- Reviewing error handling.
- Current error reporting similar to common CLI tools, however;
- The goal is to find the balance of terse specificity.
- Continue to identify unknown/unreported errors.
- No features will be pushed/pulled that cannot pass
shellcheck
ANDset -o nounset
.
v1.3.0
Several bug fixes with this release, clarified variable and function names throughout, and finished integration of custom templates.
- Added support for
.jsx
files - Fixed exit codes defaulting to
0
- Added explicit error messages for failure to touch and failure to launch editor
- Updated Makefile to include installation of
${HOME}/.gen/templates
directory"$TEMPLATE_FILE"
insidegen
now points here- This update allows
gen
to be updated without conflicts/overwriting custom templates
Thank you to @Ekatwikz and @greek-2me and the homies at [r/commandline] for getting me this far!
v1.2.1-beta
Initial Release
Let's get this out of the right at the start. I'm a Linux Sysadmin...not a software engineer. This project is a "learn-by-doing" experience. It started as something I was doing at work for a super specific use-case but evolved into something that might be helpful to others, so here we are.
Huge thanks to @tmiland, @greek-2me, and @fearlessgeekmedia for helping me get this far.
I will be more detail oriented for change logs going forward, this time I just want to get the ball rolling!