Introduction to Aliases

Aliases are another way to simplify your life of server playing. Basically, aliases allow you to assign any command to a shortcut abbreviation.

The easiest way to create an alias is to type the command or words you want to make a shortcut for, then press Control-A, or select Make Alias from the Action menu. You will be prompted for the shortcut abbreviation you wish to assign the command to. For example, enter the text ls -al and press Control-A. Then enter lss and click Save changes and then close the editor window (or just press Enter to save and close the window). Now, whenever you enter lss in the command buffer, the string ls -al will be sent to the server.

Note that aliases are only translated if they are the first word in a command. In the example described above, if you entered the text say lss on the command line, the string say lss is sent to the server and lss is not translated.

Aliases Settings Editor

Settings editorYou can edit all of your aliases using the View/Aliases menu command, or by clicking the Aliases button in the main toolbar. This brings up the Package Editor in the alias edit mode. All of your aliases (like lss from the above example) are displayed in the list on the left. To edit an alias, just click on it and the details will be shown on the right side of the window. To define a new alias, click the New button and enter the name and commands for the alias. You can copy an alias by selecting it and using the Copy command in the Edit menu (or the right-click popup menu). Then select Paste from the Edit menu to make a copy. Multiple items can be copy and pasted. To delete an alias, select it and use the Delete command in the Edit menu (or the right-click menu).

This is an example of using the TeSSH Package Editor. It has a list of your settings, just like Windows Explorer shows a list of your files and directories. The buttons on the filter toolbar on the left edge of the window allow you to select what kinds of settings you wish to view. For example, to view Aliases, click the Alias button. To view Triggers, click the Trigger button. To view more than one item at a time, hold down the Shift or Ctrl key as you click the button. You can also click the All button to display all settings.

The Package Editor is used to edit all kinds of things in TeSSH, not just Aliases. To learn more, go to the Package Editor help topic. See the Editing Aliases topic for more information on the specific editor fields and options.

The ALIAS command

Another way to define an alias is using the #ALIAS command. Commands are typed entirely in the command input line at the bottom of the screen, but perform an action within TeSSH and normally don't send any text to the server. Commands are provided for users of text-based server clients like TINTIN, and are similar in syntax. To create an alias with the ALIAS command, type

#ALIAS shortcut {command text}

The command text will then be assigned to the shortcut abbreviation that you supply. You can also list all aliases by just entering #ALIAS, or you can list the definition of a single alias using #ALIAS shortcut.

Aliases can also contain Arguments (also sometimes called Parameters). Arguments are the text following the shortcut. For example, if you enter fs foo bar, fs is the alias shortcut, foo is the first argument, bar is the second argument. Arguments are assigned to special numeric functions %1 through %99. In the previous case, %1 would contain foo, and %2 would contain bar. You can use these arguments in the alias itself.

For example, define the alias

#ALIAS c {cd %1;ls}

Now when you enter c .., the commands cd .. and ls are sent to the server.

Instead of using the cryptic %1 notation, you can use "named arguments" in TeSSH. To rewrite the above example using the argument name of "target" instead of %1, you would type:

#ALIAS c($path) {cd $path;ls}

The $ in front of the argument name indicates that this is really a Local Variable reference. Don't worry about that now. Just keep in mind that whenever you use a named argument, you always put a $ before the name.

Sometimes you might now know how many arguments are sent to the alias. Perhaps you want to send all of the text after the alias to the server. You can use the special syntax %-1 to send all arguments starting with the first (or %-2 to send all arguments starting with the second, etc). For example:

#ALIAS gc {git commit -m %-1}

If you enter gc daily update then it will send git commit -m daily update to the server. Instead of %-1, you can use the %params function if you'd like.

Strings, Quotes and Special Characters

The above example doesn't actually work because the git command requires " quotes around the -m argument.  How do you add " quotes to the alias command output?  If you just put " quotes around %-1, the TeSSH just treats "%-1" as a literal string and would just send "%-1" directly to the server.

To "escape" a character to prevent it from being parsed by TeSSH, preceed it with the ~ escape character.  To send a " quote directly to the server, you would use ~".  So the correct version of the above alias would actually be this:

#ALIAS gc {git commit -m ~"%-1~"}

If you enter gc daily update then it will send git commit -m "daily update" to the server

Using the same alias name as a server word

What do you think would happen if we created an alias like this:

#ALIAS ls {ls %1}

This actually causes an infinite alias loop! When you enter ls -al on the command line, it calls the "ls" alias, which then sends the "ls -al" command again and again and again.

To force TeSSH to send a word to the server without running it as an alias, place the "escape" character ~ in front of the word. For example, the CORRECT EXAMPLE is this:

#ALIAS ls {~ls %1}

This will send the "ls -al" text to the server without the infinite loop.

Add comment

Login or register to post comments