Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Powerline for Bash in pure Bash script.
* Git: show "*" symbol with uncommited modifications.
* Git: show "↑" symbol and number of commits ahead of remote.
* Git: show "↓" symbol and number of commits behind remote.
* Kubernetes: Show current-context
* Platform-dependent prompt symbols.
* Color-coded prompt symbol according to previous command execution status.
* Use Bash builtin when possible to reduce delay. Delay sucks!
Expand All @@ -26,6 +27,12 @@ And source it in your `.bashrc`

source ~/.bash-powerline.sh

To enable `kubectl` context support, add the `POWERLINE_KUBE` variable to your
profile before sourcing the script:

POWERLINE_KUBE=1
source ~/.bash-powerline.sh

For best result, use [Solarized
colorscheme](https://github.com/altercation/solarized) for your terminal
emulator. Or hack your own colorscheme by modifying the script. It's really
Expand Down
20 changes: 19 additions & 1 deletion bash-powerline.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#!/usr/bin/env bash

if [ -z ${POWERLINE_KUBE+x} ]
then
POWERLINE_KUBE=0
fi
## Uncomment to disable git info
#POWERLINE_GIT=0

__powerline() {
# Colorscheme
readonly RESET='\[\033[m\]'
readonly COLOR_CWD='\[\033[0;34m\]' # blue
readonly COLOR_KUBE='\[\033[0;35m\]' # violet
readonly COLOR_GIT='\[\033[0;36m\]' # cyan
readonly COLOR_SUCCESS='\[\033[0;32m\]' # green
readonly COLOR_FAILURE='\[\033[0;31m\]' # red
Expand All @@ -16,6 +21,8 @@ __powerline() {
readonly SYMBOL_GIT_PUSH='↑'
readonly SYMBOL_GIT_PULL='↓'

readonly SYMBOL_KUBE='❆'

if [[ -z "$PS_SYMBOL" ]]; then
case "$(uname)" in
Darwin) PS_SYMBOL='';;
Expand All @@ -24,6 +31,14 @@ __powerline() {
esac
fi

__kube_info() {
[[ $POWERLINE_KUBE = 0 ]] && return 0
hash kubectl 2>/dev/null || return # kubectl not found

# get current context
local ref=$(kubectl config current-context)
printf " $SYMBOL_KUBE $ref"
}
__git_info() {
[[ $POWERLINE_GIT = 0 ]] && return # disabled
hash git 2>/dev/null || return # git not found
Expand Down Expand Up @@ -75,14 +90,17 @@ __powerline() {
# POC: https://github.com/njhartwell/pw3nage
# Related fix in git-bash: https://github.com/git/git/blob/9d77b0405ce6b471cb5ce3a904368fc25e55643d/contrib/completion/git-prompt.sh#L324
if shopt -q promptvars; then
__powerline_kube_info="$(__kube_info)"
__powerline_git_info="$(__git_info)"
local kube="$COLOR_KUBE\${__powerline_kube_info}$RESET"
local git="$COLOR_GIT\${__powerline_git_info}$RESET"
else
# promptvars is disabled. Avoid creating unnecessary env var.
local kube="$COLOR_KUBE$(__kube_info)$RESET"
local git="$COLOR_GIT$(__git_info)$RESET"
fi

PS1="$cwd$git$symbol"
PS1="$cwd$kube$git\n$symbol"
}

PROMPT_COMMAND="ps1${PROMPT_COMMAND:+; $PROMPT_COMMAND}"
Expand Down