Skip to content

Instantly share code, notes, and snippets.

@concise
Last active April 30, 2017 10:56
Show Gist options
  • Select an option

  • Save concise/7641557 to your computer and use it in GitHub Desktop.

Select an option

Save concise/7641557 to your computer and use it in GitHub Desktop.

Revisions

  1. concise revised this gist Nov 25, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions control-o.bash
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    # A handy j() function, printing some useful info in bash cmdline
    j() {
    printf '\n\e[0;35m%(%Y/%m/%d (%a) %H:%M:%S)T\e[0m ' -1
    @@ -25,5 +24,5 @@ PS1='$PWD \$ \[\033[0m\]'
    # Enable Control-O in readline bash
    stty discard undef

    # Bind Control-O to execute a my j() bash function
    # Bind Control-O to execute my j() bash function
    bind -x '"\C-o": j'
  2. concise created this gist Nov 25, 2013.
    29 changes: 29 additions & 0 deletions control-o.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@

    # A handy j() function, printing some useful info in bash cmdline
    j() {
    printf '\n\e[0;35m%(%Y/%m/%d (%a) %H:%M:%S)T\e[0m ' -1
    printf '\n\e[0;33m%s@%s\e[0m ' "$USER" "${HOSTNAME/.*/}"

    if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
    local GIT_CLEAN=
    local GIT_REF=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
    git diff-index --quiet HEAD && GIT_CLEAN=1

    if [ "$GIT_CLEAN" ]; then
    printf '\e[0;32mgit:%s(clean) ' "$GIT_REF"
    else
    printf '\e[0;31mgit:%s(dirty) ' "$GIT_REF"
    fi
    fi

    printf '\e[0;34m'
    } # end of function j()

    # Simple bash prompt
    PS1='$PWD \$ \[\033[0m\]'

    # Enable Control-O in readline bash
    stty discard undef

    # Bind Control-O to execute a my j() bash function
    bind -x '"\C-o": j'