Is there such a program for Terminal like the iMacros plugin for Firefox, that can record what I did, then automatic do the work I have done? I hope that there is such a program to help me do the repeat work in the terminal, so any tips?
This question came from our site for professional and enthusiast programmers.
Google finds this. Is it what you are after?
If I were to automate human-to-TTY interaction I would rather do it using Expect.
Functions are easy
A few days ago, I defined a function
It can be invoked like
This is great to quickly group a number of commands together inside your current session. You can place the function at the end of your
Scripts are quite powerful
Scripts execute in their own process. This means that any variables you assign are local to this process. To write a script, place a shebang at the top. It consists of the characters
In a shell script, you could then do stuff like
Don't forget to make the script executable via
It can then be executed like
The bash syntax contains conditionals and loops and switches and almost anything. If you loathe the low performance or if you need nicer syntax, you can easily teach yourself a few lines of Perl or Python.
Seeing what you typed
These solutions depend on knowing what you want to do before you do it. If this is not the case, you can look at the history file (
lists the 5 last commands, with a running number. In my case, this gives
You can easily use this command list to write a function or a shell script.
A quick homebrew solution
Here is a solution for macro recording. It uses two user-defined functions, and an inline perl script to do the interesting processing.
Creates following output:
You can then easily copy-and-paste that into a new script.
Note: I don't have a Mac and tested this on Ubuntu. Paths may differ, but the concepts are sound.
It's unlikely to interest you if you're not a user, but emacs has a shell mode (
But more broadly I agree with bobah -- you don't state the problem you're trying to solve, but it's almost certainly something better suited to tools like expect than raw input forgery...
I know you're asking this for Terminal, but since I have not heard about such a program, an alternative would the ZOC Terminal. It is commercial so it may not be up your alley, but it is the closest thing I can think of, given your problem description. It does support using a local shell on Mac OS (essentially a replacement for terminal) and it has a script recording feature (Script-menu -> Record Scipt). You can also map these scripts (or shorter texts) on buttons and key combinations.