Skip to content

Instantly share code, notes, and snippets.

@bassu
Created August 1, 2019 21:16
Show Gist options
  • Save bassu/a7bec763a31178a7aeb62ef3fff31ad8 to your computer and use it in GitHub Desktop.
Save bassu/a7bec763a31178a7aeb62ef3fff31ad8 to your computer and use it in GitHub Desktop.
Original bash powerline
#!/usr/bin/env bash
__powerline() {
# Unicode symbols
# readonly PS_SYMBOL_DARWIN=''
readonly PS_SYMBOL_LINUX='$'
readonly PS_SYMBOL_OTHER='%'
readonly GIT_BRANCH_SYMBOL='⑂ '
readonly GIT_BRANCH_CHANGED_SYMBOL='+'
readonly GIT_NEED_PUSH_SYMBOL='⇡'
readonly GIT_NEED_PULL_SYMBOL='⇣'
# Solarized colorscheme
readonly FG_BASE03="\[$(tput setaf 8)\]"
readonly FG_BASE02="\[$(tput setaf 0)\]"
readonly FG_BASE01="\[$(tput setaf 10)\]"
readonly FG_BASE00="\[$(tput setaf 11)\]"
readonly FG_BASE0="\[$(tput setaf 12)\]"
readonly FG_BASE1="\[$(tput setaf 14)\]"
readonly FG_BASE2="\[$(tput setaf 7)\]"
readonly FG_BASE3="\[$(tput setaf 15)\]"
readonly BG_BASE03="\[$(tput setab 8)\]"
readonly BG_BASE02="\[$(tput setab 0)\]"
readonly BG_BASE01="\[$(tput setab 10)\]"
readonly BG_BASE00="\[$(tput setab 11)\]"
readonly BG_BASE0="\[$(tput setab 12)\]"
readonly BG_BASE1="\[$(tput setab 14)\]"
readonly BG_BASE2="\[$(tput setab 7)\]"
readonly BG_BASE3="\[$(tput setab 15)\]"
readonly FG_YELLOW="\[$(tput setaf 3)\]"
readonly FG_ORANGE="\[$(tput setaf 9)\]"
readonly FG_RED="\[$(tput setaf 1)\]"
readonly FG_MAGENTA="\[$(tput setaf 5)\]"
readonly FG_VIOLET="\[$(tput setaf 13)\]"
readonly FG_BLUE="\[$(tput setaf 4)\]"
readonly FG_CYAN="\[$(tput setaf 6)\]"
readonly FG_GREEN="\[$(tput setaf 2)\]"
readonly BG_YELLOW="\[$(tput setab 3)\]"
readonly BG_ORANGE="\[$(tput setab 9)\]"
readonly BG_RED="\[$(tput setab 1)\]"
readonly BG_MAGENTA="\[$(tput setab 5)\]"
readonly BG_VIOLET="\[$(tput setab 13)\]"
readonly BG_BLUE="\[$(tput setab 4)\]"
readonly BG_CYAN="\[$(tput setab 6)\]"
readonly BG_GREEN="\[$(tput setab 2)\]"
readonly DIM="\[$(tput dim)\]"
readonly REVERSE="\[$(tput rev)\]"
readonly RESET="\[$(tput sgr0)\]"
readonly BOLD="\[$(tput bold)\]"
# what OS?
case "$(uname)" in
Darwin)
PS_SYMBOL=$PS_SYMBOL_DARWIN
;;
Linux)
PS_SYMBOL=$PS_SYMBOL_LINUX
;;
*)
PS_SYMBOL=$PS_SYMBOL_OTHER
esac
# fonts in Emacs might not have this private unicode Apple symbol
[[ "$TERM" == "eterm-color" ]] && PS_SYMBOL=$PS_SYMBOL_LINUX
__git_info() {
[ -x "$(which git)" ] || return # git not found
# get current branch name or short SHA1 hash for detached head
local branch="$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --always 2>/dev/null)"
[ -n "$branch" ] || return # git branch not found
local marks
# branch is modified?
[ -n "$(git status --porcelain)" ] && marks+=" $GIT_BRANCH_CHANGED_SYMBOL"
# how many commits local branch is ahead/behind of remote?
local stat="$(git status --porcelain --branch | grep '^##' | grep -o '\[.\+\]$')"
local aheadN="$(echo $stat | grep -o 'ahead \d\+' | grep -o '\d\+')"
local behindN="$(echo $stat | grep -o 'behind \d\+' | grep -o '\d\+')"
[ -n "$aheadN" ] && marks+=" $GIT_NEED_PUSH_SYMBOL$aheadN"
[ -n "$behindN" ] && marks+=" $GIT_NEED_PULL_SYMBOL$behindN"
# print the git branch segment without a trailing newline
printf " $GIT_BRANCH_SYMBOL$branch$marks "
}
ps1() {
# Check the exit code of the previous command and display different
# colors in the prompt accordingly.
if [ $? -eq 0 ]; then
local BG_EXIT="$BG_BLUE"
else
local BG_EXIT="$BG_RED"
fi
PS1="$BG_MAGENTA$FG_BASE3 \W $RESET"
PS1+="$BG_BLUE$FG_BASE3$(__git_info)$RESET"
#PS1+="$BG_EXIT $FG_BASE3 $PS_SYMBOL $RESET "
PS1+="$BG_EXIT $FG_BASE3 $(date '+%H:%M') $RESET "
# Setting title, consistent history and Emacs term visibility
# Added by Bassu
[[ "$TERM" != "eterm-color" ]] && printf '\e]0;%s\a' $HOSTNAME
[[ "$TERM" == "eterm-color" ]] && PS1=" \W $(date '+%H:%M') "
history -a
}
PROMPT_COMMAND="ps1;"
}
__powerline
unset __powerline
@bassu
Copy link
Author

bassu commented Aug 1, 2019

.bashrc

# PATH is in .bash_profile
shopt -s expand_aliases
shopt -s cmdhist
shopt -s histappend
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
export LSCOLORS=exfxcxdxbxexexabagacad
export EDITOR=~/.EDITOR
export HISTTIMEFORMAT='%F %T '
export HISTSIZE=100000000000000
export HISCONTROL=ignoreboth

source ~/.bash-powerline.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment