StephenJungels.com :: Open source :: Projects :: script-functions

These are two Bash functions I wrote to help turn my hacking around with the command line into full-fledged scripts. Although they have the same goal each function works slightly differently.

macro is intended for those times when you are planning ahead. To use it you type "macro record", then type in a series of commands you would like to turn into a script, and then type "macro save" (plus an optional file name). The series of commands will be saved into a file named "macrofile" (or the name you specified) and the executable bit will be set.

scriptify is useful when you have already carried out a series of actions in the shell and you decide you would like to turn them into a script. scriptify by itself saves the last line entered into a file named "scriptfile" and sets the executable bit. If you provide a file name argument the code is saved in that file. If you provide a single line number argument, that line from the command history is saved. If you provide two line numbers, they are taken as starting and ending lines in the command history. You can provide any combination of arguments, in any order, and the function will figure out what you mean.

To use these functions, save the script in your ~/bin directory and source it in your .bash_profile.

Download