All Projects β†’ ramnes β†’ Context Color

ramnes / Context Color

Licence: gpl-3.0
🌈 To each context its own shell color

Programming Languages

shell
77523 projects

Labels

Projects that are alternatives of or similar to Context Color

Tizonia Openmax Il
Command-line cloud music player for Linux with support for Spotify, Google Play Music, YouTube, SoundCloud, TuneIn, iHeartRadio, Plex servers and Chromecast devices.
Stars: ✭ 1,556 (+1175.41%)
Mutual labels:  terminal
Box Cli Maker
Make Highly Customized Boxes for your CLI
Stars: ✭ 115 (-5.74%)
Mutual labels:  terminal
Warp
Secure and simple terminal sharing
Stars: ✭ 1,548 (+1168.85%)
Mutual labels:  terminal
Openterm
OpenTerm is a sandboxed command line interface for iOS.
Stars: ✭ 1,504 (+1132.79%)
Mutual labels:  terminal
Xterm.js
A terminal for the web
Stars: ✭ 12,019 (+9751.64%)
Mutual labels:  terminal
Awesome Macos Command Line Zh
η”¨δ½ ηš„ macOS η»ˆη«―ζžδΊ‹ζƒ…γ€‚(Use your macOS terminal shell to do awesome things. )
Stars: ✭ 117 (-4.1%)
Mutual labels:  terminal
Terminal markdown viewer
Styled Terminal Markdown Viewer
Stars: ✭ 1,565 (+1182.79%)
Mutual labels:  terminal
Fancy Git
That's a simple prompt changer to show a few cool git informations about your repository on terminal. You can choose among 13 styles and enjoy all the aliases it provides you. Feel free for contributing, pull requests and issues are always welcome! ;)
Stars: ✭ 123 (+0.82%)
Mutual labels:  terminal
Pure
Pretty, minimal and fast ZSH prompt
Stars: ✭ 10,891 (+8827.05%)
Mutual labels:  terminal
Ervy
Bring charts to terminal.
Stars: ✭ 1,530 (+1154.1%)
Mutual labels:  terminal
Termion
Mirror of https://gitlab.redox-os.org/redox-os/termion
Stars: ✭ 1,654 (+1255.74%)
Mutual labels:  terminal
Mylittledom
High-level DOM-like terminal interface library
Stars: ✭ 116 (-4.92%)
Mutual labels:  terminal
Vte
Parser for virtual terminal emulators
Stars: ✭ 117 (-4.1%)
Mutual labels:  terminal
Emacs Application Framework
A free/libre and open-source extensible framework that revolutionizes the graphical capabilities of Emacs, the key to ultimately Live in Emacs
Stars: ✭ 1,932 (+1483.61%)
Mutual labels:  terminal
Alpine Term
Repository has been moved.
Stars: ✭ 121 (-0.82%)
Mutual labels:  terminal
Vuminal
Create terminal applications with the power of Vue 3.
Stars: ✭ 114 (-6.56%)
Mutual labels:  terminal
Reflex Vty
Build terminal applications using functional reactive programming (FRP) with Reflex FRP.
Stars: ✭ 117 (-4.1%)
Mutual labels:  terminal
Dksnap
Docker Snapshots for Development and Test Data
Stars: ✭ 122 (+0%)
Mutual labels:  terminal
Gsoc Organisation Scraper
Scrape GSoC organisations using a single script.
Stars: ✭ 121 (-0.82%)
Mutual labels:  terminal
Sentaku
Utility to make sentaku (selection, 選択(sentaku)) window with shell command.
Stars: ✭ 117 (-4.1%)
Mutual labels:  terminal

context-color

Build status

🌈 To each context its own shell color

gif

context-color is a simple script that, when executed, outputs a color based on a command output's hash.

Example

Once installed somewhere in your $PATH, it allows you to do things like this:

PS1="$(context-color -p)$PS1\[\e[0m\]"

(where --prompt/-p is the switch so that the color is escaped for prompts, and \[\e[0m\] the escape sequence to reset color)

If your prompt does not use colors already, this example would customize it so that its color changes according to the current context.

The default context command (i.e. the command that is used to generate the hash) is whoami; hostname. If you would just want the color to change according to the hostname, you would change the CC_CONTEXT environment variable (export CC_CONTEXT="hostname") or simply use the --context/-c option (context-color -c "hostname").

Then you could make this customization permanent by adding this line to your ~/.bashrc, or to the system-wide bashrc file (most likely somewhere in /etc/, depending on your distribution) if you would want all users to benefit from this.

If you are working with several machines, you could either do that manipulation on every host, or use something like Russell91/xxh.

⚠️ Do not use single quotes around your PS1 value. If you want the color to be evaluated at each prompt, you should use PROMPT_COMMAND instead. Here is an example:

PS1="$PS1\[\e[0m\]"
PROMPT_COMMAND="context-color"

Install

Something in those lines should do it:

cd .local/bin/
wget https://raw.githubusercontent.com/ramnes/context-color/master/context-color
chmod a+x context-color

This snippet assumes that ~/.local/bin/ is in your $PATH environment variable. If it is not, you can either put context-color somewhere else (/usr/local/bin/, for example), or insert ~/.local/bin/ into your $PATH, by adding this line into your bash configuration:

export PATH="~/.local/bin/:$PATH"

Usage

usage: context-color [OPTIONS]

Print a color sequence based on a command output's hash.

COMMON OPTIONS:
    --help, -h          Print this help.
    --background, -b    Use a background sequence rather than foreground.
    --id, -i            Print the color id rather than the color sequence.
    --prompt, -p        Declare the sequence as non-printable for prompts.

    --context <command>, -c <command>
                        Define the context command on which result the color
                        will be generated.
                        The default context is "whoami; hostname".

    --exclude <colors>, -e <colors>
                        Comma separated list of color ids not to be used.
                        Multiple --exclude/-e arguments can be specified.
                        The default excluded colors are: "0,7,15"

    --method <method>, -m <method>
                        Choose which hashing method to use. "sum" will tend to
                        give adjacent colors for adjacent context outputs.
                        "md5sum" will give more randomization on colors.
                        The default method is: "sum"

DEBUG OPTIONS:
    --debug, -d         Output the sequence as a human-readable string and more
                        useful information.
    --force <color>, -f <color>
                        Ignore the context and force a color id instead.

The -p option must be used if you use context-color inside a prompt. It makes your shell understand that the color sequence characters won't be used when it's trying to guess the space left on the current line. See issue #8 for a good description of what happens if you do not put -p in that situation.

Credits

The original implementation was based on J Earls answer on this SuperUser question.

He's the real MVP. πŸ‘Œ

License

GNU GPL v3

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].