# string prompt_string(TEMPLATE)
# Construct a prompt string from TEMPLATE.
my $default_prompt = '\s% ';
%Psh::Prompt
::prompt_vars
= (
my ($wday, $mon, $mday) = (localtime)[6, 4, 3];
$wday = (Psh
::Locale
::weekdays
())[$wday];
$mon = (Psh
::Locale
::months
())[$mon];
return "$wday $mon $mday";
'e' => sub { return "\e"} ,
'E' => sub { return "\e"} ,
'h' => sub { return $Psh::host
; },
'H' => sub { return $Psh::longhost
|| $Psh::host
; },
'S' => sub { return "\0" }, # extends to \
'n' => sub { return "\n" },
my ($hour, $min, $sec) = (localtime)[2, 1, 0];
return sprintf("%02d:%02d:%02d", $hour, $min, $sec);
# Camel, 2e, p. 172: 'getlogin'.
return getlogin || (getpwuid($>))[0] || "uid$>";
my $home = Psh
::OS
::get_home_dir
();
return $dir unless (length($home) > length($Psh::OS
::FILE_SEPARATOR
)); # in case the home dir is the root dir
$dir =~ s/^\Q$home\E/\~/ if $home;
my ($newdir)= $dir=~ m
:/([^/]+)$:;
return $newdir||$dir||'/';
'#' => sub { return $Psh::cmd
; },
'!' => sub { return scalar(@Psh::history
); },
'$' => sub { return ($> ?
'$' : '#'); },
'[' => sub { return $Psh::term
->ReadLine() eq 'Term::ReadLine::Gnu'?
"\001":''},
']' => sub { return $Psh::term
->ReadLine() eq 'Term::ReadLine::Gnu'?
"\002":''},
my $var = $Psh::Prompt
::prompt_vars
{$code};
if (ref $var eq 'CODE') {
} elsif($code =~ /^[0-9]+$/) {
} elsif($code =~ /^\:[0-9]+$/) {
} elsif($code =~ /^0x/) {
Psh
::Util
::print_warning_i18n
('prompt_unknown_escape',$code,$Psh::bin
);
if ($sub =~ m/\\([^\\])/) {
Psh
::Util
::print_warning_i18n
('prompt_expansion_error',$code,
my @tmp= split /\s+/, $name;
$result.=$color_table{$_};
Psh
::Util
::print_debug_class
('o',"Unknown prompt color $_\n");
my $prompt_templ = shift;
# First, get the prompt string from a subroutine or from the default:
if (ref($prompt_templ) eq 'CODE') { # If it is a subroutine,
$temp = &$prompt_templ();
} elsif (ref($prompt_templ)) { # If it isn't a scalar
Psh
::Util
::print_warning_i18n
('prompt_wrong_type',$Psh::bin
);
# Now, subject it to substitutions:
# Substitution is in x steps:
# 1) \\ is substituted by \0 to be able to restore them later on
# 2) The special construct \$( ... ) or $(...) is interpreted
# 3) \char and \digits are interpreted
$temp=~ s/\\\\/\0/g; # save double backslash
# Substitute program execution (for bash compatibility)
while ($temp =~ m/^(.*)\$\((.+?)\)(.*)$/s) {
my ($save1, $code, $save2) = ($1, $2, $3);
$sub=Psh
::OS
::backtick
($code);
Psh
::Util
::print_debug_class
('e',"Error: $@") if $@
;
$temp=$save1 . $sub . $save2;
my $encoding= Psh
::Options
::get_option
('encoding');
my $my_sign= $sign_table{'default'};
if ($encoding and exists $sign_table{$encoding}) {
$my_sign= $sign_table{'iso8859-1'};
$temp=~ s/\\C\{(.+?)\}/&_color_helper($1)/ge;
# Graphics sign conversion
$temp=~ s/\\S\{(\d+?)\}/$my_sign->{$1}/g;
# Standard prompt_var substitution
$temp=~ s/\\([0-9]x?[0-9a-fA-F]*|[^0-9\\])/&_prompt_helper($1)/ge;
$temp=~ s/\0/\\/g; # restore former double backslash
my $prompt= Psh
::Options
::get_option
('ps1');
$prompt= $default_prompt unless defined $prompt;
my $prompt= Psh
::Options
::get_option
('ps2');
$prompt= '> ' unless defined $prompt;
my $tmp= Psh
::Options
::get_option
('prompt_command');
if (ref $tmp and ref $tmp eq 'CODE') {
Psh
::handle_message
($@
,'promp_command');
my $title= Psh
::Options
::get_option
('window_title');
$title= prompt_string
($title);
Psh
::OS
::set_window_title
($title);