Skip to content

Instantly share code, notes, and snippets.

@borkxs
Forked from ricardobeat/intro.md
Created July 3, 2016 20:20
Show Gist options
  • Select an option

  • Save borkxs/41c086f5d9bd4f57c77527dcd055c8e8 to your computer and use it in GitHub Desktop.

Select an option

Save borkxs/41c086f5d9bd4f57c77527dcd055c8e8 to your computer and use it in GitHub Desktop.

Revisions

  1. @ricardobeat ricardobeat created this gist Jul 12, 2013.
    8 changes: 8 additions & 0 deletions intro.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    Custom bash prompt
    ===================

    ![screenshot](http://f.cl.ly/items/0p152w1d1L183u0p1g03/Image%202013.07.11%2010%3A53%3A41%20PM.png)

    Requires a patched powerline font (see https://gist.github.com/baopham/1838072 or https://github.com/Lokaltog/powerline-fonts).

    Screenshot using the [smyck](color.smyck.org) theme.
    33 changes: 33 additions & 0 deletions ps1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    _ps1_clear() {
    echo -n "\e[0m"
    }
    _ps1_fg() {
    echo -n "\e[38;5;$1m"
    }
    _ps1_bg() {
    echo -n "\e[48;5;$1m"
    }
    _ps1_jobs() {
    if [ `jobs | wc -l` -gt 0 ]; then
    echo -n "$(_ps1_fg 229)\j⃣"
    fi
    }
    _ps1_star() {
    echo -n "$(_ps1_fg $(($RANDOM % 255)))"
    }
    _parse_git_branch() {
    if [[ `git status 2> /dev/null` == *nothing\ to\ commit* ]]; then _ps1_fg 99; else _ps1_fg 32; fi
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
    }
    _update_ps1() {
    local parts=(
    "\n$(_ps1_clear)$(_ps1_bg 236)$(_ps1_fg 236)"
    "$(_ps1_fg 246)\w"
    "$(_parse_git_branch)"
    "$(_ps1_clear)$(_ps1_fg 236)$(_ps1_jobs)"
    "\n$(_ps1_star) $(_ps1_clear)"
    )
    export PS1="${parts[@]}"
    }

    export PROMPT_COMMAND="_update_ps1"