• Stars
    star
    166
  • Rank 227,748 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cross-shell robbyrussell theme written in JavaScript

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:

  • high-level language — ZSH is nice, but not for programming. JavaScript or Python seems more comfortable for these cases.
  • single code base — Single source code for all shells. The core logic is written in a high-level language while the shell-specific code is located in special files called adapters.
  • cross-shell — different shells are too specific. Single code base on high-level language with unified interface gives us an ability to use it with any shell(fish, zsh, bash, sh, etc).
  • cross-platform — things like pkg allows us to package prompt into binary and use it wherever we want, even without installed language runtime.
  • testable — high-level language and its infrastructure make it possible to test prompt components with tools like Mocha, Jest or tape (unlike traditional prompts which are usually untested).
  • dependency managementNPM, RubyGems and PyPI store thousands of packages that could be used for special prompt's needs. It's also possible to install prompt itself with one of these package managers.
  • asynchronous checks — the more synchronous checks you do, the slower prompt becomes. Things like async/await or Promise.all() could perform environment checks concurrently, so we can achieve significant performance improvement.

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

More Repositories

1

wtfjs

🤪 A list of funny and tricky JavaScript examples
JavaScript
34,920
star
2

bash-handbook

📖 For those who wanna learn Bash
JavaScript
5,679
star
3

vacuum-card

Vacuum cleaner card for Home Assistant Lovelace UI
TypeScript
899
star
4

learnyoubash

Learn you how to write your first bash script
JavaScript
745
star
5

inboxer

Unofficial, free and open-source Inbox by Gmail Desktop App
JavaScript
666
star
6

learnyouhtml

Learn you how to create your first web page
HTML
439
star
7

dotfiles

My lovely dots ~/.💖
Shell
399
star
8

ukrainian-typographic-keyboard

Combined Ukrainian keyboard layout with typographic symbols
361
star
9

one-gnome-terminal

Atom's One Dark and One Light theme for GNOME Terminal
Shell
318
star
10

purifier-card

Air Purifier card for Home Assistant Lovelace UI
TypeScript
269
star
11

smart-home

⚙️ My homelab and smart-home server built with Proxmox, Ubuntu, Docker
Shell
246
star
12

ha-yasno-outages

⚡️ Yasno electricity outages (due to war in Ukraine) integration for Home Assistant.
Python
74
star
13

oceanic-next-gnome-terminal

Oceanic Next theme for GNOME Terminal
Shell
51
star
14

ha-check-weather

🌤️ A simple binary sensor for Home Assistant that checks the weather for the next hours and turns on when it fits certain conditions
Python
38
star
15

home-assistant-config

🏡 My home automation setup built with Home Assistant and documented in details. Press 🌟 and subscribe for updates!
Python
28
star
16

gitbook-plugin-rss

RSS for your gitbook
JavaScript
24
star
17

denysdovhan.github.io

📰 Personal blog from Denys Dovhan
JavaScript
23
star
18

less-mix

LESS-Mix - is a functional, powerful and convenient library LESS-mixins.
CSS
22
star
19

gitio-zsh

✂️ A zsh plugin for generating a GitHub short URL using git.io.
Shell
22
star
20

rsa-labwork

A javascript RSA algorithim encryption tool
JavaScript
20
star
21

ha-lun-misto-air

💨 An integration for air quality monitoring by LUN Misto.
Python
16
star
22

emojify-text

Convert boring text to wonderful emojis
JavaScript
14
star
23

chernivtsi-transport

Application for Chernivtsi public transport system
TypeScript
12
star
24

awesome-nodeschool

🏫 List of awesome things for NodeSchool people
11
star
25

textr-cli

Command line interface for Textr
JavaScript
11
star
26

learning-asm

Here I'm gonna collect links and resources, that I used for learning Assembly
Assembly
9
star
27

cv

Hire me!
CSS
8
star
28

typographic-markdown

Markdown transformers to make your typography better.
JavaScript
8
star
29

victory-or-betrayal

React app that helps you recognize betrayal and victory.
JavaScript
6
star
30

grunt-textr

Grunt plugin for Textr
JavaScript
5
star
31

home-stack

A tool for bootstrapping and managing smart homes
Shell
4
star
32

slides-kottans-chernivtsi-2019-react-continued-part-2

Slides for 2nd part of my talk about React for Kottans Chernivtsi Frontend Course 2019
JavaScript
4
star
33

slides-reactalicante-pet-projects

Slides for my talk about pet-projects at React Alicante 2019
JavaScript
4
star
34

chernivtsi-outages

Electricity outages data in Chernivtsi, Ukraine
TypeScript
4
star
35

slides-cross-shell-prompts

Slides for my talk about cross-shell prompts in JavaScript
JavaScript
4
star
36

rainbow

Rainbow - powerful, colorful, intuitive css-framework for your project.
CSS
3
star
37

slides-kottans-chernivtsi-2019-react-continued-part-1

Slides for 1st part of my talk about React for Kottans Chernivtsi Frontend Course 2019
JavaScript
3
star
38

slides-automating-github-workflow

Slides for my talk “Automating GitHub workflow with probot”
JavaScript
3
star
39

raw-brunch

A Brunch plugins for raw modules
JavaScript
3
star
40

slides-vilniusjs-pet-projects

Slides for my talk about pet-projects at VilniusJS
JavaScript
3
star
41

slides-what-is-bash

Slides for my talk about learnyoubash workshopper
HTML
3
star
42

coursework-software-engineering

Course work of «Software Engineering» discipline
JavaScript
3
star
43

slides-promises

Slides for my talk about Promises
JavaScript
2
star
44

slides-inputconf-2019-open-source

Slides for my talk about Open Source at Input conference
JavaScript
2
star
45

slides-javascript-shells

Slides for my talk about JavaScript Shells
JavaScript
2
star
46

ha-template

A tiny (<2kB) lit component for rendering templates in Home Assistant custom cards
TypeScript
2
star
47

emojify-text-cli

Command line interface to emojify-text
JavaScript
2
star
48

slides-pet-projects-ukrainian

Slides for my talk about pet-projects in Ukrainian
JavaScript
2
star
49

pingpong.js

Ping-Pong implemented on HTML Canvas + JavaScript.
JavaScript
2
star
50

keynote-slides-template

Template repo for my Keynote slides exported as HTML
2
star
51

workshopper-boilerplate

A common boilerplate for NodeSchool workshopper
JavaScript
2
star
52

slides-feel-good-with-brunch

Slides for my talk about Brunch
JavaScript
2
star
53

denysdovhan

Personal Profile Description
1
star
54

slides-vr-crash-course

Slides for my talk about VR
JavaScript
1
star
55

slides-15x4-how-internet-works

15 minutes about how Internet works
HTML
1
star
56

slides-writing-bots-for-github

Slides for my talk “Writing bots for GitHub”
JavaScript
1
star
57

slides-inputconf-2019-chernivtsijs

Slides for my talk about @chernivtsijs community at Input conference
JavaScript
1
star
58

slides-frontendzt-pet-projects

Slides for my talk about pet-projects at frontend://zt
JavaScript
1
star
59

slides-kottans-chernivtsi-2017-react-continued

Slides for my talk about React for Kottans Chernivtsi Frontend Course
JavaScript
1
star
60

slides-kottans-chernivtsi-introduction

Slides for my talk about Kottan Course in Chernivtsi
JavaScript
1
star