Skip to content

Instantly share code, notes, and snippets.

@douglaspetrin
Last active October 1, 2019 00:45
Show Gist options
  • Save douglaspetrin/830553d5cc502b0bb14330b02e3e9624 to your computer and use it in GitHub Desktop.
Save douglaspetrin/830553d5cc502b0bb14330b02e3e9624 to your computer and use it in GitHub Desktop.
dougTheme2 - bash version
#!/usr/bin/env bash
#
# One line prompt showing the following configurable information
# for git:
# time (virtual_env) username@hostname pwd git_char|git_branch git_dirty_status|→
#
# The → arrow shows the exit status of the last command:
# - bold green: 0 exit status
# - bold red: non-zero exit status
#
# Example outside git repo:
# 07:45:05 user@host ~ →
#
# Example inside clean git repo:
# 07:45:05 user@host .oh-my-bash ±|master|→
#
# Example inside dirty git repo:
# 07:45:05 user@host .oh-my-bash ±|master ✗|→
#
# Example with virtual environment:
# 07:45:05 (venv) user@host ~ →
#
GREEN=$(tput setaf 190)
PURPLE=$(tput setaf 141)
SCM_NONE_CHAR=''
SCM_THEME_PROMPT_DIRTY=" ${red}✗"
SCM_THEME_PROMPT_CLEAN=""
SCM_THEME_PROMPT_PREFIX="${PURPLE}|"
SCM_THEME_PROMPT_SUFFIX="${PURPLE}|"
SCM_GIT_SHOW_MINIMAL_INFO=true
CLOCK_THEME_PROMPT_PREFIX=''
CLOCK_THEME_PROMPT_SUFFIX=' '
THEME_SHOW_CLOCK=true
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$blue"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"}
VIRTUALENV_THEME_PROMPT_PREFIX='('
VIRTUALENV_THEME_PROMPT_SUFFIX=') '
parse_git_dirty () { [[ $(git status 2> /dev/null | tail -n1 | cut -c 1-17) != "nothing to commit" ]] && echo "*"
}
parse_git_branch () {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
function prompt_command() {
# This needs to be first to save last command return code
local RC="$?"
hostname="${blue}\u@\h"
virtualenv="${GREEN}$(virtualenv_prompt)"
# Set return status color
if [[ ${RC} == 0 ]]; then
ret_status="${green}"
else
ret_status="${bold_red}"
fi
# Append new history lines to history file
history -a
PS1="$(clock_prompt)${virtualenv}\n${hostname} ${yellow}\W $(scm_prompt_char_info)${ret_status}→ ${normal}"
}
safe_append_prompt_command prompt_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment