Here’s another little Bash function. It makes it possible to create a new script in one command, creating the file with shebang, making it executable, and opening it in your editor.
Just run newscript scriptname.rb to create a new ruby script with a /usr/bin/env ruby shebang. It also recognizes Python, Perl, and bash extensions, add more as needed.
You can also create a directory with “skeleton” scripts. If you have a list of includes that you always use in your shell scripts, add a ext.txt file to that directory (e.g. rb.txt or py.txt). By default that directory is ~/.newscript_defaults, but you can modify it in the config section. As an example, you might have a sh.txt file that sources a file of common functions you use in bash scripts, or an rb.txt file that includes contains # encoding: utf-8 to be appended after the shebang.
Just add this to ~/.bash_profile, or wherever you source your shell functions from. You’ll need to edit your script location in the scriptdir variable at the top.
Ryan Irelan has produced a series of shell trick videos based on BrettTerpstra.com posts. Readers can get 10% off using the coupon code TERPSTRA.