Bash Scripts I Use With Github

I’ve recently decided that I should put some of my projects on GitHub.

I use two bash scripts to ease my communication with my repo.


cd [path to local repo]git add .
git status
git commit
git push origin HEAD:master
git diff HEAD~1 HEAD > ~/Desktop/diff.txt

. filename

git rm $file
git commit -m "remove $file"

Todo system

I used to drown in a sea of post-it notes and repetitive todo lists, my thoughts spread across unorganized Dropbox files, repetitive Evernote entries and various iPhone apps (Checklist, Notes, GoogleTasks).

Now that I am more comfortable with vim and bash scripting than I am with bulky GUI apps, I decided to code myself a thought management system. While researching I came across this beauty, Todo.txt, and have converted my ad-hoc method of todo lists and thought recording into an organized system.

So far, I’ve broken it up into three plain text files:

  • todo.txt – mandatory actions, one liners (with abundant project names for sorting)
  • Ideas.txt – ideas and notes on said ideas
  • myday.txt – journal entries & freewriting, partitioned by day
  • This system is amazing. Very efficient, and perfect for cross-platform work on Dropbox.

    add - add simple task to todo.txt
            t add “task”
    + - associate a task with a project by including the project name with a + sign
            t add “task +Project”
    @ - note context
            t add “task @Work”
    list - see all tasks in todo.txt
            t ls
    show only the tasks related to Project
            t ls +Project
    show tasks with keyword
            t ls keyword
    pri - prioritize a task (depri)
            t pri number priority
    do - mark task complete
            t do <line of task completed>

Perl Basics

Before today, the most Perl I’d written/read was dinky one-liners.

Today, I worked with an advanced Perl script. Below are the notes I took this morning while I quickly learned the language.

scalar variable, either a number or string;

array. Perl uses the “at” symbol and parentheses with respect to the name of an array as a whole, whereas individual elements within an array are referred to as scalars and the index is placed in square brackets ($name[0])

associative array ; 2-dimensional array for handling attribute/value pairs. 1st element in each row = key, 2nd eelemt in each row = value.

Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down.

Arrow Operator ( -> ): Infix dereference operator

Left Side    :           Right Side        :        Ex
array [...]           array subscript          $aref->[42]
hash {...}            hash subscript           $href->{"corned beef"}
subroutine (...)      subroutine args list     $sref->(1,2,3)
object                Method Name              $yogi = Bear->new("Yogi"); #a class method call
object                Class Name               $yogi->swipe($picnic);  #an object method call


my @names = (‘Kernighan’, ‘Ritchie’, ‘Pike’);

is equivalent to

my @names = qw(Kernighan Ritchie Pike);

creates and scopes variable;
example: print statement outside of loop will print nothing

for (1..5) {
my $variable = “hellon”
print $variable;
print $variable;
chop() # remove last character in string index
. # concatenate
x # n repetition - e.g., “A” x 3 => “AAA”
eq # equal
ne # not equal
lt # less than
gt # greater than
le # less than or equal to
ge # greater than or equal to

($string, $substring) # position of substring in string, zero-based; -1 if not found
index ($string, $substring, $skip) # skip number of chars
substr($string, $start, $length) # substring
substr($string, -$start, $length) # defined from end
substr($string, $start) # rest of string

keys (%aAA) # list of keys for %aAA
values(%aAA) # list of values for %aAA
each (%aAA) # next key/value pair, as list
delete $aAA{“A”}; # deletes key/value pair referenced

subroutine example (sub = def in Python):

use strict;
sub HowdyEveryone {
my($greeting, @names) = @_;
my $returnString;
foreach my $name (@names) {
$returnString .= "$greeting, $name!n";
return $returnString .
"Where do you want to go with Perl today?n";
print &HowdyEveryone("Howdy", "bart", "lisa", "homer", "marge", "maggie");

while: example:

while (<INPUT>) {
# read one line at a time until EOF
chop; # remove newline
print line = $_ n”; # print line read using default scalar variable
until (expression) { #while not}


for (initial exp; text exp; increment exp) { # e.g.,  ($i=1; $i<5; $i++) }


foreach $i (@List) { }


while (expression) {
#last jumps here

(If last occurs within nested control structures, the jump can be made to the end of an outer loop by adding a label to that loop and specifying the label in the last statement.)

LABEL1: while (expression) {
LABEL2: while (expression) {
last ALABEL;
#last jumps here
while (expression) {
#next jumps here

# (see last for LABEL example)


while (expression) {
#redo jumps here

# (see last for LABEL example)

$a = <STDIN>;# returns next line in file
@a = <STDIN>; # returns entire file


1) Used to contain a block of code:

if ($word =~ m/^[$vowels].*$suffix$/io) {
$stem = substr($word, 0, - length($suffix));

2) Used to index hash arrays:

my %english;
$english{$key} = $stem;
print “$word ($latin{$english{$key}})n” if (exists($english{$key}));

3) Like in other Unix shell languages, used to delimit variable names when they are adjacent to other letters and symbols:

my $vowels = ‘aeiou’;
$key =~ s/^(.*)([^${vowels}y])$/$2$1/

Where we don’t want the variable $vowelsy but rather $vowels and ‘y’

4) In pattern matching, indicate the general form of quantifier:

m/d{5,10}/ # match at least 5 digits but no more than 10

Also used (along with parenthesis and other syntax pairs) to delimit an explicit pattern in place of slashes:

if ( $x =~ m{[yY]es} ) { … }

5) Dereference a pointer that is the last item in a block:

$scaler = ${$scalerref}
push(@{$j++; $arrayref}, $token);

6) Used to delimit an anonymous hash reference:

$hashref = {Apple => ‘Red’, Grape => ‘Purple’, Banana => ‘Yellow’}

The above initializes a hash pointer, to initialize a hash array, we use parentheses:

%hash = ( Apple => ‘Red’, Grape => ‘Purple’, Banana => ‘Yellow’ )

7) Used to subscript typeglobs

$ref = *a{SCALER};
$ioref = *DIRH{IO}