diff --git a/.gitignore b/.gitignore index 6fad6279..a17b6e82 100755 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ bats *.sublime-workspace *.sublime-project enabled/* +/enabled tmp/ diff --git a/README.md b/README.md index 13a991da..ccaa7946 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Includes autocompletion, themes, aliases, custom functions, a few stolen pieces from Steve Losh, and more. Bash-it provides a solid framework for using, developing and maintaining shell scripts and custom commands for your daily work. -If you're using the _Bourne Again Shell_ (Bash) on a regular basis and have been looking for an easy way on how to keep all of these nice little scripts and aliases under control, then Bash-it is for you! +If you're using the _Bourne Again Shell_ (Bash) regularly and have been looking for an easy way on how to keep all of these nice little scripts and aliases under control, then Bash-it is for you! Stop polluting your `~/bin` directory and your `.bashrc` file, fork/clone Bash-it and start hacking away. - [Contributing](#contributing) @@ -58,7 +58,7 @@ Feel free to enable the tools you want to use after the installation. When you run without the `--no-modify-config` switch, the Bash-it installer automatically modifies/replaces your existing config file. Use the `--no-modify-config` switch to avoid unwanted modifications, e.g. if your Bash config file already contains the code that loads Bash-it. -**NOTE**: Keep in mind how Bash load its configuration files, +**NOTE**: Keep in mind how Bash loads its configuration files, `.bash_profile` for login shells (and in macOS in terminal emulators like [Terminal.app](http://www.apple.com/osx/apps/) or [iTerm2](https://www.iterm2.com/)) and `.bashrc` for interactive shells (default mode in most of the GNU/Linux terminal emulators), to ensure that Bash-it is loaded correctly. @@ -77,7 +77,7 @@ Refer to the official [Bash documentation](https://www.gnu.org/software/bash/man ### Install using Docker You can try Bash-it in an isolated environment without changing any local files via a [Docker](https://www.docker.com/) Container. -(Bash Shell v4.4 with Bash-it, [bats](https://github.com/sstephenson/bats) and bash-completion based on [Alpine Linux](https://alpinelinux.org/)). +(Bash Shell v4.4 with Bash-it, [bats](https://github.com/sstephenson/bats),and bash-completion based on [Alpine Linux](https://alpinelinux.org/)). `docker pull ellerbrock/bash-it` @@ -206,7 +206,7 @@ export BASH_IT_THEME="" You can easily preview the themes in your own shell using `BASH_PREVIEW=true bash-it reload`. -If you've created your own custom prompts, we'd love it if you shared with everyone else! Just submit a Pull Request. +If you've created your own custom prompts, we'd love it if you shared them with everyone else! Just submit a Pull Request. You can see theme screenshots on [wiki/Themes](https://github.com/Bash-it/bash-it/wiki/Themes). **NOTE**: Bash-it and some themes use UTF-8 characters, so to avoid strange behavior in your terminal, set your locale to `LC_ALL=en_US.UTF-8` or the equivalent to your language if it isn't American English. @@ -235,7 +235,7 @@ Bash-it will automatically reload itself after activating or deactivating plugin ### Prompt Version Control Check -Bash-it provides prompt themes the ability to check and display version control information for the current directory. +Bash-it provides prompt themes with the ability to check and display version control information for the current directory. The information is retrieved for each directory and can slow down the navigation of projects with a large number of files and folders. Turn version control checking off to prevent slow directory navigation within large projects. @@ -329,6 +329,19 @@ Set `SCM_GIT_SHOW_STASH_INFO` to 'false' to **don't show** it: * `export SCM_GIT_SHOW_STASH_INFO=false` +### Ahead/Behind Count + +When displaying information regarding whether or not the local branch is ahead or behind its remote counterpart, you can opt to display the number of commits ahead/behind. +This is useful if you only care whether or not you are ahead or behind and do not care how far ahead/behind you are. + +Set `SCM_GIT_SHOW_COMMIT_COUNT` to 'true' (the default value) to **show** the count of commits ahead/behind: + +* `export SCM_GIT_SHOW_COMMIT_COUNT=true` + +Set `SCM_GIT_SHOW_COMMIT_COUNT` to 'false' to **don't show** it: + +* `export SCM_GIT_SHOW_COMMIT_COUNT=false` + ### Git user In some environments, it is useful to know the value of the current git user, which is used to mark all new commits. diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index fc95300d..9a65b22a 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -27,7 +27,7 @@ alias gpr='git pull --rebase' alias gpp='git pull && git push' alias gup='git fetch && git rebase' alias gp='git push' -alias gpo='git push origin' +alias gpo='git push origin HEAD' alias gpu='git push --set-upstream' alias gpuo='git push --set-upstream origin' alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)' @@ -43,6 +43,7 @@ alias gca='git commit -v -a' alias gcm='git commit -v -m' alias gcam="git commit -v -am" alias gci='git commit --interactive' +alias gcamd='git commit --amend' alias gb='git branch' alias gba='git branch -a' alias gbt='git branch --track' diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index bd84d322..8653084c 100644 --- a/completion/available/hub.completion.bash +++ b/completion/available/hub.completion.bash @@ -6,8 +6,8 @@ if ! declare -F _git > /dev/null && declare -F _completion_loader > /dev/null; t _completion_loader git fi -# Check that git tab completion is available -if declare -F _git > /dev/null; then +# Check that git tab completion is available and we haven't already set up completion +if declare -F _git > /dev/null && ! declare -F __git_list_all_commands_without_hub > /dev/null; then # Duplicate and rename the 'list_all_commands' function eval "$(declare -f __git_list_all_commands | \ sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" @@ -17,11 +17,16 @@ if declare -F _git > /dev/null; then cat <<-EOF alias pull-request +pr +issue +release fork create +delete browse compare ci-status +sync EOF __git_list_all_commands_without_hub } @@ -213,21 +218,36 @@ EOF esac } - # hub fork [--no-remote] + # hub fork [--no-remote] [--remote-name REMOTE] [--org ORGANIZATION] _git_fork() { - local i c=2 remote=yes + local i c=2 flags="--no-remote --remote-name --org" while [ $c -lt $cword ]; do i="${words[c]}" case "$i" in + --org) + ((c++)) + flags=${flags/$i/} + ;; + --remote-name) + ((c++)) + flags=${flags/$i/} + flags=${flags/--no-remote/} + ;; --no-remote) - unset remote + flags=${flags/$i/} + flags=${flags/--remote-name/} ;; esac ((c++)) done - if [ -n "$remote" ]; then - __gitcomp "--no-remote" - fi + case "$prev" in + --remote-name|--org) + COMPREPLY=() + ;; + *) + __gitcomp "$flags" + ;; + esac } # hub pull-request [-f] [-m |-F |-i |] [-b ] [-h ] [-a ] [-M ] [-l ] diff --git a/lib/helpers.bash b/lib/helpers.bash index 3a47cd4a..e7ef15ba 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -5,6 +5,16 @@ BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN=${BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN:-250 BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION=${BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION:-350} BASH_IT_LOAD_PRIORITY_SEPARATOR="---" +# Handle the different ways of running `sed` without generating a backup file based on OS +# - GNU sed (Linux) uses `-i` +# - BSD sed (macOS) uses `-i ''` +# To use this in Bash-it for inline replacements with `sed`, use the following syntax: +# sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file +BASH_IT_SED_I_PARAMETERS=(-i) +case "$(uname)" in + Darwin*) BASH_IT_SED_I_PARAMETERS=(-i "") +esac + function _command_exists () { _about 'checks for existence of a command' diff --git a/plugins/available/go.plugin.bash b/plugins/available/go.plugin.bash index 910194e5..566d7669 100755 --- a/plugins/available/go.plugin.bash +++ b/plugins/available/go.plugin.bash @@ -3,27 +3,17 @@ cite about-plugin about-plugin 'go environment variables & path configuration' -[ ! command -v go &>/dev/null ] && return +command -v go &>/dev/null || return -function _split_path_reverse() { - local a=( ${@//:/ } ) +function _go_pathmunge_wrap() { + IFS=':' local -a 'a=($1)' local i=${#a[@]} - local r= while [ $i -gt 0 ] ; do i=$(( i - 1 )) - if [ $(( i + 1 )) -eq ${#a[@]} ] ; then - r="${a[i]}" - else - r="${r} ${a[i]}" - fi + pathmunge "${a[i]}/bin" done - echo "$r" } -export GOROOT=${GOROOT:-$(go env GOROOT)} -pathmunge "${GOROOT}/bin" - -export GOPATH=${GOPATH:-$(go env GOPATH)} -for p in $( _split_path_reverse ${GOPATH} ) ; do - pathmunge "${p}/bin" -done +export GOROOT="${GOROOT:-$(go env GOROOT)}" +export GOPATH="${GOPATH:-$(go env GOPATH)}" +_go_pathmunge_wrap "${GOPATH}:${GOROOT}" diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index 841122ca..b6b9d1f0 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -5,6 +5,8 @@ if $(command -v pygmentize &> /dev/null) ; then # get the full paths to binaries CAT_BIN=$(which cat) LESS_BIN=$(which less) + BASH_IT_CCAT_STYLE="${BASH_IT_CCAT_STYLE:=default}" + BASH_IT_CLESS_STYLE="${BASH_IT_CLESS_STYLE:=default}" # pigmentize cat and less outputs - call them ccat and cless to avoid that # especially cat'ed output in scripts gets mangled with pygemtized meta characters @@ -15,7 +17,7 @@ if $(command -v pygmentize &> /dev/null) ; then example 'cat mysite/manage.py dir/text-file.txt' for var; do - pygmentize "$var" 2>/dev/null || "$CAT_BIN" "$var"; + pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$var" 2>/dev/null || "$CAT_BIN" "$var"; done } @@ -24,6 +26,6 @@ if $(command -v pygmentize &> /dev/null) ; then about 'it pigments the file passed in and passes it to less for pagination' param '$1: the file to paginate with less' example 'less mysite/manage.py' - pygmentize -g $* | "$LESS_BIN" -R + pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g $* | "$LESS_BIN" -R } fi diff --git a/plugins/available/node.plugin.bash b/plugins/available/node.plugin.bash index f0467cef..429ca458 100644 --- a/plugins/available/node.plugin.bash +++ b/plugins/available/node.plugin.bash @@ -1,7 +1,7 @@ cite about-plugin about-plugin 'Node.js helper functions' -pathmunge ./node_modules/.bin +pathmunge "./node_modules/.bin" "after" # Make sure the global npm prefix is on the path -[[ `which npm` ]] && pathmunge $(npm config get prefix)/bin +[[ `which npm 2>/dev/null` ]] && pathmunge "$(npm config get prefix)/bin" "after" diff --git a/plugins/available/proxy.plugin.bash b/plugins/available/proxy.plugin.bash index 4f4bcbac..f2458e3f 100644 --- a/plugins/available/proxy.plugin.bash +++ b/plugins/available/proxy.plugin.bash @@ -121,6 +121,7 @@ npm-show-proxy () echo "===" echo "npm HTTP proxy: " `npm config get proxy` echo "npm HTTPS proxy: " `npm config get https-proxy` + echo "npm proxy exceptions: " `npm config get noproxy` fi } @@ -132,6 +133,7 @@ npm-disable-proxy () if $(command -v npm &> /dev/null) ; then npm config delete proxy npm config delete https-proxy + npm config delete noproxy echo "Disabled npm proxy settings" fi } @@ -143,10 +145,12 @@ npm-enable-proxy () local my_http_proxy=${1:-$BASH_IT_HTTP_PROXY} local my_https_proxy=${2:-$BASH_IT_HTTPS_PROXY} + local my_no_proxy=${3:-$BASH_IT_NO_PROXY} if $(command -v npm &> /dev/null) ; then npm config set proxy $my_http_proxy npm config set https-proxy $my_https_proxy + npm config set noproxy $my_no_proxy echo "Enabled npm proxy settings" fi } @@ -370,7 +374,7 @@ ssh-disable-proxy () group 'proxy' if [ -f ~/.ssh/config ] ; then - sed -e's/^.*ProxyCommand/# ProxyCommand/' -i "" ~/.ssh/config + sed -e's/^.*ProxyCommand/# ProxyCommand/' "${BASH_IT_SED_I_PARAMETERS[@]}" ~/.ssh/config echo "Disabled SSH config proxy settings" fi } @@ -382,7 +386,7 @@ ssh-enable-proxy () group 'proxy' if [ -f ~/.ssh/config ] ; then - sed -e's/# ProxyCommand/ ProxyCommand/' -i "" ~/.ssh/config + sed -e's/# ProxyCommand/ ProxyCommand/' "${BASH_IT_SED_I_PARAMETERS[@]}" ~/.ssh/config echo "Enabled SSH config proxy settings" fi } diff --git a/plugins/available/pyenv.plugin.bash b/plugins/available/pyenv.plugin.bash index dced31a8..4d8db4fb 100644 --- a/plugins/available/pyenv.plugin.bash +++ b/plugins/available/pyenv.plugin.bash @@ -4,7 +4,7 @@ about-plugin 'load pyenv, if you are using it' export PYENV_ROOT="$HOME/.pyenv" pathmunge "$PYENV_ROOT/bin" -[[ `which pyenv` ]] && eval "$(pyenv init - bash)" +[[ `which pyenv 2>/dev/null` ]] && eval "$(pyenv init - bash)" #Load pyenv virtualenv if the virtualenv plugin is installed. if pyenv virtualenv-init - &> /dev/null; then diff --git a/plugins/available/rbenv.plugin.bash b/plugins/available/rbenv.plugin.bash index ecba0c89..2b01669d 100644 --- a/plugins/available/rbenv.plugin.bash +++ b/plugins/available/rbenv.plugin.bash @@ -4,4 +4,4 @@ about-plugin 'load rbenv, if you are using it' export RBENV_ROOT="$HOME/.rbenv" pathmunge "$RBENV_ROOT/bin" -[[ `which rbenv` ]] && eval "$(rbenv init - bash)" +[[ `which rbenv 2>/dev/null` ]] && eval "$(rbenv init - bash)" diff --git a/plugins/available/ssh.plugin.bash b/plugins/available/ssh.plugin.bash index f670b98c..51587b29 100644 --- a/plugins/available/ssh.plugin.bash +++ b/plugins/available/ssh.plugin.bash @@ -17,3 +17,10 @@ function sshlist() { awk '$1 ~ /Host$/ {for (i=2; i<=NF; i++) print $i}' ~/.ssh/config } + +function ssh-add-all() { + about 'add all ssh private keys to agent' + group 'ssh' + + grep -slR "PRIVATE" ~/.ssh | xargs ssh-add +} diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index e2b27e02..02806205 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -1,44 +1,53 @@ #!/usr/bin/env bats -#load ../test_helper +load ../test_helper load ../../lib/helpers load ../../lib/composure -load ../../plugins/available/go.plugin -@test 'plugins go: reverse path: single entry' { - run _split_path_reverse '/foo' - echo "output = ${output}" - [ "$output" = "/foo" ] -} - -@test 'plugins go: reverse path: single entry, colon empty' { - run _split_path_reverse '/foo:' - echo "output = ${output}" - [ "$output" = "/foo" ] -} - -@test 'plugins go: reverse path: single entry, colon whitespace' { - run _split_path_reverse '/foo: ' - echo "output = ${output}" - [ "$output" = "/foo" ] -} - -@test 'plugins go: reverse path: multiple entries' { - run _split_path_reverse '/foo:/bar' - echo "output = ${output}" - [ "$output" = "/bar /foo" ] +@test 'ensure _go_pathmunge_wrap is defined' { + load ../../plugins/available/go.plugin + run type -t _go_pathmunge_wrap + assert_line 'function' } @test 'plugins go: single entry in GOPATH' { export GOPATH="/foo" + export GOROOT="/baz" load ../../plugins/available/go.plugin - echo "$(echo $PATH | cut -d':' -f1,2)" - [ "$(echo $PATH | cut -d':' -f1)" = "/foo/bin" ] + assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/baz/bin" +} + +@test 'plugins go: single entry in GOPATH, with space' { + export GOPATH="/foo bar" + export GOROOT="/baz" + load ../../plugins/available/go.plugin + assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo bar/bin:/baz/bin" +} + +@test 'plugins go: single entry in GOPATH, with escaped space' { + export GOPATH="/foo\ bar" + export GOROOT="/baz" + load ../../plugins/available/go.plugin + assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo\ bar/bin:/baz/bin" } @test 'plugins go: multiple entries in GOPATH' { export GOPATH="/foo:/bar" + export GOROOT="/baz" load ../../plugins/available/go.plugin - echo "$(echo $PATH | cut -d':' -f1,2)" - [ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/bar/bin" ] + assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/bar/bin:/baz/bin" +} + +@test 'plugins go: multiple entries in GOPATH, with space' { + export GOPATH="/foo:/foo bar" + export GOROOT="/baz" + load ../../plugins/available/go.plugin + assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/foo bar/bin:/baz/bin" +} + +@test 'plugins go: multiple entries in GOPATH, with escaped space' { + export GOPATH="/foo:/foo\ bar" + export GOROOT="/baz" + load ../../plugins/available/go.plugin + assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/foo\ bar/bin:/baz/bin" } diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index 997b1a59..940121cc 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -72,6 +72,8 @@ setup_repo_with_upstream() { git clone "$remote" clone cd clone + SCM_GIT_SHOW_COMMIT_COUNT=true + git_prompt_vars assert_equal "$SCM_BRANCH" "${pre}" @@ -148,6 +150,7 @@ setup_repo_with_upstream() { pushd "${repo}" SCM_GIT_SHOW_REMOTE_INFO=true + SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" @@ -168,6 +171,7 @@ setup_repo_with_upstream() { pushd "${repo}" SCM_GIT_SHOW_REMOTE_INFO=auto + SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars assert_equal "$SCM_BRANCH" "${pre}${post}" @@ -204,6 +208,7 @@ setup_repo_with_upstream() { git remote add third-remote "$(mktemp -d)" SCM_GIT_SHOW_REMOTE_INFO=false + SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars assert_equal "$SCM_BRANCH" "${pre}${post}" @@ -225,6 +230,7 @@ setup_repo_with_upstream() { pushd "${repo}" SCM_GIT_SHOW_REMOTE_INFO=true + SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars assert_equal "$SCM_BRANCH" "${pre} → my-remote${post}" diff --git a/themes/agnoster/agnoster.theme.bash b/themes/agnoster/agnoster.theme.bash new file mode 100644 index 00000000..dae991cf --- /dev/null +++ b/themes/agnoster/agnoster.theme.bash @@ -0,0 +1,423 @@ +#!/usr/bin/env bash +# vim: ft=bash ts=2 sw=2 sts=2 +# +# agnoster's Theme - https://gist.github.com/3712874 +# A Powerline-inspired theme for BASH +# +# (Converted from ZSH theme by Kenny Root) +# https://gist.github.com/kruton/8345450 +# +# Updated & fixed by Erik Selberg erik@selberg.org 1/14/17 +# Tested on MacOSX, Ubuntu, Amazon Linux +# Bash v3 and v4 +# +# # README +# +# In order for this theme to render correctly, you will need a +# [Powerline-patched font](https://gist.github.com/1595572). +# I recommend: https://github.com/powerline/fonts.git +# > git clone https://github.com/powerline/fonts.git fonts +# > cd fonts +# > install.sh + +# In addition, I recommend the +# [Solarized theme](https://github.com/altercation/solarized/) and, if you're +# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app - +# it has significantly better color fidelity. + +# Install: + +# I recommend the following: +# $ cd home +# $ mkdir -p .bash/themes/agnoster-bash +# $ git clone https://github.com/speedenator/agnoster-bash.git .bash/themes/agnoster-bash + +# then add the following to your .bashrc: + +# export THEME=$HOME/.bash/themes/agnoster-bash/agnoster.bash +# if [[ -f $THEME ]]; then +# export DEFAULT_USER=`whoami` +# source $THEME +# fi + +# +# # Goals +# +# The aim of this theme is to only show you *relevant* information. Like most +# prompts, it will only show git information when in a git working directory. +# However, it goes a step further: everything from the current user and +# hostname to whether the last call exited with an error to whether background +# jobs are running in this shell will all be displayed automatically when +# appropriate. + +# Generally speaking, this script has limited support for right +# prompts (ala powerlevel9k on zsh), but it's pretty problematic in Bash. +# The general pattern is to write out the right prompt, hit \r, then +# write the left. This is problematic for the following reasons: +# - Doesn't properly resize dynamically when you resize the terminal +# - Changes to the prompt (like clearing and re-typing, super common) deletes the prompt +# - Getting the right alignment via columns / tput cols is pretty problematic (and is a bug in this version) +# - Bash prompt escapes (like \h or \w) don't get interpolated +# +# all in all, if you really, really want right-side prompts without a +# ton of work, recommend going to zsh for now. If you know how to fix this, +# would appreciate it! + +# note: requires bash v4+... Mac users - you often have bash3. +# 'brew install bash' will set you free +PROMPT_DIRTRIM=2 # bash4 and above + +###################################################################### +DEBUG=0 +debug() { + if [[ ${DEBUG} -ne 0 ]]; then + >&2 echo -e $* + fi +} + +###################################################################### +### Segment drawing +# A few utility functions to make it easy and re-usable to draw segmented prompts + +CURRENT_BG='NONE' +CURRENT_RBG='NONE' +SEGMENT_SEPARATOR='' +RIGHT_SEPARATOR='' +LEFT_SUBSEG='' +RIGHT_SUBSEG='' + +text_effect() { + case "$1" in + reset) echo 0;; + bold) echo 1;; + underline) echo 4;; + esac +} + +# to add colors, see +# http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux +# under the "256 (8-bit) Colors" section, and follow the example for orange below +fg_color() { + case "$1" in + black) echo 30;; + red) echo 31;; + green) echo 32;; + yellow) echo 33;; + blue) echo 34;; + magenta) echo 35;; + cyan) echo 36;; + white) echo 37;; + orange) echo 38\;5\;166;; + esac +} + +bg_color() { + case "$1" in + black) echo 40;; + red) echo 41;; + green) echo 42;; + yellow) echo 43;; + blue) echo 44;; + magenta) echo 45;; + cyan) echo 46;; + white) echo 47;; + orange) echo 48\;5\;166;; + esac; +} + +# TIL: declare is global not local, so best use a different name +# for codes (mycodes) as otherwise it'll clobber the original. +# this changes from BASH v3 to BASH v4. +ansi() { + local seq + declare -a mycodes=("${!1}") + + debug "ansi: ${!1} all: $* aka ${mycodes[@]}" + + seq="" + for ((i = 0; i < ${#mycodes[@]}; i++)); do + if [[ -n $seq ]]; then + seq="${seq};" + fi + seq="${seq}${mycodes[$i]}" + done + debug "ansi debug:" '\\[\\033['${seq}'m\\]' + echo -ne '\[\033['${seq}'m\]' + # PR="$PR\[\033[${seq}m\]" +} + +ansi_single() { + echo -ne '\[\033['$1'm\]' +} + +# Begin a segment +# Takes two arguments, background and foreground. Both can be omitted, +# rendering default background/foreground. +prompt_segment() { + local bg fg + declare -a codes + + debug "Prompting $1 $2 $3" + + # if commented out from kruton's original... I'm not clear + # if it did anything, but it messed up things like + # prompt_status - Erik 1/14/17 + + # if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then + codes=("${codes[@]}" $(text_effect reset)) + # fi + if [[ -n $1 ]]; then + bg=$(bg_color $1) + codes=("${codes[@]}" $bg) + debug "Added $bg as background to codes" + fi + if [[ -n $2 ]]; then + fg=$(fg_color $2) + codes=("${codes[@]}" $fg) + debug "Added $fg as foreground to codes" + fi + + debug "Codes: " + # declare -p codes + + if [[ $CURRENT_BG != NONE && $1 != $CURRENT_BG ]]; then + declare -a intermediate=($(fg_color $CURRENT_BG) $(bg_color $1)) + debug "pre prompt " $(ansi intermediate[@]) + PR="$PR $(ansi intermediate[@])$SEGMENT_SEPARATOR" + debug "post prompt " $(ansi codes[@]) + PR="$PR$(ansi codes[@]) " + else + debug "no current BG, codes is $codes[@]" + PR="$PR$(ansi codes[@]) " + fi + CURRENT_BG=$1 + [[ -n $3 ]] && PR="$PR$3" +} + +# End the prompt, closing any open segments +prompt_end() { + if [[ -n $CURRENT_BG ]]; then + declare -a codes=($(text_effect reset) $(fg_color $CURRENT_BG)) + PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR" + fi + declare -a reset=($(text_effect reset)) + PR="$PR $(ansi reset[@])" + CURRENT_BG='' +} + +### virtualenv prompt +prompt_virtualenv() { + if [[ -n $VIRTUAL_ENV ]]; then + color=cyan + prompt_segment $color $PRIMARY_FG + prompt_segment $color white "$(basename $VIRTUAL_ENV)" + fi +} + + +### Prompt components +# Each component will draw itself, and hide itself if no information needs to be shown + +# Context: user@hostname (who am I and where am I) +prompt_context() { + local user=`whoami` + + if [[ $user != $DEFAULT_USER || -n $SSH_CLIENT ]]; then + prompt_segment black default "$user@\h" + fi +} + +# prints history followed by HH:MM, useful for remembering what +# we did previously +prompt_histdt() { + prompt_segment black default "\! [\A]" +} + + +git_status_dirty() { + dirty=$(git status -s 2> /dev/null | tail -n 1) + [[ -n $dirty ]] && echo " ●" +} + +# Git: branch/detached head, dirty status +prompt_git() { + local ref dirty + if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then + ZSH_THEME_GIT_PROMPT_DIRTY='±' + dirty=$(git_status_dirty) + ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)" + if [[ -n $dirty ]]; then + prompt_segment yellow black + else + prompt_segment green black + fi + PR="$PR${ref/refs\/heads\// }$dirty" + fi +} + +# Dir: current working directory +prompt_dir() { + prompt_segment blue black '\w' +} + +# Status: +# - was there an error +# - am I root +# - are there background jobs? +prompt_status() { + local symbols + symbols=() + [[ $RETVAL -ne 0 ]] && symbols+="$(ansi_single $(fg_color red))✘" + [[ $UID -eq 0 ]] && symbols+="$(ansi_single $(fg_color yellow))⚡" + [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="$(ansi_single $(fg_color cyan))⚙" + + [[ -n "$symbols" ]] && prompt_segment black default "$symbols" +} + +###################################################################### +# +# experimental right prompt stuff +# requires setting prompt_foo to use PRIGHT vs PR +# doesn't quite work per above + +rightprompt() { + printf "%*s" $COLUMNS "$PRIGHT" +} + +# quick right prompt I grabbed to test things. +__command_rprompt() { + local times= n=$COLUMNS tz + for tz in ZRH:Europe/Zurich PIT:US/Eastern \ + MTV:US/Pacific TOK:Asia/Tokyo; do + [ $n -gt 40 ] || break + times="$times ${tz%%:*}\e[30;1m:\e[0;36;1m" + times="$times$(TZ=${tz#*:} date +%H:%M)\e[0m" + n=$(( $n - 10 )) + done + [ -z "$times" ] || printf "%${n}s$times\\r" '' +} +# PROMPT_COMMAND=__command_rprompt + +# this doens't wrap code in \[ \] +ansi_r() { + local seq + declare -a mycodes2=("${!1}") + + debug "ansi: ${!1} all: $* aka ${mycodes2[@]}" + + seq="" + for ((i = 0; i < ${#mycodes2[@]}; i++)); do + if [[ -n $seq ]]; then + seq="${seq};" + fi + seq="${seq}${mycodes2[$i]}" + done + debug "ansi debug:" '\\[\\033['${seq}'m\\]' + echo -ne '\033['${seq}'m' + # PR="$PR\[\033[${seq}m\]" +} + +# Begin a segment on the right +# Takes two arguments, background and foreground. Both can be omitted, +# rendering default background/foreground. +prompt_right_segment() { + local bg fg + declare -a codes + + debug "Prompt right" + debug "Prompting $1 $2 $3" + + # if commented out from kruton's original... I'm not clear + # if it did anything, but it messed up things like + # prompt_status - Erik 1/14/17 + + # if [[ -z $1 || ( -z $2 && $2 != default ) ]]; then + codes=("${codes[@]}" $(text_effect reset)) + # fi + if [[ -n $1 ]]; then + bg=$(bg_color $1) + codes=("${codes[@]}" $bg) + debug "Added $bg as background to codes" + fi + if [[ -n $2 ]]; then + fg=$(fg_color $2) + codes=("${codes[@]}" $fg) + debug "Added $fg as foreground to codes" + fi + + debug "Right Codes: " + # declare -p codes + + # right always has a separator + # if [[ $CURRENT_RBG != NONE && $1 != $CURRENT_RBG ]]; then + # $CURRENT_RBG= + # fi + declare -a intermediate2=($(fg_color $1) $(bg_color $CURRENT_RBG) ) + # PRIGHT="$PRIGHT---" + debug "pre prompt " $(ansi_r intermediate2[@]) + PRIGHT="$PRIGHT$(ansi_r intermediate2[@])$RIGHT_SEPARATOR" + debug "post prompt " $(ansi_r codes[@]) + PRIGHT="$PRIGHT$(ansi_r codes[@]) " + # else + # debug "no current BG, codes is $codes[@]" + # PRIGHT="$PRIGHT$(ansi codes[@]) " + # fi + CURRENT_RBG=$1 + [[ -n $3 ]] && PRIGHT="$PRIGHT$3" +} + +###################################################################### +## Emacs prompt --- for dir tracking +# stick the following in your .emacs if you use this: + +# (setq dirtrack-list '(".*DIR *\\([^ ]*\\) DIR" 1 nil)) +# (defun dirtrack-filter-out-pwd-prompt (string) +# "dirtrack-mode doesn't remove the PWD match from the prompt. This does." +# ;; TODO: support dirtrack-mode's multiline regexp. +# (if (and (stringp string) (string-match (first dirtrack-list) string)) +# (replace-match "" t t string 0) +# string)) +# (add-hook 'shell-mode-hook +# #'(lambda () +# (dirtrack-mode 1) +# (add-hook 'comint-preoutput-filter-functions +# 'dirtrack-filter-out-pwd-prompt t t))) + +prompt_emacsdir() { + # no color or other setting... this will be deleted per above + PR="DIR \w DIR$PR" +} + +###################################################################### +## Main prompt + +build_prompt() { + [[ ! -z ${AG_EMACS_DIR+x} ]] && prompt_emacsdir + prompt_status + #[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt + [[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context + prompt_virtualenv + prompt_dir + prompt_git + prompt_end +} + +# from orig... +# export PS1='$(ansi_single $(text_effect reset)) $(build_prompt) ' +# this doesn't work... new model: create a prompt via a PR variable and +# use that. + +set_bash_prompt() { + RETVAL=$? + PR="" + PRIGHT="" + CURRENT_BG=NONE + PR="$(ansi_single $(text_effect reset))" + build_prompt + + # uncomment below to use right prompt + # PS1='\[$(tput sc; printf "%*s" $COLUMNS "$PRIGHT"; tput rc)\]'$PR + PS1=$PR +} + +PROMPT_COMMAND=set_bash_prompt diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 430fb60d..8d90f043 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -33,6 +33,7 @@ SCM_GIT_IGNORE_UNTRACKED=${SCM_GIT_IGNORE_UNTRACKED:=false} SCM_GIT_SHOW_CURRENT_USER=${SCM_GIT_SHOW_CURRENT_USER:=false} SCM_GIT_SHOW_MINIMAL_INFO=${SCM_GIT_SHOW_MINIMAL_INFO:=false} SCM_GIT_SHOW_STASH_INFO=${SCM_GIT_SHOW_STASH_INFO:=true} +SCM_GIT_SHOW_COMMIT_COUNT=${SCM_GIT_SHOW_COMMIT_COUNT:=true} SCM_GIT='git' SCM_GIT_CHAR='±' @@ -79,15 +80,20 @@ RBENV_THEME_PROMPT_SUFFIX='|' RBFU_THEME_PROMPT_PREFIX=' |' RBFU_THEME_PROMPT_SUFFIX='|' +GIT_EXE=`which git 2> /dev/null || true` +P4_EXE=`which p4 2> /dev/null || true` +HG_EXE=`which hg 2> /dev/null || true` +SVN_EXE=`which svn 2> /dev/null || true` + function scm { if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE - elif [[ -f .git/HEAD ]] && which git &> /dev/null; then SCM=$SCM_GIT - elif which git &> /dev/null && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT - elif which p4 &> /dev/null && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then SCM=$SCM_P4 - elif [[ -d .hg ]] && which hg &> /dev/null; then SCM=$SCM_HG - elif which hg &> /dev/null && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG - elif [[ -d .svn ]] && which svn &> /dev/null; then SCM=$SCM_SVN - elif which svn &> /dev/null && [[ -n "$(svn info --show-item wc-root 2>/dev/null)" ]]; then SCM=$SCM_SVN + elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then SCM=$SCM_GIT + elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT + elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then SCM=$SCM_P4 + elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then SCM=$SCM_HG + elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG + elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then SCM=$SCM_SVN + elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2>/dev/null)" ]]; then SCM=$SCM_SVN else SCM=$SCM_NONE fi } @@ -181,8 +187,14 @@ function git_prompt_vars { fi IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)" - [[ "${commits_ahead}" -gt 0 ]] && SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}${commits_ahead}" - [[ "${commits_behind}" -gt 0 ]] && SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_BEHIND_CHAR}${commits_behind}" + if [[ "${commits_ahead}" -gt 0 ]]; then + SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}" + [[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_ahead}" + fi + if [[ "${commits_behind}" -gt 0 ]]; then + SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_BEHIND_CHAR}" + [[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_behind}" + fi if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then local stash_count @@ -503,4 +515,4 @@ function safe_append_prompt_command { function _save-and-reload-history() { local autosave=${1:-0} [[ $autosave -eq 1 ]] && history -a && history -c && history -r -} \ No newline at end of file +} diff --git a/themes/clean/clean.theme.bash b/themes/clean/clean.theme.bash index c479a041..0082d671 100644 --- a/themes/clean/clean.theme.bash +++ b/themes/clean/clean.theme.bash @@ -13,7 +13,7 @@ function prompt_command() { if [ "$(whoami)" = root ]; then no_color=$red; else no_color=$white; fi - PS1="${no_color}\u${reset_color}:${blue}\W/${reset_color} \[$(scm_prompt_info)\]${normal}$ " + PS1="${no_color}\u${reset_color}:${blue}\W/${reset_color} $(scm_prompt_info)${normal}$ " } safe_append_prompt_command prompt_command diff --git a/themes/gitline/gitline.theme.bash b/themes/gitline/gitline.theme.bash new file mode 100644 index 00000000..995b8c07 --- /dev/null +++ b/themes/gitline/gitline.theme.bash @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +. "$BASH_IT/themes/gitline/powerline.base.bash" + +#For the logo(Uncomment if you want a logo before your name) +#PROMPT_DISTRO_LOGO="💻" +PROMPT_DISTRO_LOGO_COLOR=15 +PROMPT_DISTRO_LOGO_COLORBG=52 + +#Prompt Seperator Charactors +PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""} +POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:=""} + +#USER INFO CHARACTERS +USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=" "} +USER_INFO_SUDO_CHAR=${POWERLINE_USER_INFO_SUDO_CHAR:=" "} +USER_INFO_THEME_PROMPT_COLOR=91 +USER_INFO_THEME_PROMPT_COLOR_SUDO=1 + +#PYTHON VENV +PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:=" "} +CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="❲c❳ "} +PYTHON_VENV_THEME_PROMPT_COLOR=17 + +#GIT Prompt Symbols +SCM_NONE_CHAR="" +SCM_GIT_CHAR=${POWERLINE_SCM_GIT_CHAR:=" "} +SCM_HG_CHAR=${POWERLINE_SCM_HG_CHAR:="☿ "} +SCM_THEME_PROMPT_CLEAN=" ✓ " +SCM_THEME_PROMPT_DIRTY=" ⨯ " +SCM_THEME_PROMPT_COLOR=91 +SCM_THEME_PROMPT_CLEAN_COLOR=41 +SCM_THEME_PROMPT_DIRTY_COLOR=94 +SCM_THEME_PROMPT_STAGED_COLOR=220 #52 +SCM_THEME_PROMPT_UNSTAGED_COLOR=81 + +#Ruby Prompt Symbols +RVM_THEME_PROMPT_PREFIX="" +RVM_THEME_PROMPT_SUFFIX="" +RBENV_THEME_PROMPT_PREFIX="" +RBENV_THEME_PROMPT_SUFFIX="" +RUBY_THEME_PROMPT_COLOR=161 +RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "} + +CWD_THEME_DIR_SEPARATOR="" +CWD_THEME_DIR_SEPARATOR_COLOR=52 +CWD_THEME_PROMPT_COLOR=252 + +HOST_THEME_PROMPT_COLOR=88 + +LAST_STATUS_THEME_PROMPT_COLOR=52 + +#Clock +CLOCK_THEME_PROMPT_COLOR=240 + +#For Battery Plugin +BATTERY_AC_CHAR=${BATTERY_AC_CHAR:="⚡"} +BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=70 +BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=208 +BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160 + +THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} + +IN_VIM_THEME_PROMPT_COLOR=245 +IN_VIM_THEME_PROMPT_TEXT="vim" + + +safe_append_prompt_command __powerline_prompt_command diff --git a/themes/gitline/powerline.base.bash b/themes/gitline/powerline.base.bash new file mode 100644 index 00000000..45387b02 --- /dev/null +++ b/themes/gitline/powerline.base.bash @@ -0,0 +1,228 @@ +# Sudo check after every command +THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} + +#To set color for foreground and background +function set_color { + set +u + if [[ "${1}" != "-" ]]; then + fg="38;5;${1}" + fi + if [[ "${2}" != "-" ]]; then + bg="48;5;${2}" + [[ -n "${fg}" ]] && bg=";${bg}" + fi + echo -e "\[\033[${fg}${bg}m\]" +} + +#Customising User Info Segment +function __powerline_user_info_prompt { + local user_info="${USER}" + local color=${USER_INFO_THEME_PROMPT_COLOR} + local fg_color=15 + + if [[ "${THEME_CHECK_SUDO}" = true ]]; then + if sudo -n uptime 2>&1 | grep -q "load"; then + color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + fi + fi + + case "${POWERLINE_PROMPT_USER_INFO_MODE}" in + "sudo") + if [[ "${color}" = "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then + user_info="👑 ${USER}" + fg_color=227 + color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + fi + ;; + *) + if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then + user_info="${USER_INFO_SSH_CHAR}${USER}" + else + user_info="${USER}" + fi + ;; + esac + [[ -n "${user_info}" ]] && echo "${user_info}|${color}|${fg_color}" +} + +#Customising Ruby Prompt +function __powerline_ruby_prompt { + local ruby_version="" + local fg_color=206 + + if _command_exists rvm; then + ruby_version="$(rvm_version_prompt)" + elif _command_exists rbenv; then + ruby_version=$(rbenv_version_prompt) + fi + + [[ -n "${ruby_version}" ]] && echo "${RUBY_CHAR}${ruby_version}|${RUBY_THEME_PROMPT_COLOR}|${fg_color}" +} + +#Customising Python (venv) Prompt +function __powerline_python_venv_prompt { + set +u + local python_venv="" + local fg_color=206 + + if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then + python_venv="${CONDA_DEFAULT_ENV}" + PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR} + elif [[ -n "${VIRTUAL_ENV}" ]]; then + python_venv=$(basename "${VIRTUAL_ENV}") + fi + + [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}|${fg_color}" +} + +#Customising SCM(GIT) Prompt +function __powerline_scm_prompt { + local color="" + local scm_prompt="" + local fg_color=206 + + scm_prompt_vars + + + if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then + if [[ "${SCM_DIRTY}" -eq 3 ]]; then + color=${SCM_THEME_PROMPT_STAGED_COLOR} + fg_color=124 + elif [[ "${SCM_DIRTY}" -eq 2 ]]; then + color=${SCM_THEME_PROMPT_UNSTAGED_COLOR} + fg_color=56 + elif [[ "${SCM_DIRTY}" -eq 1 ]]; then + color=${SCM_THEME_PROMPT_DIRTY_COLOR} + fg_color=118 + elif [[ "${SCM_DIRTY}" -eq 0 ]]; then + color=${SCM_THEME_PROMPT_CLEAN_COLOR} + fg_color=16 + else + color=${SCM_THEME_PROMPT_COLOR} + fg_color=255 + fi + if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + elif [[ "${SCM_P4_CHAR}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + elif [[ "${SCM_HG_CHAR}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + fi + echo "${scm_prompt}${scm}|${color}|${fg_color}" + fi +} + +function __powerline_cwd_prompt { + local cwd=$(pwd | sed "s|^${HOME}|~|") + local fg_color=16 + + echo "${cwd}|${CWD_THEME_PROMPT_COLOR}|${fg_color}" +} + +function __powerline_hostname_prompt { + local fg_color=206 + + echo "$(hostname -s)|${HOST_THEME_PROMPT_COLOR}|${fg_color}" +} + +function __powerline_wd_prompt { + local fg_color=206 + + echo "\W|${CWD_THEME_PROMPT_COLOR}|${fg_color}" +} + +function __powerline_clock_prompt { + local fg_color=206 + + echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}|${fg_color}" +} + +function __powerline_battery_prompt { + local color="" + local battery_status="$(battery_percentage 2> /dev/null)" + local fg_color=255 + + if [[ -z "${battery_status}" ]] || [[ "${battery_status}" = "-1" ]] || [[ "${battery_status}" = "no" ]]; then + true + else + if [[ "$((10#${battery_status}))" -le 5 ]]; then + color="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" + elif [[ "$((10#${battery_status}))" -le 25 ]]; then + color="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR}" + else + color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" + fi + ac_adapter_connected && battery_status="${BATTERY_AC_CHAR}${battery_status}" + echo "${battery_status}%|${color}|${fg_color}" + fi +} + +function __powerline_in_vim_prompt { + local fg_color=206 + + if [ -n "$VIMRUNTIME" ]; then + echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}|${fg_color}" + fi +} + +function __powerline_aws_profile_prompt { + local fg_color=206 + + if [[ -n "${AWS_PROFILE}" ]]; then + echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}|${fg_color}" + fi +} + +function __powerline_left_segment { + local OLD_IFS="${IFS}"; IFS="|" + local params=( $1 ) + IFS="${OLD_IFS}" + local separator_char="${POWERLINE_LEFT_SEPARATOR}" + local separator="" + local fg_color=206 + + #for seperator character + if [[ "${SEGMENTS_AT_LEFT}" -gt 0 ]]; then + separator="$(set_color ${LAST_SEGMENT_COLOR} ${params[1]})${separator_char}${normal}" + fi + #change here to cahnge fg color + LEFT_PROMPT+="${separator}$(set_color ${params[2]} ${params[1]}) ${params[0]} ${normal}" + #seperator char color = current bg + LAST_SEGMENT_COLOR=${params[1]} + (( SEGMENTS_AT_LEFT += 1 )) +} + +function __powerline_last_status_prompt { + [[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR}" +} + +function __powerline_prompt_command { + local last_status="$?" ## always the first + local separator_char="${POWERLINE_PROMPT_CHAR}" + + LEFT_PROMPT="" + SEGMENTS_AT_LEFT=0 + LAST_SEGMENT_COLOR="" + + + if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then + LEFT_PROMPT+="$(set_color ${PROMPT_DISTRO_LOGO_COLOR} ${PROMPT_DISTRO_LOGO_COLORBG})${PROMPT_DISTRO_LOGO}$(set_color - -)" + fi + + ## left prompt ## + for segment in $POWERLINE_PROMPT; do + local info="$(__powerline_${segment}_prompt)" + [[ -n "${info}" ]] && __powerline_left_segment "${info}" + done + + [[ "${last_status}" -ne 0 ]] && __powerline_left_segment $(__powerline_last_status_prompt ${last_status}) + [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${normal}" + + PS1="${LEFT_PROMPT} " + + ## cleanup ## + unset LAST_SEGMENT_COLOR \ + LEFT_PROMPT \ + SEGMENTS_AT_LEFT +} + diff --git a/themes/newin/newin.theme.bash b/themes/newin/newin.theme.bash new file mode 100644 index 00000000..9f54dc8a --- /dev/null +++ b/themes/newin/newin.theme.bash @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +SCM_THEME_PROMPT_DIRTY=" ${red}✗" +SCM_THEME_PROMPT_CLEAN=" ${green}✓" +SCM_THEME_PROMPT_PREFIX=" ${purple}|${green} " +SCM_THEME_PROMPT_SUFFIX="${purple} |" + +prompt() { + exit_code=$? + PS1="$(if [[ ${exit_code} = 0 ]]; then echo "${green}${exit_code}"; else echo "${red}${exit_code}"; fi) ${yellow}\t ${cyan}\w$(scm_prompt_info)${reset_color}\n${orange}$ ${reset_color}" +} + +safe_append_prompt_command prompt diff --git a/themes/sexy/sexy.theme.bash b/themes/sexy/sexy.theme.bash index 08869a3b..41d195d2 100644 --- a/themes/sexy/sexy.theme.bash +++ b/themes/sexy/sexy.theme.bash @@ -1,6 +1,13 @@ # Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt" # Screenshot: http://cloud.gf3.ca/M5rG # A big thanks to \amethyst on Freenode +# +# Configuration: +# * To visualize python environment (virtualenv and conda) add in your .bash_profile the following line: +# export SEXY_THEME_SHOW_PYTHON=true + +# Default setting +SEXY_THEME_SHOW_PYTHON="${SEXY_THEME_SHOW_PYTHON:=false}" if tput setaf 1 &> /dev/null; then if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then @@ -34,9 +41,16 @@ parse_git_dirty () { parse_git_branch () { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" } +env_prompt () { + echo -e "($(virtualenv_prompt)$(condaenv_prompt))" +} function prompt_command() { PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]" + + if [ "$SEXY_THEME_SHOW_PYTHON" = true ] ; then + PS1="\[${BOLD}${WHITE}\]$(env_prompt) "$PS1 + fi } safe_append_prompt_command prompt_command