NAME
Env::PS1 - prompt string formatter
SYNOPSIS
# use the import function
use Env::PS1 qw/$PS1/;
$ENV{PS1} = '\u@\h \$ ';
print $PS1;
$readline = <STDIN>;
# or tie it yourself
tie $prompt, 'Env::PS1', 'PS1';
DESCRIPTION
This package supplies variables that are "tied" to environment variables like 'PS1' and 'PS2', if read it takes the contents of the variable as a format string like the ones bash(1) uses to format the prompt.
It is intended to be used in combination with the various ReadLine packages.
EXPORT
You can request for arbitrary variables to be exported, they will be tied to the environment variables of the same name.
METHODS
sprintf($format)
-
Returns the formatted string.
Using this method all the time is a lot less efficient then using the tied variable, because the tied variable caches parts of the format that remain the same anyway.
FORMAT
The format is copied from bash(1) because that's what it is supposed to be compatible with. We made some private extensions which obviously are not portable.
Note that is not the prompt format specified by the posix spec, that one only knows "!" for istory number and "!!" for literal "!".
The following escape sequences are recognized:
- \a
-
The bell character, identical to "\007"
- \d
-
The date in "Weekday Month Date" format
- \D{format}
-
The date in strftime(3) format, uses POSIX
- \e
-
The escape character, identical to "\033"
- \n
-
Newline
- \r
-
Carriage return
- \s
-
The basename of $0
- \t
-
The current time in 24-hour format, identical to "\D{%H:%M:%S}"
- \T
-
The current time in 12-hour format, identical to "\D{%I:%M:%S}"
- \@
-
The current time in 12-hour am/pm format, identical to "\D{%I:%M %p}"
- \A
-
The current time in short 24-hour format, identical to "\D{%H:%M}"
- \u
-
The username of the current user
- \w
-
The current working directory
- \W
-
The basename of the current working directory
- \$
-
"#" for effective uid is 0 (root), else "$"
- \0dd
-
The character corresponding to the octal number 0dd
- \\
-
Literal backslash
- \H
-
Hostname, uses Sys::Hostname
- \h
-
First part of the hostname
- \l
-
The basename of the (output) terminal device name
- \[ \]
-
These are used to encapsulate a sequence of non-printing chars. Since we don't need that, they are removed.
Extensions
The following escapes are extensions not supported by bash:
Not implemented escapes
The following escapes are not implemented, most of them because they are application specific.
FIXME how to customly supply these ? overload or hash ?
- \j
-
The number of jobs currently managed by the shell
- \v
-
The version of bash
- \V
-
The release of bash, version + patchelvel
- \!
-
The history number of this command, gets replaced by literal '!' while a literal '!' gets replaces by '!!'; this makes the string a posix compatible prompt, thus it will work if your readline module expects a posix prompt.
- \#
-
The command number of this command (like history number, but minus the lines read from the history file).
BUGS
Please mail the author if you encounter any bugs.
AUTHOR
Jaap Karssenberg || Pardus [Larus] <pardus@cpan.org>
Copyright (c) 2004 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.