The main point of the script is to undo your last command. So many times have I mistyped a mv
command! With undo
, you can go back to the state you were previously:
$ ls
afile another_file many_files_here yet_another_file
$ mv afile bfile
$ # aw man, this was not what I wanted!
$ undo
$ ls
afile another_file many_files_here yet_another_file
Of course, undo
doesn't understand all the commands you can ever type. It ships with a few handlers for often-used commands which have a natural fit for being undone.
Namely, there are handlers for cp, mv, mkdir, push and popd.
If you have more commands that you often type and want to define how to undo it, all you have to do is define a function called command_undo
, changing command
for the actual command name.
Let's say you want to define that a touch
command can be undone by removing the touched file. All you have to do is:
$ touch_undo() {
> rm "$2"
}
$ ls
afile another_file many_files_here yet_another_file
$ touch test_file
$ undo
$ ls
afile another_file many_files_here yet_another_file
undo
is a shell function, and if you wish to use it, source
it in your shell initialization script.