Git Product home page Git Product logo

ps1_lint's Introduction

PS1Lint

PS1Lint is a tool for finding flaws in Bash PS1 strings. While Bash is forgiving, a poorly formatted PS1 can cause line wrapping issues.

Usage

There are two ways to use PS1Lint.

  1. Use setup.py to install the module to your machine.

     python3 setup.py install
    
     # someFile.py
     import ps1Lint
     ps1Lint.parse(r'\u@\h\n\$ ')  # Returns a boolean.
    
  2. Pass the module a single quoted (prevents shell expansion) PS1 argument.

     ps1Lint.py [-h] bashPS1
    
     # e.g.
     python3 ps1Lint.py '\[\e[0;32m\]\u@\[\e[0;36m\]\h:\[\e[0;35m\] '
    

Quick PS1 Overview

Prompt Variables

See here for a list of prompt variables.

Note: \a and \r are not tolerated as they cause line wrapping issues.

Colors

A color sequence affects everything after its declaration. It must be escaped with \[ ... \] so that lines wrap properly.

Below are valid escaped color sequences:

    \[\e[0m\]  # (a text reset--the same as \[\033[0m\])
    \[\e[1;43m\]
    \[\e[32m\]
    \[\e[4;32;44m\]
    \[\e[44;0;34m\]
    \[\e[34;4m\]

Color Codes [1]:

    Text Attributes         Foreground Colors   Background Colors
    0 All Attributes Off    30 Black            40 Black
    1 Bold On               31 Red              41 Red
    4 Underscore On         32 Green            42 Green
    5 Blink On              33 Yellow           43 Yellow
    7 Reverse Video On      34 Blue             44 Blue
    8 Concealed On          35 Magenta          45 Magenta
                            36 Cyan             46 Cyan
                            37 White            47 White

Cursor Movement

Cursor movement sequences must be escaped like color sequences.

Escaped Cursor Movement Sequences [1]:

    \[\e[<Line>;<Column>H\]         Cursor Position
    \[\e[<Line>;<Column>f\]
    \[\e[<Value>A\]                 Cursor Up
    \[\e[<Value>B\]                 Cursor Down
    \[\e[<Value>C\]                 Cursor Forward
    \[\e[<Value>D\]                 Cursor Backward
    \[\e[s\]                        Save Cursor Position
    \[\e[u\]                        Restore Cursor Position
    \[\e[2J\]                       Erase Display
    \[\e[K\]                        Erase Line
    \[\e[<Value>;...;<Value>m\]     Set Graphics Mode

Shell Expansions

Shell code must be wrapped in either ` ... ` or \$( ... ).

    `echo thing | sed 's/thing/ding/'`
    \$(date +%H:%M)

Shell variables must be wrapped in ${ ... } or solely prefixed with $.

    \[${blue}\]@\[${purple}\]
    \[$orange\]\u\[$blue\]\h

Things to Avoid

Only color or cursor movement sequences should be put inside \[ ... \]. Do not do this as PS1Lint will complain:

    \[\n[$PWD]\] \n\[\033[1;34m\]\u  # Causes line wrapping issues.

Instead, change the PS1 to this:

    \n[$PWD] \n\[\033[1;34m\]\u

Resources

Looking for a new PS1?

ps1_lint's People

Contributors

ustasb avatar

Watchers

 avatar  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.