Skip to content

Commit

Permalink
Add readme and initial scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Dec 2, 2009
0 parents commit d262a6d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.mdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Shell Scripts
=============
This repository contains of a collection of simple and small, but very useful
shell scripts that I often use personally.

* base64decode: decode BASE64 strings received from stdin.
* base64encode: encode plain strings into BASE64 from stdin.
* git-can-ff: determines if the current branch can fast-forward (ff) to its
remote counterpart.
* quote: quotes each line from stdin to stdout. Very useful when piping
filenames with spaces into xargs.
* sedfiles.sh: batch change file names using a sed expression.
2 changes: 2 additions & 0 deletions base64decode
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/php
<?php print base64_decode(file_get_contents('php://stdin')) ?>
2 changes: 2 additions & 0 deletions base64encode
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/php
<?php print base64_encode(file_get_contents('php://stdin')) ?>
21 changes: 21 additions & 0 deletions git-can-ff
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
usage() {
echo "usage: $(basename $0) <from-ref> <to-ref>" >&2
exit 2
}

[ $# -ne 2 ] && usage

FROM_REF=$1
TO_REF=$2

FROM_HASH=$(git show-ref --hash $FROM_REF)
TO_HASH=$(git show-ref --hash $FROM_REF)
BASE_HASH=$(git merge-base $FROM_REF $TO_REF)

if [ "$BASE_HASH" = "$FROM_HASH" -o \
"$BASE_HASH" = "$FROM_REF" ]; then
exit 0
else
exit 1
fi
2 changes: 2 additions & 0 deletions quote
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
sed -E 's/^(.*)$/"&"/g'
36 changes: 36 additions & 0 deletions sedfiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

if test -z "$*"; then
echo "No files to parse"
exit
fi

SEARCH="contextStackSize"
REPLACE="actualStackSize"

echo "Searching for $SEARCH"
echo "Replacing with $REPLACE"

for afile in $*; do
DATA=`grep "$SEARCH" $afile`

if test -n "$DATA"; then

echo "Processing $afile ..."

rm -f $afile.backup
rm -f $afile.backup2

cp $afile $afile.backup

COMMAND="s/$SEARCH/$REPLACE/g"
echo "`cat $afile.backup | sed -e $COMMAND`" > $afile

if grep "$SEARCH" $afile; then
echo "Ops.. maybe it didn't work..."
else
echo "Ok, it worked."
fi
fi

done

0 comments on commit d262a6d

Please sign in to comment.