Ptouch: Difference between revisions

From Cheatsheet
Jump to navigation Jump to search
No edit summary
m 4 revisions
 
(One intermediate revision by one other user not shown)
Line 23: Line 23:
   wget -O ~/bin/ptouch http://henge.cavemantech.net/source/utilities/ptouch/ptouch
   wget -O ~/bin/ptouch http://henge.cavemantech.net/source/utilities/ptouch/ptouch
   chmod u+x ~/bin/ptouch
   chmod u+x ~/bin/ptouch
   echo "export PATH=$PATH:~/bin" >> ~/.bashrc
   echo 'export PATH=$PATH:~/bin' >> ~/.bashrc
 
 


== The code ==
== The code ==

Latest revision as of 23:51, 23 October 2014

What is ptouch?

"I am 12 and what is this?" Ptouch is basically an attempt at saving a few key strokes. The utility is designed to allow a programmer to begin work on an executable script. It will create a file, make it executable and add your interpreter specified at the command line. If you do not specify an interpreter, PERL is assumed by this


Usage

 ptouch code_file [interpreter]


Installation

You can do this in a couple of ways. If you would like the script to be installed for all users on a system do the following:

 wget -O /usr/local/bin/ptouch http://henge.cavemantech.net/source/utilities/ptouch/ptouch
 chmod 755 /usr/local/bin/ptouch

Alternatively, if you wish to install for only the currently logged in user:

 mkdir ~/bin
 wget -O ~/bin/ptouch http://henge.cavemantech.net/source/utilities/ptouch/ptouch
 chmod u+x ~/bin/ptouch
 echo 'export PATH=$PATH:~/bin' >> ~/.bashrc

The code

#!/bin/bash

#**************************#
# Name: ptouch             #
# Version: 1.1             #
# Author: Kevin M. Johsnon #
#**************************#

#-------------#--------------------------------------------#---------#
#  Change Log |                                            |         |
#-------------#--------------------------------------------#---------#
# Date        # Change Description                         | Version |
#-------------#--------------------------------------------#---------#
# 2011-05-21  | Original utility creation.                 |   1.0   |
#-------------#--------------------------------------------#---------#
# 2011-05-31  | Added support for second interpreter arg.  |   1.1   |
#-------------#--------------------------------------------#---------#

if [ -e $1 ]
then 
   echo "The file $1 already exists. Launching vim." ;
   sleep 2;
   vim $1;
   exit;
fi

if [ "$2" != "" ] 
then
interpreter=`which $2`;
else
interpreter=`which perl`;
fi

echo "#!$interpreter" > $1;
chmod u+x $1;
vim $1;