GithubHelp home page GithubHelp logo

optionalg / bash-7 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from calid/bash

0.0 2.0 0.0 26.51 MB

Bash fork that supports custom mode indicators

License: GNU General Public License v3.0

Shell 3.51% C 82.50% Makefile 3.32% C++ 0.34% M4 1.18% Yacc 5.01% Assembly 0.06% Awk 0.03% Perl 4.04% Groff 0.01%

bash-7's Introduction

Bash with Configurable Mode Strings

This is a patched version of bash 4.3 that adds support for custom prompt mode indicators. It also adds support for a \m prompt escape to specify where in the prompt the indicator should occur.

modestr demo

This will (mostly) be available in bash 4.4/readline 7.0. However the 4.4 beta is currently pretty buggy and the \m indicator hasn't been accepted (yet). So for now if you really want this functionality you'll probably have to use the patched 4.3 version.

Install

$ git clone https://github.com/calid/bash.git -b modestrs --recurse-submodules
$ cd bash
$ ./configure
$ make
$ sudo make install

You can also just run ./bash after make completes if you want to try the patched version without installing it

Usage

In your inputrc

set show-mode-in-prompt on
set vi-ins-mode-string <some string>
set vi-cmd-mode-string <some other string>

If you don't set custom strings the defaults are (ins) and (cmd).

In your PS1

Set your PS1 as normal, but now you can also include a \m escape to specify where in the prompt you want the mode strings to display. e.g. PS1='\u@\h \m $ '

If you turn show-mode-in-prompt on without specifying \m the default is to display the mode string at the beginning of the last line of the prompt.

All the pretty colors

You can use color codes in your mode strings. Simply bracket the color escape sequences with \1 and \2. So to produce colored (ins) and (cmd) mode strings like in the demo above you would do:

set vi-ins-mode-string \1\e[34;1m\2(ins)\1\e[0m\2
set vi-cmd-mode-string \1\e[35;1m\2(cmd)\1\e[0m\2

You can also use 256 color escape sequences. Throw in some unicode characters and things can start to get pretty fancy:

multiline unicode color mode strings

Known Issues

Multiline prompts

  • Mode strings currently only work on the last line of multiline prompts. Lame, I know. Unfortunately readline has deeply baked logic to only redraw the last line of multiline prompts, and it will take some work to change this.

  • For multiline prompts the vi movement seems to get confused if there's no terminal reset sequence after the last newline. I haven't figured out why this is, but the fix is easy: just make sure you put a reset sequence after the last newline. So not:

    PS1='\n\m$ '
    

    but rather:

    PS1='\n\[\e[0m\]\m$ '
    

Contributing

If you'd like to submit pull requests with fixes or improvements for the mode strings functionality I'm happy to accept them. I'll forward any relevant patches upstream to the bash mailing list (with attribution of course).

See Also

If you want a patched version of the standalone readline library: https://github.com/calid/readline.git

The original mailing list post: https://lists.gnu.org/archive/html/bug-bash/2014-08/msg00124.html

bash-7's People

Contributors

calid avatar jaalto avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.