I have updated N.S.F. - New Script File to version 2.60 which now adds an option to add a GPL statement to your script file. If you like to share your scripts with others, you may want to think about including a GPL statement. It makes it clear that there is no warranty included with your script even as anyone is free to use and modify your script as they so desire. You still maintain a copyright on your original work, should that be required for something in the future.
NSF (New Script File) version 2.6 has the following features …
-
NSF assists you in creating a new and or editing an existing bash script file.
-
NSF uses a GUI question and answer window in your desktop for the file name, no need to open up a terminal session.
-
NSF asks for the name of the script file you wish to create, but if it already exists, you can just edit the existing file.
-
Existing bash script files will have a backup file made for you, just in case you need it.
-
Your new script file will receive a header and footer, which you can modify in NSF.
-
Your new script file will be marked Executable for you.
-
As you save your bash script file, you do not need to close the editor. Just open a Terminal session, type the script file name and see if it works.
-
Auto Detection of zenity and kdialog made for you which you can override.
-
Allows the addition of a GPL statement to make clear the use of your script should it be released to the public.
-
Here is the Script File GUI Name Request:
http://thumbnails12.imagebam.com/14047/88f2b6140464202.jpg](http://www.imagebam.com/image/88f2b6140464202)
- Here is the GPL GUI statement inclusion request:
http://thumbnails30.imagebam.com/14047/5860f5140464198.jpg](http://www.imagebam.com/image/5860f5140464198)
- Should the script file already exist, here is the GUI request to edit anyway:
http://thumbnails44.imagebam.com/14047/de1cdf140464201.jpg](http://www.imagebam.com/image/de1cdf140464201)
To create nsf, copy and past the text in the following code block into your favorite text editor and save the file as nsf in your home area bin folder (~/bin/nsf).
#!/bin/bash
#: Title : nsf - New Script File creator
#: Date Created: Thu Sep 2 12:19:58 CDT 2010
#: Last Edit : Wed Jul 13 17:08:58 CDT 2011
#: Author : J. McDaniel < jmcdaniel3@austin.rr.com
#: Version : 2.60
#: Description : Create a new script file with blank header in your ~/bin folder
#: Options : Name of new script file $1, now optional
#
# Created for openSUSE forums on Wednesday July 13, 2011
#
TITLE="N.F.S. - New Script File creator - Version 2.60"
#
# Copy and Paste the text of this script into a text editor and save
# it as the file nsf in the /home area bin folder
# example is: /home/username/bin, also known as ~/bin
# This script must be marked executable to be used. Please
# run the following Terminal command: chmod +x ~/bin/nsf
# nfs was designed to be run from inside your desktop.
#
#
# Place Your Name Here as the script file author
#
AUTHOR="You Name Here"
#
# Place Your Email Address Here
#
email="your.email@address.com"
#
# Place the name of your favorite Script Editor here
#
EDITOR="kwrite"
#
# Location For Your Script Files to be saved
#
FOLDER=~/bin
#
# Determine if you want a backup file made for existing scripts.
# Just set to false if you do not want this backup file made.
#
BACKUP=true
#
# The GPL Statement
#
function show_gpl {
echo
echo "-----------------------------------------------------------------------"
echo "NSF (New Script File) is written to create a script in openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo "-----------------------------------------------------------------------"
echo
}
#
# The Help which is Displayed
#
function help {
tput clear
cat << EOFHELP
$TITLE
Your NSF Startup and help options are:
$(basename $0) -h --help :to show this help
OR
$(basename $0) [script.file]
The name script.file is optional and will be requested if not supplied. If the
script file already exists, you will be asked if you wish to edit this file.
EOFHELP
show_gpl
exit 0
}
#
# Display Help if requested.
#
case "$1" in
-h|--help) help ;;
esac
#
# Lets Determine if first zenity (default) or if kdialog is present
#
which zenity
rc1=$?
if "${rc1}" == "0" ]; then
Desktop="GNOME"
else
which kdialog
rc2=$?
if "${rc2}" == "0" ]; then
Desktop="KDE"
else
echo "I did not find either program zenity or kdialog as being present!"
exit 1
fi
fi
#
# You may force the use of kdialog if you wish
#
# Desktop="KDE"
#
# Check for File Name & Ask for one if not present
#
if $# -eq 0 ] ; then
if $Desktop == "GNOME" ] ; then
FNAME=$(zenity --title "$TITLE" --entry --text "Please enter the file name for your new (or existing) bash script file:")
rc=$?
else
FNAME=$(kdialog --title "$TITLE" --inputbox "Please enter the file name for your new (or existing) bash script file:")
rc=$?
fi
if "${rc}" != "0" ]; then
exit 1
fi
TARGET=$FOLDER"/"$FNAME
else
TARGET=$FOLDER"/"$1
fi
#
# Check for Existance of New File, Ask to just edit existing file
#
if -e $TARGET ] ; then
if $Desktop == "GNOME" ] ; then
zenity --title "The Script File <$(basename $TARGET)> Already Exists!" --question --text "Do you really wish to Edit this Existing Bash Script File?"
rc=$?
else
kdialog --title "The Script File <$(basename $TARGET)> Already Exists!" --yesnocancel "Do you really wish to Edit this Existing Bash Script File?"
rc=$?
fi
if "${rc}" == "0" ]; then
if "$BACKUP" == "true" ] ; then
#
# Create File Extension for Backup File
#
ext=$(date +%y%m%d.%H%M%S)
BACK=$TARGET.$ext
#
# Make a Backup Copy of the File Before the File is edited
#
cp $TARGET "$BACK"
chmod -x "$BACK"
fi
$EDITOR $TARGET
exit 0
else
exit 1
fi
fi
#
# When we get to here, we are creating an all new bash script file
#
echo "#!/bin/bash" > $TARGET
echo "" >> $TARGET
echo "#: Title : "$(basename $TARGET) >> $TARGET
echo "#: Date Created: "$( date ) >> $TARGET
echo "#: Last Edit : "$( date ) >> $TARGET
echo "#: Author : "$AUTHOR >> $TARGET
echo "#: Version : 1.00" >> $TARGET
echo "#: Description : " >> $TARGET
echo "#: Options : " >> $TARGET
if $Desktop == "GNOME" ] ; then
zenity --title "GPL Function Statement Request?" --question --text "Do you wish to include a GPL Statement in your script?"
rc=$?
else
kdialog --title "GPL Function Statement Request?" --yesnocancel "Do you wish to include a GPL Statement in your script?"
rc=$?
fi
if "${rc}" == "0" ]; then
#
# Place GPL Statement into new script file
#
echo "" >> $TARGET
strng='#' && echo $strng >> $TARGET
strng='# This is the standard GPL Statement, leave at the top of the script.' && echo $strng >> $TARGET
strng='# Just use the command show_gpl after this function for it to be shown.' && echo $strng >> $TARGET
strng='#' && echo $strng >> $TARGET
echo "" >> $TARGET
strng='function show_gpl { ' && echo $strng >> $TARGET
strng='echo ""' && echo $strng >> $TARGET
strng='echo "'$(basename $TARGET)' is a bash script file written to be used with openSUSE."' && echo $strng >> $TARGET
strng='echo "Copyright (C) 2011 by '$AUTHOR', '$email'"' && echo $strng >> $TARGET
strng='echo ""' && echo $strng >> $TARGET
strng='echo "This program is free software; you can redistribute it and/or modify"' && echo $strng >> $TARGET
strng='echo "it under the terms of the GNU General Public License as published by"' && echo $strng >> $TARGET
strng='echo "the Free Software Foundation; either version 2 of the License, or"' && echo $strng >> $TARGET
strng='echo "(at your option) any later version."' && echo $strng >> $TARGET
strng='echo ""' && echo $strng >> $TARGET
strng='echo "This program is distributed in the hope that it will be useful,"' && echo $strng >> $TARGET
strng='echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"' && echo $strng >> $TARGET
strng='echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"' && echo $strng >> $TARGET
strng='echo "GNU General Public License for more details."' && echo $strng >> $TARGET
strng='echo ""' && echo $strng >> $TARGET
strng='echo "You should have received a copy of the GNU General Public License"' && echo $strng >> $TARGET
strng='echo "along with this program; if not, write to the Free Software"' && echo $strng >> $TARGET
strng='echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"' && echo $strng >> $TARGET
strng='echo ""'&& echo $strng >> $TARGET
strng='}' && echo $strng >> $TARGET
fi
echo "" >> $TARGET
echo "" >> $TARGET
echo "" >> $TARGET
echo "exit 0" >> $TARGET
echo "" >> $TARGET
echo "# End Of Script" >> $TARGET
chmod +x $TARGET
# Your script editor name goes here
$EDITOR $TARGET
exit 0
# End Of Script
Once saved, open up a terminal session and run the following command:
chmod +x ~/bin/nsf
In the script, there are three lines you need to edit. The first is your name as the script file author. Next is your email address for the GPL statement and finally the name of the text editor you wist to use. Modify the script lines that say:
AUTHOR="You Name Here"
email="your.email@address.com"
EDITOR="kwrite"
You can create a shortcut on your desktop using the following text. Copy and past this into a text editor and save it as the file nsf.desktop in your /home/username/Desktop folder (~/Desktop/nsf.desktop):
[Desktop Entry]
Comment[en_US]=
Comment=
Exec=~/bin/nsf
GenericName[en_US]=New Script File
GenericName=New Script File
Icon=yast-scripts
MimeType=
Name[en_US]=NSF
Name=NSF
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=
X-SuSE-translate=true
You must open a terminal session and mark the shortcut executable with the following terminal command.
chmod +x ~/Desktop/nsf.desktop
Running the nsf.desktop icon from your desktop would create an executable script file called myscript (in this example) and once kwrite opens it up, you would see something like the following information which you can then edit as your new script:
#!/bin/bash
#: Title : myscript
#: Date Created: Wed Jul 13 17:54:21 CDT 2011
#: Last Edit : Wed Jul 13 17:54:21 CDT 2011
#: Author : Your Name Here
#: Version : 1.00
#: Description :
#: Options :
#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#
function show_gpl {
echo ""
echo "myscript is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by Your Name Here, your.email@address.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}
exit 0
# End Of Script
As always, I would love to hear any comments you have about using the script file creator script.
Thank You,