Skip to content

Instantly share code, notes, and snippets.

@nagataka
Created August 5, 2013 19:57
Show Gist options
  • Save nagataka/6159029 to your computer and use it in GitHub Desktop.
Save nagataka/6159029 to your computer and use it in GitHub Desktop.
This is a script to automate writing shebang at the top of the file. You can add any extension to 'case' statement.
#!/bin/sh
#set this script as alias of editor like
#alias vim='/path/shebang.sh'
if [ "${1}" = "" ]; then
vim
fi
filename=${1}
if [ -e $filename ]; then
vim $filename
else
case $filename in
*\.rb) touch $filename
echo '#!'`which ruby` > $filename
vim $filename;;
*\.py) touch $filename
echo '#!'`which python` > $filename
vim $filename;;
*\.sh) touch $filename
echo '#!'`which sh` > $filename
vim $filename;;
*) vim $filename;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment