Skip to content

Commit

Permalink
Merge branch 'powerline'
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Jan 26, 2020
2 parents f074f0b + b5bf972 commit 71859c9
Show file tree
Hide file tree
Showing 26 changed files with 3,080 additions and 198 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 10
146 changes: 99 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,96 @@
Nodeprompt
==================================================

Smart Git prompt for your terminal made in Node.js.
[![npm version](https://badge.fury.io/js/nodeprompt.svg)](https://www.npmjs.com/package/nodeprompt)
[![Build Status](https://travis-ci.org/oleq/nodeprompt.svg?branch=master)](https://travis-ci.org/oleq/nodeprompt)
[![Dependency Status](https://img.shields.io/david/oleq/nodeprompt.svg)](https://david-dm.org/oleq/nodeprompt)
[![devDependency Status](https://img.shields.io/david/dev/oleq/nodeprompt.svg)](https://david-dm.org/oleq/nodeprompt?type=dev)

A smart Git prompt for your terminal powered by Node.js.

![Staged, unstaged and untracked files](demo/git-various.png?raw=true)

## Requirements

### System

* Bash 3.2.x
* [Fish](https://fishshell.com/) 2.5.x (experimental)
* [Node.js](https://nodejs.org/) (tested with 0.10.x, 5.7.x, 6.9.x).
* [Git](https://git-scm.com/) (tested with 1.9.x, 2.7.x, 2.11.x, 2.14.x).
* [Fish](https://fishshell.com/) 2.5.x
* Zsh 5.3
* [Node.js](https://nodejs.org/) (tested with 0.10.x, 5.7.x, 6.9.x, 10.x).
* [Git](https://git-scm.com/) (tested with 1.9.x, 2.7.x, 2.11.x, 2.14.x, 2.25.x).

**Note:** There is a good change Nodeprompt will work with other configurations — just give it a shot and let me know!

## Demo
### Font

**Since v2.0.0 Nodeprompt requires some special (powerline) symbols to be supported by the terminal font to render properly.**

Some fonts support those symbols (glyphs) out–of–the–box, for instance, [Fira Code](https://github.com/tonsky/FiraCode) used in examples below. Many open–source fonts have been patched and [can be downloaded from GitHub](https://github.com/powerline/fonts). If neither works for you, you can google "[your font name] powerline" because it's likely someone patched your favorite font and posted it on–line.

**A note for iTerm 2 users**: Make sure the powerline–compatible font is enabled in both `Profiles > Text > Font` and `Profiles > Text > Non–ASCII Font`.

## Examples

### A plain folder (no Git)

![A simple folder](demo/no-git.png?raw=true)

### An empty Git repository

![An empty Git repository](demo/git-init.png?raw=true)

### Unstaged changes

![Unstaged changes](demo/git-unstaged.png?raw=true)

### Staged, unstaged and untracked

![Nodeprompt demo](demo/demo.gif?raw=true)
![Staged, unstaged and untracked files](demo/git-various.png?raw=true)

### Branch ahead of the remote

![Branch ahead](demo/git-ahead.png?raw=true)

### Merge conflict

![Merge conflict](demo/git-merge-conflict.png?raw=true)

## Installation

### Bash
1. Call `npm install -g nodeprompt` (or `yarn global add nodeprompt`).
2. Configure your shell:

1. Call `npm install -g nodeprompt` first.
1. Put the following line
### Bash

```bash
. nodeprompt-enable
```
Put the following line:

in your `~/.bashrc` or `~/.bash_profile` file.
1. Re–open the terminal window or source the file, i.e. `source ~/.bashrc`.
1. Enjoy your beautiful prompt!
```bash
. nodeprompt-enable-bash
```

in your `~/.bashrc` or `~/.bash_profile` file. Re–open the terminal window or source the file, e.g. `source ~/.bashrc`.

### Zsh

Put the following lines:

```bash
. nodeprompt-enable-zsh
```

in your `~/.zshrc` file. Re–open the terminal window or `source ~/.zshrc`.

### Fish

Create a symbolic link to the `fish_prompt.fish` function file:

```bash
ln -s /path/to/../nodeprompt/bin/fish_prompt.fish ~/.config/fish/functions/fish_prompt.fish
```

### Fish (experimental)
Re–open the terminal window.

1. Locate the path to the package (`npm install -g nodeprompt`) in your OS or [clone Nodeprompt](#how-to-contribute) from GitHub.
1. Create a symlink to the fish script:
```bash
ln -s path/to/nodeprompt/bin/fish_prompt.fish ~/.config/fish/functions/fish_prompt.fish
```
1. Re–open the terminal window.
1. Enjoy your beautiful prompt!

## Configuration and customization
Expand All @@ -47,15 +99,15 @@ Nodeprompt is configurable and things like the length of the SHA-1 hash or the n

**Note**: You **don't** have to configure Nodeprompt. By default, it uses [`config.default.js`](https://github.com/oleq/nodeprompt/blob/master/config.default.js).

Config file is a plain Node.js module. To configure your prompt, create a `~/.nodeprompt/config.user.js` file with `module.exports` declaration
The config file is a plain Node.js module. To configure your prompt, create a `~/.nodeprompt/config.user.js` file with `module.exports`:

```js
module.exports = {
option: 'value'
};
```

or simply copy `config.default.js` there and modify it. Refer to documentation inside [`config.default.js`](https://github.com/oleq/nodeprompt/blob/master/config.default.js) to learn more.
or simply copy [the default configuration](https://github.com/oleq/nodeprompt/blob/master/config.default.js) and modify it. Refer to the [documentation](https://github.com/oleq/nodeprompt/blob/master/config.default.js) to learn more.

## Using as a library

Expand All @@ -68,28 +120,28 @@ const prompt = new Nodeprompt();
console.log( prompt.model );

> {
pwd: '/Users/oleq/nodeprompt',
home: '/Users/oleq',
gitDir: '.git',
isGit: true,
hostname: 'MBP',
username: 'oleq',
path: '~/nodeprompt',
namerev: 'v1.0',
head: 'ref: refs/heads/v1.0',
hash: 'b22bb89',
mergeHead: '',
isInit: false,
isBisecting: false,
isDetached: false,
isMerging: false,
modified: 2,
added: 0,
untracked: 0,
ahead: 2,
behind: 0,
branch: 'v1.0',
hasDiverged: false
pwd: '/Users/oleq/nodeprompt',
home: '/Users/oleq',
gitDir: '.git',
isGit: true,
hostname: 'MBP',
username: 'oleq',
path: [ '~', 'nodeprompt' ],
namerev: 'v1.0',
head: 'ref: refs/heads/v1.0',
hash: 'b22bb89',
mergeHead: '',
isInit: false,
isBisecting: false,
isDetached: false,
isMerging: false,
modified: 2,
added: 0,
untracked: 0,
ahead: 2,
behind: 0,
branch: 'v1.0',
hasDiverged: false
}
```

Expand All @@ -99,7 +151,7 @@ Create an issue [here](https://github.com/oleq/nodeprompt/issues).

## How to contribute?

Clone the repository to `/path/to/nodeprompt` and put `. /path/to/nodeprompt/bin/nodeprompt-enable` in your `~/.bashrc` or `~/.bash_profile` file. Source it or restart the terminal.
Clone the repository to `/path/to/nodeprompt` and put `. /path/to/nodeprompt/bin/nodeprompt-bash` in your `~/.bashrc` or `~/.bash_profile` file. Source it or restart the terminal.

## License

Expand Down
7 changes: 2 additions & 5 deletions bin/fish_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

if status --is-interactive
function fish_prompt
if test -d "$PWD";
set DIR (dirname (readlink (status --current-filename)))
echo -e (eval $DIR/nodeprompt)
end
echo -e (eval nodeprompt)
end
end
end
4 changes: 2 additions & 2 deletions bin/nodeprompt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* @license MIT
*/

/* global process */
/* global process, __dirname */

'use strict';

const Nodeprompt = require( '../lib/nodeprompt.js' );
const Nodeprompt = require( __dirname + '/../lib/nodeprompt.js' );
const prompt = new Nodeprompt().print();

process.stdout.write( prompt );
17 changes: 0 additions & 17 deletions bin/nodeprompt-enable

This file was deleted.

14 changes: 14 additions & 0 deletions bin/nodeprompt-enable-bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# A bash script which enables Nodeprompt by setting the PS1.
# License: MIT.

# Abort if not an interactive shell.
[[ $- != *i* ]] && return

NODEPROMPT() {
PS1=$(nodeprompt)
}

PROMPT_COMMAND=NODEPROMPT

8 changes: 8 additions & 0 deletions bin/nodeprompt-enable-zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/zsh

# A zsh script which enables Nodeprompt by setting the PS1.
# License: MIT.

setopt PROMPT_SUBST
PROMPT='$(nodeprompt)'

Loading

0 comments on commit 71859c9

Please sign in to comment.