Design a site like this with
Get started

Workon Stuff – A Simple Script

This is a simple script I wrote to quickly open a new file from the command line prompt. I have workon as an alias in my shell profile, and I use this any time I want to test a snippet or start a new script, but it can also be used to generate Word documents or Excel files.

#set -x

#Check for an empty argument
if [ "${1}" = '' ]; then
	echo "Provide a file name to create or open a file."
	exit 1

#Check if the file already exists
if [ -e "${1}" ]; then
	open "${1}"
	exit 0

#Create the file
touch "${1}"

#Check for executable file extensions.
if [[ "${1}" == *".sh" ]] || [[ "${1}" == *."py" ]] ; then
	chmod +x "${1}"

if [[ "${1}" == *".sh" ]]; then
cat >> "${1}" << SCRIPTGOESHERE
set -x 


open "${1}"

exit 0

What Does This Do?

This script will create a new empty file and open it in the default application for the file type. If the file already exists, it just opens it.

If the file type is .sh, then the #!/bin/zsh line and set -x are automatically added. The file is also set to be executable.


  • This script doesn’t create folders. This could be added easily enough.
  • The script doesn’t error check itself

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s