Aliases


What is an alias?

An alias is a way to create complex or new commands.
Let's say that you often use the following sequence of commands to recognize an user:
/WHOIS Nickname
/CTCP PING Nickname
/CTCP VERSION Nickname
/CTCP FINGER Nickname
It may be annoying to type all these commands each time.
So you can create an alias that does everything by typing just '/BIGINFO Nickname'.
Open the aliases dialog and add an alias called BIGINFO.
Just place the following code in the body of the alias:
/<
    whois $1;
    ctcp PING $1;
    ctcp VERSION $1;
    ctcp FINGER $1;
    echo $_window Sent BIGINFO request for $1. Waiting for reply...;
>
The $1 variable will be evaluated to the first parameter that you pass to the alias.
So typing /BIGINFO Pragma , $1 will evaluate to 'Pragma'.

Another example

Another classic example:
Alias 'P':
    /part $0;
This is a simple part shortcut.
$0 will evaluate to ALL parameters passed , so you can write:
/P #kaos Bye to all!; And $0 will evaluate to '#kaos Bye to all!'.
If there was $1 , it would be evaluated to '#kaos' only, and the other words ignored.
Another way to do it could be:
Alias 'P':
    /part $1 $2-;
$1 will evaluate to '#kaos' and $2- to all the words following the first : 'Bye to all!'.
In this way you have a problem: if no second word is specified in the alias call,
$2- will be evaluated to an empty string that IF treates as false.
You can prevent it in the following way:
Alias 'P':
/<
    if ($2)part $1 $2-;
    else part $1 Bye to all!
>
In this way ,if you don't specify a part message (starting from the second parameter) ,
a default one will be used.

Notes

*
The '$0','$1',...'$9' variables are LOCAL variables , you can SET and UNSET it , but you will never see the changes outside of the current alias.

*
You can call other aliases from an alias , and if you want you can use it recursively , but there is no infinite-recursion check as in mIrc , so you MUST exit from the recursion sooner or later.
An infinite recursion loop WILL hang kvirc!.

*
A command is terminated either by a ';' or a newline.
The correct syntax requires to start an alias with a '/' and include it into a block of commands.
However ,from this version , the block become optional,and you can write the alias text just like it were typed in a channel window : only the leading '/' is needed.
So these three versions of the 'HOP' alias are valid:
/<
    set $last.chan $_chan; part $last.chan; join $last.chan; unset $last.chan
>

is equivalent to
/set $last.chan $_chan
part $last.chan
join $last.chan
unset $last.chan

is equivalent to
/<
    set $last.chan $_chan;
    part $last.chan;
    join $last.chan; unset $last.chan;
>

*
An alias is always bound to the window that is executed in.
If it is executed from anoter alias or event , it gets the window of the calling command.
So every call to $_window , $_chan or $_target will return that window/channel/target name.

*
$0 is NOT equivalent to $1-:
    $0 will return you the list of parameters
    passed EXACTLY as you typed it in (for example with many spaces),
    $1- will return the same list but withall words separated by only one space.
In the following alias call:
/MYALIAS 1 2 3         4;
$0 will evaluate to:
1 2 3         4
and $1- will evaluate to:
1 2 3 4

*
$0- will give you all the parameters repeated twice!.

*
The aliases are parsed sequentially at runtime and executed WHILE parsing it.
There is no previous syntax check or tree-building.
The execution stops at the first error encountered in the parsed command sequence.
It may happen that an alias contain a syntax error in an if conditional subtree , and that is never executed . In that case you will never see that error!
Example: This will execute correctly.
if ($_false)< stupid_command_parser blahblahblahblah > ; else echo $_window OK, it is false!.


Index