| 1 | package Psh::Builtins::Unalias; | ||
| 2 | |||
| 3 | require Psh::Util; | ||
| 4 | require Psh::Support::Alias; | ||
| 5 | |||
| 6 | =item * C<unalias NAME | -a | all]> | ||
| 7 | |||
| 8 | Removes the alias with name <C<I<NAME>> or all aliases if either <C<I<-a>> | ||
| 9 | (for bash compatibility) or <C<I<all>> is specified. | ||
| 10 | |||
| 11 | =cut | ||
| 12 | |||
| 13 | sub bi_unalias { | ||
| 14 | my $name= shift; | ||
| 15 | if( ($name eq '-a' || $name eq 'all') and !Psh::Support::Alias::is_aliased($name) ) { | ||
| 16 | %Psh::Support::Alias::aliases=(); | ||
| 17 | return (1,undef); | ||
| 18 | } elsif( Psh::Support::Alias::is_aliased($name)) { | ||
| 19 | delete($Psh::Support::Alias::aliases{$name}); | ||
| 20 | return (1,undef); | ||
| 21 | } else { | ||
| 22 | Psh::Util::print_error_i18n('unalias_noalias', $name); | ||
| 23 | return (0,undef); | ||
| 24 | } | ||
| 25 | return (0,undef); | ||
| 26 | } | ||
| 27 | |||
| 28 | |||
| 29 | sub cmpl_unalias { | ||
| 30 | my $text= shift; | ||
| 31 | return (1,grep { Psh::Util::starts_with($_,$text) } Psh::Support::Alias::get_alias_commands()); | ||
| 32 | } | ||
| 33 | |||
| 34 | 1; |