| 1 | package Psh::Builtins::Option; | ||
| 2 | |||
| 3 | require Psh; | ||
| 4 | require Psh::Options; | ||
| 5 | |||
| 6 | =item * C<option[s]> | ||
| 7 | |||
| 8 | Lists the current configuration options | ||
| 9 | |||
| 10 | =item * C<option +NAME> | ||
| 11 | |||
| 12 | Activates an option | ||
| 13 | |||
| 14 | =item * C<option -NAME> | ||
| 15 | |||
| 16 | Deactivates an option | ||
| 17 | |||
| 18 | =item * C<option NAME=VALUE> | ||
| 19 | |||
| 20 | Sets an options | ||
| 21 | |||
| 22 | =item * C<option NAME> | ||
| 23 | |||
| 24 | Prints the value of an option | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | |||
| 29 | sub bi_option { | ||
| 30 | my $line= shift; | ||
| 31 | my @words= @{shift()}; | ||
| 32 | if (!@words) { | ||
| 33 | my @opts= Psh::Options::list_options(); | ||
| 34 | @opts= sort @opts; | ||
| 35 | foreach my $opt (@opts) { | ||
| 36 | my $val= Psh::Options::get_printable_option($opt); | ||
| 37 | Psh::Util::print_out("$opt=$val\n"); | ||
| 38 | } | ||
| 39 | } else { | ||
| 40 | while (my $tmp= shift @words) { | ||
| 41 | if (substr($tmp,0,1) eq '-') { | ||
| 42 | Psh::Options::del_option(substr($tmp,1)); | ||
| 43 | } elsif (substr($tmp,0,1) eq '+') { | ||
| 44 | Psh::Options::set_option(substr($tmp,1),1); | ||
| 45 | } elsif ($tmp=~/=/) { | ||
| 46 | my ($key,$val)= $tmp=~ /^(.*?)=(.*)$/; | ||
| 47 | |||
| 48 | if (!$val or $val eq 'sub') { | ||
| 49 | $val||=''; | ||
| 50 | $val.= shift @words; | ||
| 51 | if ($val eq 'sub') { | ||
| 52 | $val.= shift @words; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | my $char= substr($val,0,1); | ||
| 56 | if ($char eq '(') { | ||
| 57 | $val=qq:[$val]:; | ||
| 58 | } elsif ($char ne "'" and $char ne '"' and | ||
| 59 | $char ne '[' and $char ne '{' and $char ne "\\" and | ||
| 60 | $char ne '%' and $char ne '$' and $char ne '%' and | ||
| 61 | $val !~ /^sub\s*\{/) { | ||
| 62 | $val=qq['$val']; | ||
| 63 | } | ||
| 64 | $val=~ s/\033/\\033/g; | ||
| 65 | my @tmp= Psh::PerlEval::protected_eval($val,'eval'); | ||
| 66 | $val= $tmp[0]; | ||
| 67 | if (@tmp>1) { | ||
| 68 | $val= \@tmp; | ||
| 69 | } | ||
| 70 | Psh::Options::set_option($key, $val); | ||
| 71 | } else { | ||
| 72 | my $val= Psh::Options::get_printable_option($tmp,1); | ||
| 73 | Psh::Util::print_out("$val\n"); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | return (1,undef); | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | 1; |