Introduction to Macros

One of the first ways to make TeSSH do more than just a dumb TELNET client is to assign commands to keys on your keyboard.

To assign a command to a key, press Control-K, or select Define Key from the Action menu. You will be prompted to press the key combination that you wish to assign a command to. Almost any key on the keyboard can be assigned a command, in combination with the Shift, ALT, and Ctrl keys. If you assign the macro to a key already used by TeSSH (like Ctrl-C for Copy), then your macro will override the TeSSH command, so be careful about this. You can control whether your macros override Windows commands (like Alt-F) in your Command Line Preferences. Also, note that TeSSH automatically activates the NUMLOCK mode to allow you to assign macros to the keypad. If NUMLOCK is off, the keypad functions as the cursor keys. Since the cursor keys are used to edit the command buffer and recall from the command history, you should refrain from assigning macros to the arrow keys (although you can if you want).

Once you press the key you want to assign a command to (for example, the NUM8 key, the 8 key on the keypad) you will be prompted for the command. Enter the text you wish to be sent to the server when you press this key. For example, if you were assigning a command to the NUM8 key, you could enter the text ls. Now, when you press the NUM8 key, the text ls is sent to the server. Notice that when you press a macro key the text in the command entry field is selected, but is otherwise undisturbed. This allows you to repeat the same command over and over again easily.

For details on editing Macro properties in the Package Editor, go to the Editing Macros topic.

Macro Chaining

If you want the text assigned to the macro key to be placed into the command line instead of being sent to the server, turn off the "Send to server" option in the Macro editor screen. To append the text of the macro key to the current contents of the command line, turn on the "Append to Command Line" option. Text will only be appended if the command line is not fully highlighted.

If you turn on the Daisy Chain option, then this macro can be used after other macro keys for a special effect called "Macro Chaining". When Daisy Chain is enabled, the macro text is appended to the command line if the command line ends in a space character. Then the whole command line is sent to the server. Otherwise, if the command line doesn't end in a space, the macro command is sent to the server normally.

The best way to understand how macro chaining works is to look at an example:

Define a macro key with the string "git " and turn off the "Send to server" option, but turn on the "Append" option. If you assigned this to the F8 key, then pressing F8 would put the text "git " in the command line (without sending it to the server).

Next, define a macro with a command of "commit" and turn on the Daisy Chain option. Assign this macro to the F9 key on the keypad.  Now, when you press F8, the text "git" is placed in the command line. Now when you press F9, the command "commit" is appended to the command line (since it ends with a space) and the command "git commit" is sent to the server. However, if you just press NUM8 by itself with nothing on the command line, then the command "commit" is just sent to the server.

Add comment

Login or register to post comments