Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / Psh / Builtins / Alias.pm
CommitLineData
86530b38
AT
1package Psh::Builtins::Alias;
2
3require Psh::Support::Alias;
4require Psh::Util;
5require Psh::Parser;
6
7=item * C<alias [NAME [=] REPLACEMENT]>
8
9Add C<I<NAME>> as a built-in so that NAME <REST_OF_LINE> will execute
10exactly as if REPLACEMENT <REST_OF_LINE> had been entered. For
11example, one can execute C<alias ls ls -F> to always supply the B<-F>
12option to "ls". Note the built-in is defined to avoid recursion
13here.
14
15With no arguments, prints out a list of the current aliases.
16With only the C<I<NAME>> argument, prints out a definition of the
17alias with that name.
18
19=cut
20
21sub bi_alias
22{
23 my $line = shift;
24 my @words= @{shift()};
25 my ($command, $firstDelim, @rest) = Psh::Parser::decompose('([ \t\n=]+)', $line, undef, 0);
26 my $text = join('',@rest); # reconstruct everything after the
27 # first delimiter, sans quotes
28 if (($command eq "") && ($text eq "")) {
29 my $wereThereSome = 0;
30 for $command (sort keys %Psh::Support::Alias::aliases) {
31 my $aliasrhs = $Psh::Support::Alias::aliases{$command};
32 $aliasrhs =~ s/\'/\\\'/g;
33 Psh::Util::print_out("alias $command='$aliasrhs'\n");
34 $wereThereSome = 1;
35 }
36 if (!$wereThereSome) {
37 Psh::Util::print_out_i18n('bi_alias_none');
38 }
39 } elsif( $text eq '') {
40 my $aliasrhs = $Psh::Support::Alias::aliases{$command};
41 $aliasrhs =~ s/\'/\\\'/g;
42 Psh::Util::print_out("alias $command='$aliasrhs'\n");
43 } elsif ($text eq '-a') {
44 Psh::Util::print_error_i18n('bi_alias_cant_a');
45 return (0,undef);
46 } else {
47 $Psh::Support::Alias::aliases{$command} = Psh::Parser::unquote($text);
48 }
49 return (1,undef);
50}
51
52
531;