Home

Awesome

robbyrussell-img

robbyrussell-node

NPM version Node.js version Dependency status Build status Donate

Cross-shell robbyrussell theme written in JavaScript

Motivation

I'm developing 🚀⭐️ spaceship-zsh-theme which is an extremely powerful and customizable prompt for ZSH. It supports a lot of environments and tools to make you enjoy using it. However, there are plenty issues I faced: zsh is hard, dependency management is difficult, testing is near to impossible and so on.

This project is just a proof of concept. Definitely, that's not the best implementation, nevertheless, it opens interesting possibilities:

Why JavaScript? Just because it's a high-level language which provides wide infrastructure with a good package manager, lots of packages and good community. It's quite fast and easy to make a simple working example.

Installation

npm

npm install -g robbyrussell

Done. This command should source the corresponding adapter for your shell. Just reload your terminal.

Binaries

If you don't have Node.js installed on your machine, you can download pre-built binaries with built-in Node.js version.

⬇️ Download binary ⬇️

Use them in your shell configuration with adapters.

bash:

# BASH-specific adapter
robbyrussell_bash_adapter() {
  robbyrussell_previous_exit_code="$?"
  /path/to/robbyrussell $robbyrussell_previous_exit_code 'bash'
}

# set prompt
PS1='$(robbyrussell_bash_adapter)'

zsh:

# ZSH-specific adapter
robbyrussell_zsh_adapter() {
  robbyrussell_previous_exit_code="$?"
  /path/to/robbyrussell $robbyrussell_previous_exit_code 'zsh'
}

# set prompt
PROMPT='$(robbyrussell_zsh_adapter)'

fish:

# FISH-specific adapter
function robbyrussell_fish_adapter -d "a robbyrussell theme adapter for fish"
  set robbyrussell_previous_exit_code "$status"
  /path/to/robbyrussell $robbyrussell_previous_exit_code 'fish'
end

# set prompt
function fish_prompt
  # fish splits command substitutions on newlines
  # need to temporarily reset IFS to empty
  #   @see: http://stackoverflow.com/a/34186172/5508862
  set -l IFS
  robbyrussell_fish_adapter
end

Configuration

Exposing the pormpt settings as environment variables is a known problem. This prompt reads a special configuration file from your home directory, which allows you to define more complex configs. A prompt automatically looks for ~/.prompt-config.js or ~/.prompt-config.json files. These files should export configuration object.

Important: A prompt needs to escape colors codes, otherwise it would behave incorrectly. This prompt includes patched chalk package with escape codes for current process.env.SHELL.

Default config looks like this:

// Patched for current shell chalk/chalk colors
const styles = require('robbyrussell/utils/colors');

module.exports = {
  /**
   * Check git status asynchronously
   */
  async: false,
  /**
   * Prompt prefix and suffix
   */
  prompt: {
    open: styles.bold.open,
    close: styles.bold.close + styles.reset.close
  },
  /**
   * Status code
   */
  status: {
    char: '➜',
    success: styles.green.open,
    failure: styles.red.open,
  },
  /**
   * Directory style
   */
  dir: {
    color: styles.cyan.open
  },
  /**
   * Git status styles
   */
  git: {
    indicator: styles.blue.open,
    branch: styles.red.open,
    dirty: styles.yellow.open,
    dirtyChar: '✗'
  }
};

License

MIT © Denys Dovhan

<!-- Badges --> <!-- References -->