Skip to content

Latest commit

History

History
168 lines (108 loc) · 5.15 KB

README.md

File metadata and controls

168 lines (108 loc) · 5.15 KB

Nodeprompt

npm version Build Status Dependency Status devDependency Status

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

Staged, unstaged and untracked files

Requirements

System

  • Bash 3.2.x
  • Fish2.5.x
  • Zsh 5.3
  • Node.js(tested with 0.10.x, 5.7.x, 6.9.x, 10.x).
  • Git(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!

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 Codeused in examples below. Many open–source fonts have been patched andcan be downloaded from GitHub.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 bothProfiles > Text > FontandProfiles > Text > Non–ASCII Font.

Examples

A plain folder (no Git)

A simple folder

An empty Git repository

An empty Git repository

Unstaged changes

Unstaged changes

Staged, unstaged and untracked

Staged, unstaged and untracked files

Branch ahead of the remote

Branch ahead

Merge conflict

Merge conflict

Installation

  1. Callnpm install -g nodeprompt(oryarn global add nodeprompt).

  2. Configure your shell:

    Bash

    Put the following line:

    .nodeprompt-enable-bash

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

    Zsh

    Put the following lines:

    .nodeprompt-enable-zsh

    in your~/.zshrcfile. Re–open the terminal window orsource ~/.zshrc.

    Fish

    Create a symbolic link to thefish_prompt.fishfunction file:

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

    Re–open the terminal window.

  3. Enjoy your beautiful prompt!

Configuration and customization

Nodeprompt is configurable and things like the length of the SHA-1 hash or the number of levels displayed in the path can be adjusted. It is also possible to create a new prompt template from scratch, if that's what you want to do tonight.

Note:Youdon'thave to configure Nodeprompt. By default, it usesconfig.default.js.

The config file is a plain Node.js module. To configure your prompt, create a~/.nodeprompt/config.user.jsfile withmodule.exports:

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

or simply copythe default configurationand modify it. Refer to thedocumentationto learn more.

Using as a library

Nodeprompt can be used as a utility to obtain the status of the Git repository. Use themodelproperty to build your own prompt or logger on top of the library:

constNodeprompt=require('./lib/nodeprompt.js');
constprompt=newNodeprompt();

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
}

Found a bug?

Create an issuehere.

How to contribute?

Clone the repository to/path/to/nodepromptand put./path/to/nodeprompt/bin/nodeprompt-bashin your~/.bashrcor~/.bash_profilefile. Source it or restart the terminal.

License

MIT/X11. See theLICENSEfile to know more.

Misc

Kudos toLeonid Volnitskyforgit-prompt,an inspiration to create this project.

Tests and development

  • Callnpm run testto run tests.
  • Callnpm run coverageto run tests with code coverage report in./coverage.
  • Callnpm run lintto run ESLint.