decode-prompt
v0.0.2
Published
parse bash $PS1 escape characters
Downloads
1,962
Readme
decode-prompt
parse bash $PS1 escape characters
example
var decode = require('../');
var s = decode(process.argv[2], { env: process.env });
console.log(s);
$ node example/prompt.js '\w \$ '
~/projects/decode-prompt $
$
substack : decode-prompt $ node example/prompt.js "<$PS1>"
<substack : decode-prompt $ >
substack : decode-prompt $
methods
var decode = require('decode-prompt')
decode(str, opts)
Return the decoded bash $PS1
string str
.
opts.env
- environment variables to use.$NAME
and${NAME}
are decoded and some options useopts.env
as a fallback default value.opts.now
- date for all the time functions to use, default:new Date
opts.hostname
- theos.hostname()
value to use, otherwiseos.hostname()
opts.jobs
- number of jobs currently managed by the shell, default: 0opts.tty
- the shell's tty name (like thetty
command gives), default: -1opts.shell
- the current $SHELL, default:opts.env.SHELL
.opts.user
- username to use, default:opts.env.USER
.opts.version
- version of the shell (bash), default:'0.0.0'
opts.cwd
- current working directory, default:opts.env.PWD || process.cwd()
opts.dirtrim
- number of directories to trim output at with an ellipsis, default:opts.env.DIRTRIM || 0
opts.history
- history number, default:0
opts.command
- command number, default:0
opts.uid
- uid, default:opts.env.UID || process.getuid()
install
With npm do:
npm install decode-prompt
license
MIT