# decode-prompt

> parse bash $PS1 escape characters

Latest version **0.0.2** (published 2013-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install decode-prompt
pnpm add decode-prompt
yarn add decode-prompt
bun add decode-prompt
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2013-08-06 |
| First published | 2013-06-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | James Halliday |
| Maintainers | substack |
| Keywords | bash, PS1, escape, shell, env |

## Links

- npm: https://www.npmjs.com/package/decode-prompt
- Repository: https://github.com/substack/decode-prompt
- Issues: https://github.com/substack/decode-prompt/issues
- npm.io page: https://npm.io/package/decode-prompt

## Dependencies (1)

- [strftime](https://npm.io/package/strftime.md) ~0.6.1

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 0.0.2 (latest) — 2013-08-06
- 0.0.1 — 2013-06-24
- 0.0.0 — 2013-06-24

## README

# decode-prompt

parse bash 
[$PS1 escape characters](https://www.gnu.org/software/bash/manual/bash.html#Printing-a-Prompt)

[![browser support](https://ci.testling.com/substack/decode-prompt.png)](http://ci.testling.com/substack/decode-prompt)

[![build status](https://secure.travis-ci.org/substack/decode-prompt.png)](http://travis-ci.org/substack/decode-prompt)

# example

``` js
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

``` js
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 use `opts.env` as a fallback default value.
* `opts.now` - date for all the time functions to use, default: `new Date`
* `opts.hostname` - the `os.hostname()` value to use, otherwise `os.hostname()`
* `opts.jobs` - number of jobs currently managed by the shell, default: 0
* `opts.tty` - the shell's tty name (like the `tty` command gives), default: -1
* `opts.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](https://npmjs.org) do:

```
npm install decode-prompt
```

# license

MIT

---
_Source: https://npm.io/package/decode-prompt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
