diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..49cb74e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,23 @@ +Copyright (c) {{{year}}}, {{{fullname}}} +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index ce3102a..9be4440 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,40 @@ staged, changed, etc. (an original idea from this [blog post][]). -`gitstatus.sh` added by [AKS](http://github.com/aks). +`gitstatus.sh` and `git-prompt-help.sh` added by [AKS](http://github.com/aks). + +# ATTENTION! Breaking changes! + +**If you use this prompt already, please update your `.git-prompt-colors.sh`, +if you have one. It now contains a function named `define_git_prompt_colors()` or `override_git_prompt_colors()`!** + +**Please see the ``Custom.bgptemplate`` in the ``themes`` subdirectory of the installation directory!** + +**You can now also use the function `override_git_prompt_colors()`. It should define the variable `GIT_PROMPT_THEME_NAME` +and call the function `reload_git_prompt_colors ` like follows:** + +```sh +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Custom" # needed for reload optimization, should be unique + + # Place your overrides here + ... +} + +# load the theme +reload_git_prompt_colors "Custom" +``` + +The advantage of this approach is, that you only need to specify the parts, that are different to the Default theme. + +--- + +**The variable `GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR` was replaced with a more general placeholder +named ``_LAST_COMMAND_INDICATOR_``, which is replaced by the state of the last executed command. It is now activated by default.** ## Examples -The prompt may look like the following: +The prompt may look like the following: ![Example prompt](gitprompt.png) @@ -44,14 +73,39 @@ The symbols are as follows: - ``↑n``: ahead of remote by ``n`` commits - ``↓n``: behind remote by ``n`` commits - ``↓m↑n``: branches diverged, other by ``m`` commits, yours by ``n`` commits + - ``L``: local branch, not remotely tracked - Branch Symbol:
When the branch name starts with a colon ``:``, it means it's actually a hash, not a branch (although it should be pretty clear, unless you name your branches like hashes :-) -## Install +## Installation + +### via [Homebrew][homebrew] on Mac OS X + +- Run `brew update` + +- Run `brew install bash-git-prompt` for the last stable release or `brew install --HEAD bash-git-prompt` for the + latest version directly from the repository + +- Now you can source the file in your `~/.bash_profile` as follows: + +```sh +if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then + source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" +fi +``` + +### via Git clone + +- Clone this repository to your home directory. + +```sh +cd ~ +git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt +``` + +- Source the file `gitprompt.sh` from `~/.bashrc` -- Clone this repository to your homedir - e.g. ``git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt`` -- Source the file ``gitprompt.sh`` from your ``~/.bashrc`` config file: +### Configuration ```sh # some other config in .bashrc @@ -61,28 +115,81 @@ The symbols are as follows: # Set config variables first GIT_PROMPT_ONLY_IN_REPO=1 + # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status + + # GIT_PROMPT_START=... # uncomment for custom prompt start sequence + # GIT_PROMPT_END=... # uncomment for custom prompt end sequence + # as last entry source the gitprompt script + # GIT_PROMPT_THEME=Custom # use custom .git-prompt-colors.sh + # GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme source ~/.bash-git-prompt/gitprompt.sh ``` -- Go in a git repository and test it! +- `cd` to a git repository and test it! -## Configuration +#### Themes -- The default colors and some variables for tweaking the prompt are defined - within ``gitprompt.sh``, but may be overridden by copying ``git-prompt-colors.sh`` - to your home directory at ``~/.git-prompt-colors.sh``. This file may also be found in the same - directory as ``gitprompt.sh``, but without the leading ``.``. +The most settings are now stored in theme files. To select a theme, set the variable `GIT_PROMPT_THEME` to the name +of the theme located in `/themes` without the extension `.bgptheme` like this: -- You can use ``GIT_PROMPT_START_USER``, ``GIT_PROMPT_START_ROOT``, ``GIT_PROMPT_END_USER`` and ``GIT_PROMPT_END_ROOT`` in your ``.git-prompt-colors.sh`` to tweak your prompt. You can also override the start and end of the prompt by setting ``GIT_PROMPT_START`` and ``GIT_PROMPT_END`` before you source the ``gitprompt.sh`` +```sh +GIT_PROMPT_THEME=Solarized +``` + +If you set `GIT_PROMPT_THEME` to `Custom`, then the `.git-prompt-colors.sh` in the home directory will be used. +This file can now be generated with the command `git_prompt_make_custom_theme []`. If the name of +the base theme is ommitted or the theme file is not found, then the Default theme is used. If you have already a custom +`.git-prompt-colors.sh` in your home directory, a error message will be shown. + +You can display a list of available themes with `git_prompt_list_themes` (the current theme is highlighted) + +**If you omit the `GIT_PROMPT_THEME` variable, the Default theme is used or, if you have a custom `.git-prompt-colors.sh` +in your home directory, then the Custom theme is used.** + +##### Theme structure -- The current git repo information is obtained by the script `gitstatus.sh` or - `gitstatus.py`. Both scripts do the same thing, but the bash script is a - tad more quick, and is used by default. If you prefer the python script - (possibly because you have enhanced it), simply delete or change the name of - ``gitstatus.sh``. +Please see the ``Custom.bgptemplate`` in the ``themes`` subdirectory of the installation directory! + +A theme consists of a function `override_git_prompt_colors()` which defines at least the variable `GIT_PROMPT_THEME_NAME` + with a unique theme identifier and a call to the function `reload_git_prompt_colors ` like follows: + +```sh +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Custom" # needed for reload optimization, should be unique + + # Place your overrides here + ... +} + +# load the theme +reload_git_prompt_colors "Custom" +``` + +The advantage of this approach is, that you only need to specify the parts, that are different to the Default theme. + +If you use a custom theme in `.git-prompt-colors.sh`, please set `GIT_PROMPT_THEME_NAME="Custom"`. + +#### Further customizations + +- You can define `GIT_PROMPT_START` and `GIT_PROMPT_END` to tweak your prompt. + +- The default colors are defined within `prompt-colors.sh`, which is sourced by + `gitprompt.sh`. The colors used for various git status are defined in + `themes/Default.bgptheme`. Both of these files may be overridden by copying + them to $HOME with a `.` prefix. They can also be placed in `$HOME/lib` + without the leading `.`. The defaults are the original files in the + `~/.bash-git-prompt` directory. + +- You can use `GIT_PROMPT_START_USER`, `GIT_PROMPT_START_ROOT`, + `GIT_PROMPT_END_USER` and `GIT_PROMPT_END_ROOT` in your + `.git-prompt-colors.sh` to tweak your prompt. You can also override the start + and end of the prompt by setting `GIT_PROMPT_START` and `GIT_PROMPT_END` + before you source the `gitprompt.sh`. + +- The current git repo information is obtained by the script `gitstatus.sh`. +- You can define `prompt_callback` function to tweak your prompt dynamically. -- You can define ``prompt_callback`` function to tweak your prompt dynamically. ```sh function prompt_callback { if [ `jobs | wc -l` -ne 0 ]; then @@ -91,11 +198,119 @@ function prompt_callback { } ``` -- If you want to show the git prompt only, if you are in a git repository you can set ``GIT_PROMPT_ONLY_IN_REPO=1`` before sourcing the gitprompt script +- If you want to show the git prompt only if you are in a git repository you + can set ``GIT_PROMPT_ONLY_IN_REPO=1`` before sourcing the gitprompt script + +- There is an indicator at the start of the prompt, which shows + the result of the last executed command by if you put the placeholder + `_LAST_COMMAND_INDICATOR_` in any of the prompt templates. + It is now by default activated in the default theme: + +```sh + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" +``` + + If you want to display the exit code too, you can use the placeholder + ``_LAST_COMMAND_STATE_`` in ``GIT_PROMPT_COMMAND_OK`` or ``GIT_PROMPT_COMMAND_FAIL`` + in your ``.git-prompt-colors.sh``: + +```sh +GIT_PROMPT_COMMAND_OK="${Green}✔ " # displays as ✔ +GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 for exit code 1 +``` + +- It is now possible to disable the fetching of the remote repository either + globally by setting ``GIT_PROMPT_FETCH_REMOTE_STATUS=0`` in your .bashrc or + on a per repository basis by creating a file named ``.bash-git-rc`` with the + content ``FETCH_REMOTE_STATUS=0`` in the root of your git repository. -- You can get help on the git prompt with the function ``git_prompt_help``. - Examples are available with ``git_prompt_examples``. +- You can also ignore a repository completely by creating a file named ``.bash-git-rc`` with the + content ``GIT_PROMPT_IGNORE=1`` in the root of your git repository. + +- You can get help on the git prompt with the function ``git_prompt_help``. + Examples are available with ``git_prompt_examples``. + A list of all available named colors is available with `git_prompt_color_samples` + +- If you make any changes to any file that is sourced by `gitprompt.sh`, you + should run this command, so that the next prompt update will find all the + files and source them anew. + +```sh +git_prompt_reset +``` **Enjoy!** +## Alternative RPM Install + +This project ships an RPM spec to simplify installation on RHEL and +clones. If you wish to install from RPM, you may first build the RPM +from scratch by following this procedure: +* Clone this repository and tag the release with a version number + +````sh + git tag -a -m "Tag release 1.1" 1.1 +```` + +* Run the following command to create a tarball: + +````sh + VER=$(git describe) + # replace dash with underscore to work around + # rpmbuild does not allow dash in version string + VER=${VER//\-/_} + git archive \ + --format tar \ + --prefix=bash-git-prompt-${VER}/ \ + HEAD \ + -- *.sh \ + *.fish \ + README.md \ + themes \ + > bash-git-prompt-${VER}.tar + mkdir -p /tmp/bash-git-prompt-${VER} + sed "s/Version:.*/Version: ${VER}/" \ + bash-git-prompt.spec \ + > /tmp/bash-git-prompt-${VER}/bash-git-prompt.spec + OLDDIR=$(pwd) + cd /tmp + tar -uf ${OLDDIR}/bash-git-prompt-${VER}.tar \ + bash-git-prompt-${VER}/bash-git-prompt.spec + cd ${OLDDIR} + gzip bash-git-prompt-${VER}.tar + mv bash-git-prompt-${VER}.tar.gz bash-git-prompt-${VER}.tgz +```` + +* Log into an RHEL or clones host and run: + +````sh +rpmbuild -ta bash-git-prompt-xxx.tar.gz +```` +Then you may publish or install the rpm from "~/rpmbuild/RPMS/noarch". + +## License +This code is under the [BSD 2 Clause (NetBSD) license][license]. + +## Who Are You? +The current maintainer of the original bash-git-prompt is [Martin Gondermann][magicmonty]. + +## Contributing +If you want to contribute you can look for issues with the label [up-for-grabs][upforgrabs]. +Please leave a comment on the issue, that you want to fix it, so others know, the labels are "taken". + +Pull requests are welcome. I will check them and merge them, if I think they help the project. + +## Donations +I accept tips through [Gittip][tip] and [Flattr][flattr]. + +[![Gittip](https://img.shields.io/gittip/magicmonty.svg?style=flat)](https://www.gittip.com/magicmonty/) +[![Flattr](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt) + [blog post]: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ +[tip]:https://www.gittip.com/magicmonty/ +[magicmonty]: http://blog.pagansoft.de/pages/about.html +[license]:https://github.com/magicmonty/bash-git-prompt/tree/master/LICENSE.txt +[flattr]: https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt +[homebrew]: http://brew.sh/ +[upforgrabs]: https://github.com/magicmonty/bash-git-prompt/labels/up-for-grabs diff --git a/bash-git-prompt.rb b/bash-git-prompt.rb new file mode 100644 index 0000000..9be0688 --- /dev/null +++ b/bash-git-prompt.rb @@ -0,0 +1,25 @@ +require "formula" + +class BashGitPrompt < Formula + homepage "https://github.com/magicmonty/bash-git-prompt" + url "https://github.com/magicmonty/bash-git-prompt/archive/2.3.5.tar.gz" + sha1 "16e1a9ab0ac711de79fd3b823138c16fadb3d5de" + head "https://github.com/magicmonty/bash-git-prompt.git" + + def install + share.install "gitprompt.sh", "gitprompt.fish", "git-prompt-help.sh", + "gitstatus.sh", "prompt-colors.sh" + + (share/"themes").install Dir["themes/*.bgptheme"], "themes/Custom.bgptemplate" + doc.install "README.md" + end + + def caveats; <<-EOS.undent + You should add the following to your .bashrc (or equivalent): + if [ -f "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" ]; then + GIT_PROMPT_THEME=Default + source "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" + fi + EOS + end +end diff --git a/bash-git-prompt.spec b/bash-git-prompt.spec new file mode 100644 index 0000000..9ae7c9b --- /dev/null +++ b/bash-git-prompt.spec @@ -0,0 +1,76 @@ +%global START_TOKEN ### Generated by %{name} rpm package +%global END_TOKEN ### Generated by %{name} rpm package + +Name: bash-git-prompt +Version: 1.0 +Release: 1%{?dist} +Summary: Informative git prompt for bash and fish + +Group: Development/Tools +License: GPL +URL: https://github.com/magicmonty/bash-git-prompt.git +Source0: https://github.com/magicmonty/bash-git-prompt/archive/%{name}-%{version}.tgz +Requires: git +BuildArch: noarch + +%description +A bash prompt that displays information about the current git repository. In particular the branch name, difference with remote branch, number of files staged, changed, etc. + +This package will automatically enable the git prompt for bash after +install. It will disable the prompt accordingly after uninstall. + +%prep +%setup -q + + +%build + + +%install +rm -rf %{buildroot} + +install -d 755 %{buildroot}%{_datadir}/%{name} +install -pm 755 *.sh %{buildroot}%{_datadir}/%{name} +#install -pm 755 *.py %{buildroot}%{_datadir}/%{name} +install -pm 755 *.fish %{buildroot}%{_datadir}/%{name} +install -pm 644 README.md %{buildroot}%{_datadir}/%{name} +install -d 755 %{buildroot}%{_datadir}/%{name}/themes +install -pm 644 themes/*.bgptheme %{buildroot}%{_datadir}/%{name}/themes +install -pm 644 themes/*.bgptemplate %{buildroot}%{_datadir}/%{name}/themes + +# never include compiled Python program +#rm -fr %{buildroot}%{_datadir}/%{name}/*.pyo +#rm -fr %{buildroot}%{_datadir}/%{name}/*.pyc + + +%clean +rm -rf %{buildroot} + + +%files +%defattr(-,root,root,-) +%{_datadir}/%{name} + + +%post +# enable bash-git-prompt +cat << EOF >> /etc/bashrc +%{START_TOKEN} +if [ -f %{_datadir}/%{name}/gitprompt.sh ]; then + # Set config variables first + + GIT_PROMPT_ONLY_IN_REPO=1 + GIT_PROMPT_THEME=Default + source %{_datadir}/%{name}/gitprompt.sh +fi +%{END_TOKEN} +EOF + +%postun +# remove bash-git-prompt setup +sed -i -e '/^%{START_TOKEN}/, /^%{END_TOKEN}/{d}' /etc/bashrc + + +%changelog +* Fri Aug 08 2014 Justin Zhang |] +The git prompt format is ${GIT_PROMPT_PREFIX}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_SUFFIX} BRANCH is a branch name, such as "master" or "stage", a tag name, or commit hash prefixed with ':'. @@ -12,18 +14,18 @@ hash prefixed with ':'. TRACKING indicates how the local branch differs from the remote branch. It can be empty, or one of: - ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}↑·N${ResetColor} - ahead of remote by N commits - ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}↓·N${ResetColor} - behind remote by N commits - ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}↓·M↑·N${ResetColor} - branches diverged, other by M commits, yours by N commits + ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${ResetColor} - ahead of remote by N commits + ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - behind remote by M commits + ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - branches diverged, other by M commits, yours by N commits LOCALSTATUS is one of the following: - ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean - ${GIT_PROMPT_STAGED}N${ResetColor} - N staged files - ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N conflicted files - ${GIT_PROMPT_CHANGED}N${ResetColor} - N changed but *unstaged* files - ${GIT_PROMPT_UNTRACKED}N${ResetColor} - N untracked files - ${GIT_PROMPT_STASHED}N${ResetColor} - N stash entries + ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean + ${GIT_PROMPT_STAGED}N${ResetColor} - N staged files + ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N conflicted files + ${GIT_PROMPT_CHANGED}N${ResetColor} - N changed but *unstaged* files + ${GIT_PROMPT_UNTRACKED}N${ResetColor} - N untracked files + ${GIT_PROMPT_STASHED}N${ResetColor} - N stash entries See "git_prompt_examples" for examples. EOF @@ -56,3 +58,18 @@ These are examples of the git prompt: EOF } +git_prompt_color_samples() { + + showColor() { + local color=$(eval echo "\${$1}") + echo -e "${color}$1${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g' + } + + while (( x < 8 )) ; do + showColor ${ColorNames[x]} + showColor "Dim${ColorNames[x]}" + showColor "Bold${ColorNames[x]}" + showColor "Bright${ColorNames[x]}" + (( x++ )) + done +} diff --git a/gitprompt.sh b/gitprompt.sh index 33d4c16..323fcfc 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -3,183 +3,411 @@ function async_run() { { - $1 &> /dev/null + eval "$@" &> /dev/null }& } function git_prompt_dir() { - # assume the gitstatus.py is in the same directory as this script + # assume the gitstatus.sh is in the same directory as this script # code thanks to http://stackoverflow.com/questions/59895 - if [ -z "${__GIT_PROMPT_DIR}" ]; then + if [ -z "$__GIT_PROMPT_DIR" ]; then local SOURCE="${BASH_SOURCE[0]}" - while [ -h "${SOURCE}" ]; do - local DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" - SOURCE="$(readlink "${SOURCE}")" - [[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}" + while [ -h "$SOURCE" ]; do + local DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" done - __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" + __GIT_PROMPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" fi } -function git_prompt_config() +function echoc() { + echo -e "${1}$2${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g' +} + +function get_theme() { - # Colors - ResetColor="\[\033[0m\]" # Text reset + local CUSTOM_THEME_FILE="${HOME}/.git-prompt-colors.sh" + local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" - # Bold - local BoldGreen="\[\033[1;32m\]" # Green - local BoldBlue="\[\033[1;34m\]" # Blue + if [[ -z ${GIT_PROMPT_THEME} ]]; then + if [[ -r $CUSTOM_THEME_FILE ]]; then + GIT_PROMPT_THEME="Custom" + __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE + else + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE + fi + else + if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then + GIT_PROMPT_THEME="Custom" + __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE - # High Intensty - local IntenseBlack="\[\033[0;90m\]" # Grey + if [[ ! (-r $__GIT_PROMPT_THEME_FILE) ]]; then + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE + fi + else + local theme="" - # Bold High Intensty - local Magenta="\[\033[1;95m\]" # Purple + # use default theme, if theme was not found + for themefile in $(cd "$__GIT_PROMPT_DIR/themes" && echo *); do + if [[ "${themefile}" = "${GIT_PROMPT_THEME}.bgptheme" ]]; then + theme=$GIT_PROMPT_THEME + fi + done - # Regular Colors - local Yellow="\[\033[0;33m\]" - local White='\[\033[37m\]' - local Red="\[\033[0;31m\]" - local Blue="\[\033[0;34m\]" - local Cyan="\[\033[0;36m\]" + if [[ "${theme}" = "" ]]; then + GIT_PROMPT_THEME="Default" + fi + + __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/${GIT_PROMPT_THEME}.bgptheme" + fi + fi +} + +function git_prompt_load_theme() +{ + get_theme + local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + source "${DEFAULT_THEME_FILE}" + source "${__GIT_PROMPT_THEME_FILE}" +} +function git_prompt_list_themes() +{ + local oldTheme + local oldThemeFile + + git_prompt_dir + get_theme + + for themefile in `ls "$__GIT_PROMPT_DIR/themes"`; do + local theme="$(basename $themefile .bgptheme)" + + if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then + echoc ${Red} "*${theme}" + else + echo $theme + fi + done + + if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then + echoc ${Magenta} "*Custom" + else + echoc ${Blue} "Custom" + fi +} + +function git_prompt_make_custom_theme() { + if [[ -r "${HOME}/.git-prompt-colors.sh" ]]; then + echoc ${Red} "You alread have created a custom theme!" + else + git_prompt_dir + + local base="Default" + if [[ -n $1 && -r "${__GIT_PROMPT_DIR}/themes/${1}.bgptheme" ]]; then + base=$1 + echoc ${Green} "Using theme ${Magenta}\"${base}\"${Green} as base theme!" + else + echoc ${Green} "Using theme ${Magenta}\"Default\"${Green} as base theme!" + fi + + if [[ "${base}" = "Custom" ]]; then + echoc ${Red} "You cannot use the custom theme as base" + else + echoc ${Green} "Creating new cutom theme in \"${HOME}/.git-prompt-colors.sh\"" + echoc ${DimYellow} "Please add ${Magenta}\"GIT_PROMPT_THEME=Custom\"${DimYellow} to your .bashrc to use this theme" + if [[ "${base}" == "Default" ]]; then + cp "${__GIT_PROMPT_DIR}/themes/Custom.bgptemplate" "${HOME}/.git-prompt-colors.sh" + else + cp "${__GIT_PROMPT_DIR}/themes/${base}.bgptheme" "${HOME}/.git-prompt-colors.sh" + fi + fi + fi +} + +# gp_set_file_var ENVAR SOMEFILE +# +# If ENVAR is set, check that it's value exists as a readable file. Otherwise, +# Set ENVAR to the path to SOMEFILE, based on $HOME, $__GIT_PROMPT_DIR, and the +# directory of the current script. The SOMEFILE can be prefixed with '.', or +# not. +# +# Return 0 (success) if ENVAR not already defined, 1 (failure) otherwise. + +function gp_set_file_var() { + local envar="$1" + local file="$2" + if eval "[[ -n \"\$$envar\" && -r \"\$$envar\" ]]" ; then # is envar set to a readable file? + local basefile + eval "basefile=\"\`basename \\\"\$$envar\\\"\`\"" # assign basefile + if [[ "$basefile" = "$file" || "$basefile" = ".$file" ]]; then + return 0 + fi + else # envar is not set, or it's set to a different file than requested + eval "$envar=" # set empty envar + gp_maybe_set_envar_to_path "$envar" "$HOME/.$file" "$HOME/$file" "$HOME/lib/$file" && return 0 + git_prompt_dir + gp_maybe_set_envar_to_path "$envar" "$__GIT_PROMPT_DIR/$file" "${0##*/}/$file" && return 0 + fi + return 1 +} + +# gp_maybe_set_envar_to_path ENVAR FILEPATH ... +# +# return 0 (true) if any FILEPATH is readable, set ENVAR to it +# return 1 (false) if not + +function gp_maybe_set_envar_to_path(){ + local envar="$1" + shift + local file + for file in "$@" ; do + if [[ -r "$file" ]]; then + eval "$envar=\"$file\"" + return 0 + fi + done + return 1 +} + +# git_prompt_reset +# +# unsets selected GIT_PROMPT variables, causing the next prompt callback to +# recalculate them from scratch. + +git_prompt_reset() { + local var + for var in GIT_PROMPT_DIR __GIT_PROMPT_COLORS_FILE __PROMPT_COLORS_FILE __GIT_STATUS_CMD GIT_PROMPT_THEME_NAME; do + unset $var + done +} + +# gp_format_exit_status RETVAL +# +# echos the symbolic signal name represented by RETVAL if the process was +# signalled, otherwise echos the original value of RETVAL + +gp_format_exit_status() { + local RETVAL="$1" + local SIGNAL + # Suppress STDERR in case RETVAL is not an integer (in such cases, RETVAL + # is echoed verbatim) + if [ "${RETVAL}" -gt 128 ] 2>/dev/null; then + SIGNAL=$(( ${RETVAL} - 128 )) + kill -l "${SIGNAL}" 2>/dev/null || echo "${RETVAL}" + else + echo "${RETVAL}" + fi +} + +function git_prompt_config() +{ #Checking if root to change output _isroot=false [[ $UID -eq 0 ]] && _isroot=true - # source the user's ~/.git-prompt-colors.sh file, or the one that should be - # sitting in the same directory as this script + # There are two files related to colors: + # + # prompt-colors.sh -- sets generic color names suitable for bash `PS1` prompt + # git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh - if [[ -z "$__GIT_PROMPT_COLORS_FILE" ]]; then - local pfx file dir - for dir in "$HOME" "$__GIT_PROMPT_DIR" ; do - for pfx in '.' '' ; do - file="$dir/${pfx}git-prompt-colors.sh" - if [[ -f "$file" ]]; then - __GIT_PROMPT_COLORS_FILE="$file" - break 2 - fi - done - done + if gp_set_file_var __PROMPT_COLORS_FILE prompt-colors.sh ; then + source "$__PROMPT_COLORS_FILE" # outsource the color defs + else + echo 1>&2 "Cannot find prompt-colors.sh!" fi - # Various variables you might want for your PS1 prompt instead - local Time12a="\$(date +%H:%M)" - # local Time12a="(\$(date +%H:%M:%S))" - # local Time12a="(\@))" - local PathShort="\w" + # source the user's ~/.git-prompt-colors.sh file, or the one that should be + # sitting in the same directory as this script + + git_prompt_load_theme - # if the envar is defined, source the file for custom colors - if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then - source "$__GIT_PROMPT_COLORS_FILE" + if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then + LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK"; else - # Default values for the appearance of the prompt. Do not change these - # below. Instead, copy these to `~/.git-prompt-colors.sh` and change them - # there. - GIT_PROMPT_PREFIX="[" - GIT_PROMPT_SUFFIX="]" - GIT_PROMPT_SEPARATOR="|" - GIT_PROMPT_BRANCH="${Magenta}" - GIT_PROMPT_STAGED="${Red}●" - GIT_PROMPT_CONFLICTS="${Red}✖" - GIT_PROMPT_CHANGED="${Blue}✚" - GIT_PROMPT_REMOTE=" " - GIT_PROMPT_UNTRACKED="${Cyan}…" - GIT_PROMPT_STASHED="${BoldBlue}⚑" - GIT_PROMPT_CLEAN="${BoldGreen}✔" - - GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - - # Please do not add colors to these symbols - GIT_PROMPT_SYMBOLS_AHEAD="↑·" - GIT_PROMPT_SYMBOLS_BEHIND="↓·" - GIT_PROMPT_SYMBOLS_PREHASH=":" + LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_FAIL"; fi - if [ "x${GIT_PROMPT_START}" == "x" ]; then - #First statment is for non root behavior second for root - if $_isroot; then - PROMPT_START="${GIT_PROMPT_START_ROOT}" + # replace _LAST_COMMAND_STATE_ token with the actual state + GIT_PROMPT_LAST_COMMAND_STATE=$(gp_format_exit_status ${GIT_PROMPT_LAST_COMMAND_STATE}) + LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR//_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}" + + # Do this only once to define PROMPT_START and PROMPT_END + + if [[ -z "$PROMPT_START" || -z "$PROMPT_END" ]]; then + + if [[ -z "$GIT_PROMPT_START" ]] ; then + if $_isroot; then + PROMPT_START="$GIT_PROMPT_START_ROOT" + else + PROMPT_START="$GIT_PROMPT_START_USER" + fi else - PROMPT_START="${GIT_PROMPT_START_USER}" + PROMPT_START="$GIT_PROMPT_START" fi - else - PROMPT_START="${GIT_PROMPT_START}" - fi - if [ "x${GIT_PROMPT_END}" == "x" ]; then - #First statment is for non root behavior second for root - if ! $_isroot; then - PROMPT_END="${GIT_PROMPT_END_USER}" + if [[ -z "$GIT_PROMPT_END" ]] ; then + if $_isroot; then + PROMPT_END="$GIT_PROMPT_END_ROOT" + else + PROMPT_END="$GIT_PROMPT_END_USER" + fi else - PROMPT_END="${GIT_PROMPT_END_ROOT}" + PROMPT_END="$GIT_PROMPT_END" fi - else - PROMPT_END="${GIT_PROMPT_END}" fi # set GIT_PROMPT_LEADING_SPACE to 0 if you want to have no leading space in front of the GIT prompt - if [ "x${GIT_PROMPT_LEADING_SPACE}" == "x0" ]; then + if [[ "$GIT_PROMPT_LEADING_SPACE" = 0 ]]; then PROMPT_LEADING_SPACE="" else PROMPT_LEADING_SPACE=" " fi - if [ "x${GIT_PROMPT_ONLY_IN_REPO}" == "x1" ]; then - EMPTY_PROMPT=$OLD_GITPROMPT + if [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then + EMPTY_PROMPT="$OLD_GITPROMPT" else - if [[ -n "${VIRTUAL_ENV}" ]]; then - EMPTY_PROMPT="(${Blue}$(basename "${VIRTUAL_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}" - else - EMPTY_PROMPT="${PROMPT_START}$($prompt_callback)${PROMPT_END}" + local ps="" + if [[ -n "$VIRTUAL_ENV" ]]; then + VENV=$(basename "${VIRTUAL_ENV}") + ps="${ps}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" fi + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + VENV=$(basename "${CONDA_DEFAULT_ENV}") + ps="${ps}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" + fi + ps="$ps$PROMPT_START$($prompt_callback)$PROMPT_END" + EMPTY_PROMPT="${ps//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" fi # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes - GIT_PROMPT_FETCH_TIMEOUT=${1-5} - if [ "x$__GIT_STATUS_CMD" == "x" ] - then + if [[ -z "$GIT_PROMPT_FETCH_TIMEOUT" ]]; then + GIT_PROMPT_FETCH_TIMEOUT="5" + fi + if [[ -z "$__GIT_STATUS_CMD" ]] ; then # if GIT_STATUS_CMD not defined.. git_prompt_dir - local sfx file - # look first for a '.sh' version, then use the python version - for sfx in sh py ; do - file="${__GIT_PROMPT_DIR}/gitstatus.$sfx" - if [[ -x "$file" ]]; then - __GIT_STATUS_CMD="$file" - break - fi - done + if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "$__GIT_PROMPT_DIR/gitstatus.sh" ; then + echo 1>&2 "Cannot find gitstatus.sh!" + fi + # __GIT_STATUS_CMD defined fi } +function setLastCommandState() { + GIT_PROMPT_LAST_COMMAND_STATE=$? +} + +function we_are_on_repo() { + if [[ -e "$(git rev-parse --git-dir 2> /dev/null)" ]]; then + echo 1 + fi + echo 0 +} + +function update_old_git_prompt() { + local in_repo=$(we_are_on_repo) + if [[ $GIT_PROMPT_OLD_DIR_WAS_GIT = 0 ]]; then + OLD_GITPROMPT=$PS1 + fi + + GIT_PROMPT_OLD_DIR_WAS_GIT=$in_repo +} + function setGitPrompt() { + update_old_git_prompt + + local repo=`git rev-parse --show-toplevel 2> /dev/null` + if [[ ! -e "$repo" ]] && [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then + # we do not permit bash-git-prompt outside git repos, so nothing to do + PS1="$OLD_GITPROMPT" + return + fi local EMPTY_PROMPT local __GIT_STATUS_CMD git_prompt_config - local repo=`git rev-parse --show-toplevel 2> /dev/null` - if [[ ! -e "${repo}" ]]; then - PS1="${EMPTY_PROMPT}" + if [[ ! -e "$repo" ]]; then + PS1="$EMPTY_PROMPT" return fi - checkUpstream + local FETCH_REMOTE_STATUS=1 + if [[ "$GIT_PROMPT_FETCH_REMOTE_STATUS" = 0 ]]; then + FETCH_REMOTE_STATUS=0 + fi + + unset GIT_PROMPT_IGNORE + + if [[ -e "$repo/.bash-git-rc" ]]; then + source "$repo/.bash-git-rc" + fi + + if [[ "$GIT_PROMPT_IGNORE" = 1 ]]; then + PS1="$EMPTY_PROMPT" + return + fi + + if [[ "$FETCH_REMOTE_STATUS" = 1 ]]; then + checkUpstream + fi + updatePrompt } +# some versions of find do not have -mmin +_have_find_mmin=1 + +function olderThanMinutes() { + local matches + local find_exit_code + + if [[ -z "$_find_command" ]]; then + if command -v gfind > /dev/null; then + _find_command=gfind + else + _find_command=find + fi + fi + + if [[ "$_have_find_mmin" = 1 ]]; then + matches=`"$_find_command" "$1" -mmin +"$2" 2> /dev/null` + find_exit_code="$?" + if [[ -n "$matches" ]]; then + return 0 + else + if [[ "$find_exit_code" != 0 ]]; then + _have_find_mmin=0 + else + return 1 + fi + fi + fi + + # try perl, solaris ships with perl + if command -v perl > /dev/null; then + perl -e '((time - (stat("'"$1"'"))[9]) / 60) > '"$2"' && exit(0) || exit(1)' + return "$?" + else + echo >&2 + echo "WARNING: neither a find that supports -mmin (such as GNU find) or perl is available, disabling remote status checking. Install GNU find as gfind or perl to enable this feature, or set GIT_PROMPT_FETCH_REMOTE_STATUS=0 to disable this warning." >&2 + echo >&2 + GIT_PROMPT_FETCH_REMOTE_STATUS=0 + return 1 + fi +} + function checkUpstream() { local GIT_PROMPT_FETCH_TIMEOUT git_prompt_config - local FETCH_HEAD="${repo}/.git/FETCH_HEAD" + local FETCH_HEAD="$repo/.git/FETCH_HEAD" # Fech repo if local is stale for more than $GIT_FETCH_TIMEOUT minutes - if [[ ! -e "${FETCH_HEAD}" || -e `find "${FETCH_HEAD}" -mmin +${GIT_PROMPT_FETCH_TIMEOUT}` ]] + if [[ ! -e "$FETCH_HEAD" ]] || olderThanMinutes "$FETCH_HEAD" "$GIT_PROMPT_FETCH_TIMEOUT" then if [[ -n $(git remote show) ]]; then ( @@ -190,34 +418,35 @@ function checkUpstream() { fi } +function replaceSymbols() +{ + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING=L + fi + + local VALUE=${1//_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} + local VALUE1=${VALUE//_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} + local VALUE2=${VALUE1//_NO_REMOTE_TRACKING_/${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}} + + echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} +} + function updatePrompt() { - local GIT_PROMPT_PREFIX - local GIT_PROMPT_SUFFIX - local GIT_PROMPT_SEPARATOR - local GIT_PROMPT_BRANCH - local GIT_PROMPT_STAGED - local GIT_PROMPT_CONFLICTS - local GIT_PROMPT_CHANGED - local GIT_PROMPT_REMOTE - local GIT_PROMPT_UNTRACKED - local GIT_PROMPT_STASHED - local GIT_PROMPT_CLEAN + local LAST_COMMAND_INDICATOR local PROMPT_LEADING_SPACE local PROMPT_START local PROMPT_END local EMPTY_PROMPT - local GIT_PROMPT_FETCH_TIMEOUT - local __GIT_STATUS_CMD - local Blue="\[\033[0;34m\]" git_prompt_config + export __GIT_PROMPT_IGNORE_STASH=${GIT_PROMPT_IGNORE_STASH} local -a GitStatus - GitStatus=($("${__GIT_STATUS_CMD}" 2>/dev/null)) + GitStatus=($("$__GIT_STATUS_CMD" 2>/dev/null)) - local GIT_BRANCH=${GitStatus[0]} - local GIT_REMOTE=${GitStatus[1]} + local GIT_BRANCH=$(replaceSymbols ${GitStatus[0]}) + local GIT_REMOTE="$(replaceSymbols ${GitStatus[1]})" if [[ "." == "$GIT_REMOTE" ]]; then unset GIT_REMOTE fi @@ -228,56 +457,72 @@ function updatePrompt() { local GIT_STASHED=${GitStatus[6]} local GIT_CLEAN=${GitStatus[7]} - if [[ -n "${GitStatus}" ]]; then + local NEW_PROMPT="$EMPTY_PROMPT" + if [[ -n "$GitStatus" ]]; then local STATUS="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" - if [[ -n "${GIT_REMOTE}" ]]; then - STATUS="${STATUS}${GIT_PROMPT_REMOTE}${GIT_REMOTE}${ResetColor}" - fi + # __add_status KIND VALEXPR INSERT + # eg: __add_status 'STAGED' '-ne 0' - STATUS="${STATUS}${GIT_PROMPT_SEPARATOR}" - if [ "${GIT_STAGED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_STAGED}${GIT_STAGED}${ResetColor}" - fi - - if [ "${GIT_CONFLICTS}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_CONFLICTS}${GIT_CONFLICTS}${ResetColor}" - fi - - if [ "${GIT_CHANGED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_CHANGED}${GIT_CHANGED}${ResetColor}" - fi - - if [ "${GIT_UNTRACKED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_UNTRACKED}${GIT_UNTRACKED}${ResetColor}" - fi - - if [ "${GIT_STASHED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_STASHED}${GIT_STASHED}${ResetColor}" - fi - - if [ "${GIT_CLEAN}" -eq "1" ]; then - STATUS="${STATUS}${GIT_PROMPT_CLEAN}" + __chk_gitvar_status() { + local v + if [[ "x$2" == "x-n" ]] ; then + v="$2 \"\$GIT_$1\"" + else + v="\$GIT_$1 $2" + fi + if eval "test $v" ; then + if [[ $# -lt 2 || "$3" != '-' ]]; then + __add_status "\$GIT_PROMPT_$1\$GIT_$1\$ResetColor" + else + __add_status "\$GIT_PROMPT_$1\$ResetColor" + fi + fi + } + + __add_gitvar_status() { + __add_status "\$GIT_PROMPT_$1\$GIT_$1\$ResetColor" + } + + # __add_status SOMETEXT + __add_status() { + eval "STATUS=\"$STATUS$1\"" + } + + __chk_gitvar_status 'REMOTE' '-n' + __add_status "$GIT_PROMPT_SEPARATOR" + __chk_gitvar_status 'STAGED' '-ne 0' + __chk_gitvar_status 'CONFLICTS' '-ne 0' + __chk_gitvar_status 'CHANGED' '-ne 0' + __chk_gitvar_status 'UNTRACKED' '-ne 0' + __chk_gitvar_status 'STASHED' '-ne 0' + __chk_gitvar_status 'CLEAN' '-eq 1' - + __add_status "$ResetColor$GIT_PROMPT_SUFFIX" + + NEW_PROMPT="" + if [[ -n "$VIRTUAL_ENV" ]]; then + VENV=$(basename "${VIRTUAL_ENV}") + NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" fi - STATUS="${STATUS}${ResetColor}${GIT_PROMPT_SUFFIX}" - - - PS1="${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}" - if [[ -n "${VIRTUAL_ENV}" ]]; then - PS1="(${Blue}$(basename ${VIRTUAL_ENV})${ResetColor}) ${PS1}" + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + VENV=$(basename "${CONDA_DEFAULT_ENV}") + NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" fi + NEW_PROMPT="$NEW_PROMPT$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" else - PS1="${EMPTY_PROMPT}" + NEW_PROMPT="$EMPTY_PROMPT" fi + + PS1="${NEW_PROMPT//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" } function prompt_callback_default { return } -function run { +function gp_install_prompt { if [ "`type -t prompt_callback`" = 'function' ]; then prompt_callback="prompt_callback" else @@ -288,6 +533,10 @@ function run { OLD_GITPROMPT=$PS1 fi + if [ -z "$GIT_PROMPT_OLD_DIR_WAS_GIT" ]; then + GIT_PROMPT_OLD_DIR_WAS_GIT=$(we_are_on_repo) + fi + if [ -z "$PROMPT_COMMAND" ]; then PROMPT_COMMAND=setGitPrompt else @@ -306,8 +555,19 @@ function run { esac fi + local setLastCommandStateEntry="setLastCommandState" + case ";$PROMPT_COMMAND;" in + *";$setLastCommandStateEntry;"*) + # echo "PROMPT_COMMAND already contains: $setLastCommandStateEntry" + :;; + *) + PROMPT_COMMAND="$setLastCommandStateEntry;$PROMPT_COMMAND" + # echo "PROMPT_COMMAND does not contain: $setLastCommandStateEntry" + ;; + esac + git_prompt_dir source "$__GIT_PROMPT_DIR/git-prompt-help.sh" } -run \ No newline at end of file +gp_install_prompt diff --git a/gitstatus.sh b/gitstatus.sh index e64df13..68d1a08 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -19,42 +19,6 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" fi -if [[ -z "$__GIT_PROMPT_COLORS_FILE" ]]; then - for dir in "$HOME" "$__GIT_PROMPT_DIR" ; do - for pfx in '.' '' ; do - file="$dir/${pfx}git-prompt-colors.sh" - if [[ -f "$file" ]]; then - __GIT_PROMPT_COLORS_FILE="$file" - break 2 - fi - done - done -fi - -# if the envar is defined, source the file for custom colors -if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then - source "$__GIT_PROMPT_COLORS_FILE" -fi - -# change those symbols to whatever you prefer -if [[ -n "${GIT_PROMPT_SYMBOLS_AHEAD}" ]]; then - symbols_ahead="${GIT_PROMPT_SYMBOLS_AHEAD}" -else - symbols_ahead='↑·' -fi - -if [[ -n "${GIT_PROMPT_SYMBOLS_BEHIND}" ]]; then - symbols_behind="${GIT_PROMPT_SYMBOLS_BEHIND}" -else - symbols_behind='↓·' -fi - -if [[ -n "${GIT_PROMPT_SYMBOLS_PREHASH}" ]]; then - symbols_prehash=':' -else - symbols_prehash="${GIT_PROMPT_SYMBOLS_PREHASH}" -fi - gitsym=`git symbolic-ref HEAD` # if "fatal: Not a git repo .., then exit @@ -74,8 +38,8 @@ staged_files=`git diff --staged --name-status` num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) num_conflicts=`count_lines "$staged_files" U` num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) -num_untracked=`git status -s -uall | grep -c "^??"` -if [[ -n "$GIT_PROMPT_IGNORE_STASH" ]]; then +num_untracked=`git ls-files --others --exclude-standard $(git rev-parse --show-cdup) | wc -l` +if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then num_stashed=0 else num_stashed=`git stash list | wc -l` @@ -93,7 +57,7 @@ if [[ -z "$branch" ]]; then if [[ -n "$tag" ]]; then branch="$tag" else - branch="${symbols_prehash}`git rev-parse --short HEAD`" + branch="_PREHASH_`git rev-parse --short HEAD`" fi else remote_name=`git config branch.${branch}.remote` @@ -111,22 +75,36 @@ else remote_ref="refs/remotes/$remote_name/${merge_name##refs/heads/}" fi + # detect if the local branch have a remote tracking branch + cmd_output=$(git rev-parse --abbrev-ref ${branch}@{upstream} 2>&1 >/dev/null) + + if [ `count_lines "$cmd_output" "fatal: No upstream"` == 1 ] ; then + has_remote_tracking=0 + else + has_remote_tracking=1 + fi + # get the revision list, and count the leading "<" and ">" revgit=`git rev-list --left-right ${remote_ref}...HEAD` num_revs=`all_lines "$revgit"` num_ahead=`count_lines "$revgit" "^>"` num_behind=$(( num_revs - num_ahead )) if (( num_behind > 0 )) ; then - remote="${remote}${symbols_behind}${num_behind}" + remote="${remote}_BEHIND_${num_behind}" fi if (( num_ahead > 0 )) ; then - remote="${remote}${symbols_ahead}${num_ahead}" + remote="${remote}_AHEAD_${num_ahead}" fi fi + if [[ -z "$remote" ]] ; then remote='.' fi +if [[ "$has_remote_tracking" == "0" ]] ; then + remote='_NO_REMOTE_TRACKING_' +fi + for w in "$branch" "$remote" $num_staged $num_conflicts $num_changed $num_untracked $num_stashed $clean ; do echo "$w" done diff --git a/prompt-colors.sh b/prompt-colors.sh new file mode 100644 index 0000000..5176d36 --- /dev/null +++ b/prompt-colors.sh @@ -0,0 +1,86 @@ +# prompt-colors.sh +# +# source this file to get color definitions +# if $debug or $verbose is set, the definitions +# are also printed to STDERR. + +define_color_names() { + + ColorNames=( Black Red Green Yellow Blue Magenta Cyan White ) + FgColors=( 30 31 32 33 34 35 36 37 ) + BgColors=( 40 41 42 43 44 45 46 47 ) + + local AttrNorm=0 + local AttrBright=1 + local AttrDim=2 + local AttrUnder=4 + local AttrBlink=5 + local AttrRev=7 + local AttrHide=8 + + # define "BoldCOLOR", "BrightCOLOR", and "DimCOLOR" names + + # _map_colors ATTRNAME ATTRVALUE + # + # Defines three names for every color, attribute combintaion: + # {ATTRNAME}{COLORNAME} + # {ATTRNAME}{COLORNAME}Fg + # {ATTRNAME}{COLORNAME}Bg + # + # Example: BoldRed, BoldRedFg, BoldRedBg + + _map_colors() { + local x=0 + local attrname="$1" + local attrcode=$2 + while (( x < 8 )) ; do + local colorname=${ColorNames[x]} + local fgcolorcode=${FgColors[x]} + local bgcolorcode=${BgColors[x]} + longcolorname="${attrname}${colorname}" + _def_color $longcolorname $attrcode $fgcolorcode + _def_color ${longcolorname}Fg $attrcode $fgcolorcode + _def_color ${longcolorname}Bg $attrcode $bgcolorcode + (( x++ )) + done + } + + # _term_color [ N | N M ] + _term_color() { + local cv + if (( $# > 1 )); then + cv="${1};${2}" + else + cv="${1}" + fi + echo "\[\033[${cv}m\]" + } + + # def_color NAME ATTRCODE COLORCODE + _def_color() { + local def="$1=\"\`_term_color $2 $3\`\"" + if [[ -n "$debug$verbose" ]]; then + echo 1>&2 "+ $def" + fi + eval "$def" + } + + #ResetColor="`_term_color 0`" # Text reset + + _map_colors Bold $AttrBright + _map_colors Bright $AttrBright + _map_colors Dim $AttrDim + _map_colors '' $AttrNorm + + _def_color IntenseBlack 0 90 + _def_color ResetColor 0 0 + +} + +# do the color definitions only once +if [[ ${#ColorNames[*]} = 0 || -z "$IntenseBlack" || -z "$ResetColor" ]]; then + define_color_names +fi + +# end of prompt-colors.sh +# vim: set ai sw=2 diff --git a/themes/Crunch.bgptheme b/themes/Crunch.bgptheme new file mode 100644 index 0000000..78b99a5 --- /dev/null +++ b/themes/Crunch.bgptheme @@ -0,0 +1,34 @@ +# This theme for gitprompt.sh is designed for dark color schemes +# it is clone of oh-my-zsh crunch theme style with exit status + +override_git_prompt_colors() { + if [ -e ~/.rvm/bin/rvm-prompt ]; then + RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' + else + if command -v rbenv > /dev/null; then + RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' + fi + fi + Time12a="\$(date +%H:%M)" + + GIT_PROMPT_THEME_NAME="Crunch" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + + KERNEL_PROMPT='‹$(uname -r)›' + +GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_${White}{${Yellow}${Time12a}${White}}[${Magenta}${RUBY_PROMPT}${White}]${Cyan}${PathShort}${White}:" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="${BoldBlue} ➭ ${ResetColor}" + GIT_PROMPT_END_ROOT="${BoldRed} # ${ResetColor}" + GIT_PROMPT_LEADING_SPACE=0 + GIT_PROMPT_PREFIX="${Green}[" + GIT_PROMPT_SUFFIX="${Green}]" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} + +reload_git_prompt_colors "Crunch" diff --git a/themes/Custom.bgptemplate b/themes/Custom.bgptemplate new file mode 100644 index 0000000..8305d70 --- /dev/null +++ b/themes/Custom.bgptemplate @@ -0,0 +1,53 @@ +# This is the custom theme template for gitprompt.sh + +# These are the defaults from the "Default" theme +# You just need to override what you want to have changed +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Custom" + + # Time12a="\$(date +%H:%M)" + # PathShort="\w"; + + ## These are the color definitions used by gitprompt.sh + # GIT_PROMPT_PREFIX="[" # start of the git info string + # GIT_PROMPT_SUFFIX="]" # the end of the git info string + # GIT_PROMPT_SEPARATOR="|" # separates each item + + # GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + # GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories + # GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + # GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + # GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + # GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + # GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir + # GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo + + ## For the command indicator, the placeholder _LAST_COMMAND_STATE_ + ## will be replaced with the exit code of the last command + ## e.g. + ## GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + ## GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + # GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 + + ## template for displaying the current virtual environment + ## use the placeholder _VIRTUALENV_ will be replaced with + ## the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + # GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + ## _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + # GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + # GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + # GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + # GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + ## Please do not add colors to these symbols + # GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + # GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + # GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found + # GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" # This symbol is written after the branch, if the branch is not tracked +} + +reload_git_prompt_colors "Custom" \ No newline at end of file diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme new file mode 100644 index 0000000..b37b0e3 --- /dev/null +++ b/themes/Default.bgptheme @@ -0,0 +1,94 @@ +# This is the default theme for gitprompt.sh + +unset_git_prompt_colors() { + unset Time12a + unset PathShort + unset GIT_PROMPT_PREFIX + unset GIT_PROMPT_SUFFIX + unset GIT_PROMPT_SEPARATOR + unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_STAGED + unset GIT_PROMPT_CONFLICTS + unset GIT_PROMPT_CHANGED + unset GIT_PROMPT_REMOTE + unset GIT_PROMPT_UNTRACKED + unset GIT_PROMPT_STASHED + unset GIT_PROMPT_CLEAN + unset GIT_PROMPT_COMMAND_OK + unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_VIRTUALENV + unset GIT_PROMPT_START_USER + unset GIT_PROMPT_START_ROOT + unset GIT_PROMPT_END_USER + unset GIT_PROMPT_END_ROOT + unset GIT_PROMPT_SYMBOLS_AHEAD + unset GIT_PROMPT_SYMBOLS_BEHIND + unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING +} + +define_helpers() +{ + Time12a="\$(date +%H:%M)" + PathShort="\w"; +} + +define_undefined_git_prompt_colors() { + if [[ -z ${GIT_PROMPT_THEME_NAME} ]]; then GIT_PROMPT_THEME_NAME="Default"; fi + + # These are the color definitions used by gitprompt.sh + if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="["; fi # start of the git info string + if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX="]"; fi # the end of the git info string + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR="|"; fi # separates each item + + if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED="${Red}●"; fi # the number of staged files/directories + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files + + if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED="${Cyan}…"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED="${BoldBlue}⚑ "; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN="${BoldGreen}✔"; fi # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_"; fi # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"; fi + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi + if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ "; fi + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # "; fi + + # Please do not add colors to these symbols + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked +} + +# call only from theme file +reload_git_prompt_colors() { + if [[ "${GIT_PROMPT_THEME_NAME}" != $1 ]]; then + unset_git_prompt_colors + define_helpers + override_git_prompt_colors + define_undefined_git_prompt_colors + fi +} + +if [[ "${GIT_PROMPT_THEME}" == "Default" && "${GIT_PROMPT_THEME_NAME}" != "Default" ]]; then + define_helpers + define_undefined_git_prompt_colors +fi diff --git a/themes/Default_NoExitState.bgptheme b/themes/Default_NoExitState.bgptheme new file mode 100644 index 0000000..239aae1 --- /dev/null +++ b/themes/Default_NoExitState.bgptheme @@ -0,0 +1,11 @@ +# This is the default theme for gitprompt.sh +# without the indicator of the last command state + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Default NoExitState" + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" +} + +reload_git_prompt_colors "Default NoExitState" diff --git a/themes/Default_NoExitState_Ubuntu.bgptheme b/themes/Default_NoExitState_Ubuntu.bgptheme new file mode 100644 index 0000000..2af22f3 --- /dev/null +++ b/themes/Default_NoExitState_Ubuntu.bgptheme @@ -0,0 +1,16 @@ +# This is the default theme for gitprompt.sh +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Default NoExitState Ubuntu" + GIT_PROMPT_STAGED="${Red}● " # the number of staged files/directories + GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs + GIT_PROMPT_CLEAN="${BoldGreen}✔ " # a colored flag indicating a "clean" repo + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" +} + +reload_git_prompt_colors "Default NoExitState Ubuntu" \ No newline at end of file diff --git a/themes/Default_Ubuntu.bgptheme b/themes/Default_Ubuntu.bgptheme new file mode 100644 index 0000000..7ddf91f --- /dev/null +++ b/themes/Default_Ubuntu.bgptheme @@ -0,0 +1,12 @@ +# This is the default theme for gitprompt.sh +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Default Ubuntu" + GIT_PROMPT_STAGED="${Red}● " # the number of staged files/directories + GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs + GIT_PROMPT_CLEAN="${BoldGreen}✔ " # a colored flag indicating a "clean" repo + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 +} + +reload_git_prompt_colors "Default Ubuntu" \ No newline at end of file diff --git a/themes/Single_line.bgptheme b/themes/Single_line.bgptheme new file mode 100644 index 0000000..b64e361 --- /dev/null +++ b/themes/Single_line.bgptheme @@ -0,0 +1,94 @@ +# This is an alternative approach. Single line in git repo. + +unset_git_prompt_colors() { + unset Time12a + unset PathShort + unset GIT_PROMPT_PREFIX + unset GIT_PROMPT_SUFFIX + unset GIT_PROMPT_SEPARATOR + unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_STAGED + unset GIT_PROMPT_CONFLICTS + unset GIT_PROMPT_CHANGED + unset GIT_PROMPT_REMOTE + unset GIT_PROMPT_UNTRACKED + unset GIT_PROMPT_STASHED + unset GIT_PROMPT_CLEAN + unset GIT_PROMPT_COMMAND_OK + unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_VIRTUALENV + unset GIT_PROMPT_START_USER + unset GIT_PROMPT_START_ROOT + unset GIT_PROMPT_END_USER + unset GIT_PROMPT_END_ROOT + unset GIT_PROMPT_SYMBOLS_AHEAD + unset GIT_PROMPT_SYMBOLS_BEHIND + unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING +} + +define_helpers() +{ + Time12a="\$(date +%H:%M)" + PathShort="\w"; +} + +define_undefined_git_prompt_colors() { + if [[ -z ${GIT_PROMPT_THEME_NAME} ]]; then GIT_PROMPT_THEME_NAME="Single_line"; fi + + # These are the color definitions used by gitprompt.sh + if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="["; fi # start of the git info string + if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX="]"; fi # the end of the git info string + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR="|"; fi # separates each item + + if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED="${Red}●"; fi # the number of staged files/directories + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files + + if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED="${Cyan}…"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED="${BoldBlue}⚑ "; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN="${BoldGreen}✔"; fi # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${BoldYellow}${PathShort}${ResetColor}"; fi + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi + if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER="${ResetColor} $ "; fi + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${BoldRed} # "; fi + + # Please do not add colors to these symbols + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked +} + +# call only from theme file +reload_git_prompt_colors() { + if [[ "${GIT_PROMPT_THEME_NAME}" != $1 ]]; then + unset_git_prompt_colors + define_helpers + override_git_prompt_colors + define_undefined_git_prompt_colors + fi +} + +if [[ "${GIT_PROMPT_THEME}" == "Single_line" && "${GIT_PROMPT_THEME_NAME}" != "Single_line" ]]; then + define_helpers + define_undefined_git_prompt_colors +fi diff --git a/themes/Single_line_NoExitState_openSUSE.bgptheme b/themes/Single_line_NoExitState_openSUSE.bgptheme new file mode 100644 index 0000000..e3580d7 --- /dev/null +++ b/themes/Single_line_NoExitState_openSUSE.bgptheme @@ -0,0 +1,19 @@ +# This is a theme for gitprompt.sh, +# it uses the default openSUSE bash prompt style + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_NoExitState_openSUSE" + GIT_PROMPT_BRANCH="${Cyan}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_CHANGED="${Yellow}✚ " + GIT_PROMPT_STAGED="${Magenta}●" + + GIT_PROMPT_START_USER="\u@\h:\w" + GIT_PROMPT_START_ROOT="${BoldRed}\h:\w" + + GIT_PROMPT_END_USER="> " + GIT_PROMPT_END_ROOT=" # ${ResetColor}" +} + +reload_git_prompt_colors "Single_line_NoExitState_openSUSE" + diff --git a/themes/Single_line_Solarized.bgptheme b/themes/Single_line_Solarized.bgptheme new file mode 100644 index 0000000..d44e0ea --- /dev/null +++ b/themes/Single_line_Solarized.bgptheme @@ -0,0 +1,102 @@ +# This is an alternative approach. Single line in git repo. +# Theme optimised for Terminus and PowerLine compatible fonts. +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +unset_git_prompt_colors() { + unset Time12a + unset PathShort + unset GIT_PROMPT_PREFIX + unset GIT_PROMPT_SUFFIX + unset GIT_PROMPT_SEPARATOR + unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_STAGED + unset GIT_PROMPT_CONFLICTS + unset GIT_PROMPT_CHANGED + unset GIT_PROMPT_REMOTE + unset GIT_PROMPT_UNTRACKED + unset GIT_PROMPT_STASHED + unset GIT_PROMPT_CLEAN + unset GIT_PROMPT_COMMAND_OK + unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_VIRTUALENV + unset GIT_PROMPT_START_USER + unset GIT_PROMPT_START_ROOT + unset GIT_PROMPT_END_USER + unset GIT_PROMPT_END_ROOT + unset GIT_PROMPT_SYMBOLS_AHEAD + unset GIT_PROMPT_SYMBOLS_BEHIND + unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING +} + +define_helpers() +{ + PathShort="${BoldBlue}\u:${Cyan}\W" +} + +define_undefined_git_prompt_colors() { + if [[ -z ${GIT_PROMPT_THEME_NAME} ]]; then GIT_PROMPT_THEME_NAME="Single_line_Solarized"; fi + + # These are the color definitions used by gitprompt.sh + if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="[ "; fi # start of the git info string + if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX=" ]"; fi # the end of the git info string + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR=" |"; fi # separates each item + + if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED=" ${Yellow}●${ResetColor}"; fi # the number of staged files/directories + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS=" ${Red}✖ ${ResetColor}"; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED=" ${Blue}✚ ${ResetColor}"; fi # the number of changed files + + if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED=" ${BoldMagenta}⚑ ${ResetColor}"; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN=" ${Green}✔ ${ResetColor}"; fi # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"; fi + + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi + if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER="${BoldBlue} ➭ ${ResetColor}"; fi # Reset color for user + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${BoldRed} # "; fi # Bright red for Root + + # Please do not add colors to these symbols + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭"; fi # This symbol is written after the branch, if the branch is not tracked +} + +# call only from theme file +reload_git_prompt_colors() { + if [[ "${GIT_PROMPT_THEME_NAME}" != $1 ]]; then + unset_git_prompt_colors + define_helpers + override_git_prompt_colors + define_undefined_git_prompt_colors + fi +} + +if [[ "${GIT_PROMPT_THEME}" == "Single_line_Solarized" && "${GIT_PROMPT_THEME_NAME}" != "Single_line_Solarized" ]]; then + define_helpers + define_undefined_git_prompt_colors +fi + +overide_git_prompt_colors() { + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} \ No newline at end of file diff --git a/themes/Single_line_Ubuntu.bgptheme b/themes/Single_line_Ubuntu.bgptheme new file mode 100644 index 0000000..2a42acd --- /dev/null +++ b/themes/Single_line_Ubuntu.bgptheme @@ -0,0 +1,96 @@ +# This is an alternative approach. Single line in git repo. +# Theme optimised for Terminus and PowerLine compatible fonts. + +unset_git_prompt_colors() { + unset Time12a + unset PathShort + unset GIT_PROMPT_PREFIX + unset GIT_PROMPT_SUFFIX + unset GIT_PROMPT_SEPARATOR + unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_STAGED + unset GIT_PROMPT_CONFLICTS + unset GIT_PROMPT_CHANGED + unset GIT_PROMPT_REMOTE + unset GIT_PROMPT_UNTRACKED + unset GIT_PROMPT_STASHED + unset GIT_PROMPT_CLEAN + unset GIT_PROMPT_COMMAND_OK + unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_VIRTUALENV + unset GIT_PROMPT_START_USER + unset GIT_PROMPT_START_ROOT + unset GIT_PROMPT_END_USER + unset GIT_PROMPT_END_ROOT + unset GIT_PROMPT_SYMBOLS_AHEAD + unset GIT_PROMPT_SYMBOLS_BEHIND + unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING +} + +define_helpers() +{ + Time12a="\$(date +%H:%M)" + PathShort="\w"; +} + +define_undefined_git_prompt_colors() { + if [[ -z ${GIT_PROMPT_THEME_NAME} ]]; then GIT_PROMPT_THEME_NAME="Single_line_Ubuntu"; fi + + # These are the color definitions used by gitprompt.sh + if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="[ "; fi # start of the git info string + if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX=" ]"; fi # the end of the git info string + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR=" |"; fi # separates each item + + if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED=" ${Red}●${ResetColor}"; fi # the number of staged files/directories + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS=" ${Red}✖ ${ResetColor}"; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED=" ${Blue}✚ ${ResetColor}"; fi # the number of changed files + + if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED=" ${BoldBlue}⚑ ${ResetColor}"; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN=" ${BoldGreen}✔ ${ResetColor}"; fi # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${Cyan}${PathShort}${ResetColor}"; fi + + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi + if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER="${ResetColor} $ "; fi # Reset color for user + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${BoldRed} # "; fi # Bright red for Root + + # Please do not add colors to these symbols + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked +} + +# call only from theme file +reload_git_prompt_colors() { + if [[ "${GIT_PROMPT_THEME_NAME}" != $1 ]]; then + unset_git_prompt_colors + define_helpers + override_git_prompt_colors + define_undefined_git_prompt_colors + fi +} + +if [[ "${GIT_PROMPT_THEME}" == "Single_line_Ubuntu" && "${GIT_PROMPT_THEME_NAME}" != "Single_line_Ubuntu" ]]; then + define_helpers + define_undefined_git_prompt_colors +fi diff --git a/themes/Single_line_openSUSE.bgptheme b/themes/Single_line_openSUSE.bgptheme new file mode 100644 index 0000000..396006a --- /dev/null +++ b/themes/Single_line_openSUSE.bgptheme @@ -0,0 +1,19 @@ +# This is a theme for gitprompt.sh, +# it uses the default openSUSE bash prompt style with exit status + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_openSUSE" + GIT_PROMPT_BRANCH="${Cyan}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_CHANGED="${Yellow}✚ " + GIT_PROMPT_STAGED="${Magenta}●" + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${ResetColor}\u@\h:\w" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${BoldRed}\h:\w" + + GIT_PROMPT_END_USER="${ResetColor}> " + GIT_PROMPT_END_ROOT=" # ${ResetColor}" +} + +reload_git_prompt_colors "Single_line_openSUSE" + diff --git a/themes/Solarized.bgptheme b/themes/Solarized.bgptheme new file mode 100644 index 0000000..caf1ea8 --- /dev/null +++ b/themes/Solarized.bgptheme @@ -0,0 +1,13 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized" + GIT_PROMPT_STAGED="${Yellow}●" + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "Solarized" \ No newline at end of file diff --git a/themes/Solarized_Extravagant.bgptheme b/themes/Solarized_Extravagant.bgptheme new file mode 100644 index 0000000..f93c362 --- /dev/null +++ b/themes/Solarized_Extravagant.bgptheme @@ -0,0 +1,41 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts +# some modifications on colors +# added ruby prompt, and kernel version as well + +override_git_prompt_colors() { + if [ -e ~/.rvm/bin/rvm-prompt ]; then + RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' + else + if command -v rbenv > /dev/null; then + RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' + fi + fi + Time12a="\$(date +%H:%M:%S)" + + GIT_PROMPT_THEME_NAME="Solarized Extravagant" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + + KERNEL_PROMPT='‹$(uname -r)›' + +GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${BoldBlueFg}${Time12a} ${Green}${KERNEL_PROMPT} ${Cyan}${RUBY_PROMPT} ${Yellow}${PathShort}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + if [ -n "$SSH_CLIENT" ]; then + GIT_PROMPT_END_USER="\n${BoldRed} ➤ ${ResetColor}" + GIT_PROMPT_END_ROOT="\n${BoldRed} » ${ResetColor}" + else + GIT_PROMPT_END_USER="\n${BoldBlue} ➭ ${ResetColor}" + GIT_PROMPT_END_ROOT="\n${BoldRed} # ${ResetColor}" + fi + GIT_PROMPT_LEADING_SPACE=1 + GIT_PROMPT_PREFIX="${Cyan}[" + GIT_PROMPT_SUFFIX="${Cyan}]" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} + +reload_git_prompt_colors "Solarized Extravagant" diff --git a/themes/Solarized_NoExitState.bgptheme b/themes/Solarized_NoExitState.bgptheme new file mode 100644 index 0000000..77f8e50 --- /dev/null +++ b/themes/Solarized_NoExitState.bgptheme @@ -0,0 +1,16 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized NoExitState" + GIT_PROMPT_STAGED="${Yellow}●" + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔" + GIT_PROMPT_COMMAND_FAIL="${Red}✘" + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "Solarized NoExitState" \ No newline at end of file diff --git a/themes/Solarized_NoExitState_Ubuntu.bgptheme b/themes/Solarized_NoExitState_Ubuntu.bgptheme new file mode 100644 index 0000000..ae47548 --- /dev/null +++ b/themes/Solarized_NoExitState_Ubuntu.bgptheme @@ -0,0 +1,19 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized NoExitState Ubuntu" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "Solarized NoExitState Ubuntu" \ No newline at end of file diff --git a/themes/Solarized_Ubuntu.bgptheme b/themes/Solarized_Ubuntu.bgptheme new file mode 100644 index 0000000..a60a0ef --- /dev/null +++ b/themes/Solarized_Ubuntu.bgptheme @@ -0,0 +1,15 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized Ubuntu" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "Solarized Ubuntu" \ No newline at end of file