Li'l bash scripts
After coming across Modernizr’s compress bash script, I’ve been adding my own li’l bash scripts here and there in my projects. They help automate any repetitive task, or provide a shortcut for a bash command I don’t want to remember.
Development
Make a sweet bash script, like helloworld.sh
:
#!/bin/bash
echo 'Hello world!'
Make the script executable by changing the permissions:
$ chmod 755 helloworld.sh
Run the script from the command line
$ ./helloworld.sh
# > Hello World
Examples
metafizzy.co / newpost.sh and dropshado.ws / newpost.sh: creates a new post from a template
#!/bin/bash
# creates a new post
# format as _posts/YYYY/YYYY-MM-DD-filename.ext
# usage:
# $ ./newpost.sh my-new-post-filename
COPY_FILE=_posts/template.mdown
# create file
POST_FILE=_posts/$(date "+%Y/%Y-%m-%d")-$1.mdown
echo new post: $POST_FILE
cp $COPY_FILE $POST_FILE
# open it
mate $POST_FILE
demo / deploy.sh and desandro / deploy.sh: rsyncs project to remote server
#!/bin/bash
rsync -avz --exclude '.git' --exclude '*.sh' ./ $BERNA:~/www/demo
neo-vision / build.sh: moves release files into sub directory, compresses JS, zips it all up
#!/bin/bash
BUILD_DIR='neo-vision'
ZIP='neo-vision.zip'
REMOVABLES=("build.sh" "prettify.js" "lang-css.js" "README.mdown" $ZIP)
rm -rf $BUILD_DIR/
mkdir $BUILD_DIR
cp *.* $BUILD_DIR
# minifies prettify js
cat prettify.js lang-css.js | uglifyjs -nc > $BUILD_DIR/prettify.min.js
for REMOVE in "${REMOVABLES[@]}"
do
rm $BUILD_DIR/$REMOVE
done
zip -r -u $ZIP $BUILD_DIR