├── .gitignore ├── src ├── contrib │ └── .placeholder ├── themes │ ├── vms │ ├── git │ ├── giles │ └── progit └── libexec │ ├── prompt │ ├── print-face-colors │ ├── functions │ ├── face │ └── facecolors.rgb ├── screenshots ├── screenshot-1.png ├── screenshot-10.png ├── screenshot-11.png ├── screenshot-2.png ├── screenshot-3.png ├── screenshot-4.png ├── screenshot-5.png ├── screenshot-6.png ├── screenshot-7.png ├── screenshot-8.png └── screenshot-9.png ├── release-notes ├── README.commands ├── changelog ├── bldtgz ├── examples ├── template ├── how-it-all-works └── CUSTOMIZING ├── INSTALL ├── README ├── README.md ├── man └── face ├── install └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/contrib/.placeholder: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /screenshots/screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-1.png -------------------------------------------------------------------------------- /screenshots/screenshot-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-10.png -------------------------------------------------------------------------------- /screenshots/screenshot-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-11.png -------------------------------------------------------------------------------- /screenshots/screenshot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-2.png -------------------------------------------------------------------------------- /screenshots/screenshot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-3.png -------------------------------------------------------------------------------- /screenshots/screenshot-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-4.png -------------------------------------------------------------------------------- /screenshots/screenshot-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-5.png -------------------------------------------------------------------------------- /screenshots/screenshot-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-6.png -------------------------------------------------------------------------------- /screenshots/screenshot-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-7.png -------------------------------------------------------------------------------- /screenshots/screenshot-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-8.png -------------------------------------------------------------------------------- /screenshots/screenshot-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christopher-barry/bash-color-tools/HEAD/screenshots/screenshot-9.png -------------------------------------------------------------------------------- /release-notes: -------------------------------------------------------------------------------- 1 | 2 | ########################### IMPORTANT ########################### 3 | 4 | Affects all theme config files prior to v1.1.2 5 | 6 | The config file format for theme configurations in ~/.prompt-themes.d 7 | has changed, and WILL lead to breakage if left unchanged. 8 | 9 | You should either rename (if you modified them) or delete them, then 10 | log out and back in to automatically re-create the new default ones as 11 | you reload different themes. 12 | 13 | Until I can hack up a nice way around it, you'll need to manually 14 | migrate any previous color or character changes you made over to the 15 | new config file(s). Sorry for the inconvenience. 16 | 17 | -C 18 | 19 | ##################################################################### 20 | -------------------------------------------------------------------------------- /README.commands: -------------------------------------------------------------------------------- 1 | bash-color-tools 2 | ================================================================================ 3 | Copyright 2007-2012 Christopher Barry 4 | 5 | This file is part of the bash-color-tools 6 | 7 | bash-color-tools is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | ================================================================================ 21 | 22 | The following commands are part of the bash-color-tools: 23 | 24 | * face 25 | 26 | a hi-color echo command that can be used in scripts or on the 27 | commandline. 28 | 29 | type face -H for more information. 30 | 31 | 32 | * print-face-colors 33 | 34 | prints out color pallettes, and with '-v', also their rgb values 35 | to be used with face. 36 | 37 | can also be run with 'face -v colors' 38 | 39 | 40 | * prompt 41 | 42 | face and prompt work together to provide themeable colorized prompts. 43 | 44 | If you've installed bash-color-tools as root for use system-wide 45 | (recommended), each user should run: setup-prompt to get started. 46 | 47 | 48 | * setup-prompt 49 | 50 | setup-prompt adds a few lines of code to your .bashrc file that do 51 | the following: 52 | 53 | * sources the face colorizing functions 54 | * sources the prompt function framework 55 | * adds a commented out 'prompt' line for auto-starting prompt 56 | 57 | Follow the instructions printed after running setup-prompt as a 58 | user, once bash-color-tools has been successfully installed. 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /changelog: -------------------------------------------------------------------------------- 1 | bash-color-tools changelog 2 | 3 | 2014-2-8 Christopher Barry 4 | * fix more friggin typos... 5 | * new tag v1.1.2 6 | 7 | 2014-2-8 Christopher Barry 8 | * fix typo 9 | * output release notes ahead of normal welcome output 10 | * new tag v1.1.1 11 | 12 | 2014-2-7 Christopher Barry 13 | * added screenshots of prompt and face in action 14 | * fixed a low-color mode bug wrt xterm titlebar code 15 | * updated config file format to address above 16 | * fixed a color rendering bug when an invalid rgb was entered 17 | * new tag v1.1 18 | 19 | 2013-8-17 Christopher Barry 20 | * merge in color names code. all X colors as well as hex and 21 | decimal are now allowed. run 'face -H' for more info. 22 | * fix path bug for face help 23 | * lots of cool stuff in the progit theme, which is now the default 24 | * new .bctrc file for loading libs simplifies .bashrc mods 25 | * bct finally goes to v1.0 26 | 27 | 2013-4-8 Christopher Barry 28 | * lots of cleanup, typo corrections in docs, etc. 29 | * removed test fuzzy_truncation function. 30 | * fixed a latent bug in face that only recently became an issue 31 | with newer terminals. 32 | * reformatted this file to emacs changelog-mode. 33 | * new tag v0.9.9 34 | 35 | 2012-9-15 Christopher Barry 36 | * added bldtgz - generic versioned source tree tarballer 37 | * new tag v0.9.8 38 | 39 | 2012-9-13 Christopher Barry 40 | * reverse the order of this changelog 41 | 42 | 2012-9-12 Christopher Barry 43 | * add quick start section to INSTALL 44 | * refactor theme list printing 45 | * refactor prompt(), adding 'save' feature 46 | * complete draft of how-it-works 47 | * created 'setup-prompt' command to automate user configuration 48 | * moved CUSTOMIZING into ./examples/ 49 | * new tag v0.9.7 50 | 51 | 2012-9-08 Christopher Barry 52 | * fix README.commands .bashrc example - again 53 | * minor tweaks 54 | * modify all numeric tests to use (( ... )) construct 55 | 56 | 2012-9-04 Christopher Barry 57 | * fix README.commands .bashrc example 58 | * new tag v0.9.5 59 | 60 | 2012-9-03 Christopher Barry 61 | * new tag v0.9.4 62 | * add new theme 'giles' 63 | 64 | 2012-9-03 Christopher Barry 65 | * new tag v0.9.3 66 | * fixed bug mis-named filename 67 | * updated changelog 68 | 69 | 2012-9-03 Christopher Barry 70 | * new tag v0.9.2 71 | * fixed bug caused by empty directory. 72 | 73 | 2012-9-03 Christopher Barry 74 | * new tag v0.9.1 75 | * fixed 'list' bug caused by moving code off to own function. 76 | 77 | 2012-9-03 Christopher Barry 78 | * initial release tag 0.9.0 pushed into GitHub 79 | -------------------------------------------------------------------------------- /bldtgz: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # bldtgz 26 | #------------------------------------------------------------------------------- 27 | # generic versioned source tree tarball generator 28 | #=============================================================================== 29 | 30 | #------------------------------------------------------------------------------- 31 | function _get_pkg_version_() 32 | { 33 | git describe 2>/dev/null || { 34 | date | sed -e 's/\ /_/g' -e 's/\:/-/g' 35 | echo >&2 "Warning: not a git source dir, using *now* as version instead." 36 | } 37 | } 38 | 39 | #------------------------------------------------------------------------------- 40 | function _gen_pkg_name_() 41 | { 42 | local pkg_root=${0%/*} 43 | local pkg_name= 44 | ( 45 | cd ${pkg_root} 46 | pkg_name=${PWD} 47 | echo "${pkg_name##*/}-$(_get_pkg_version_)" 48 | ) 49 | } 50 | 51 | #------------------------------------------------------------------------------- 52 | function _create_build_dir_() 53 | { 54 | local pkg_name=${1} 55 | 56 | local build_dir=${TMPDIR:-/tmp}/bct-${RANDOM}-${RANDOM}-${RANDOM}/${pkg_name} 57 | mkdir -p ${build_dir} || return 1 58 | 59 | rsync -a --exclude=".git*" --exclude="bldtgz" ${0%/*}/ ${build_dir} 2>/dev/null || return 1 60 | echo "${build_dir}" 61 | } 62 | 63 | #------------------------------------------------------------------------------- 64 | function _create_tarball_() 65 | { 66 | local pkg_name=${1} 67 | local build_dir=${2} 68 | 69 | ( 70 | cd ${build_dir%/*} 71 | tar czvf ${pkg_name}.tgz ${pkg_name}/ || exit 1 72 | ) 73 | 74 | mv ${build_dir%/*}/${pkg_name}.tgz ${0%/*}/../ || exit 1 75 | echo >&2 "New package: ${0%/*}/../${pkg_name}.tgz" 76 | (( ${?} == 0 )) && rm -rf ${build_dir%/*} || return 1 77 | } 78 | 79 | #------------------------------------------------------------------------------- 80 | function _main_() 81 | { 82 | local pkg_name= 83 | pkg_name=$(_gen_pkg_name_) || return ${?} 84 | 85 | local build_dir= 86 | build_dir=$(_create_build_dir_ ${pkg_name}) 87 | [[ -d ${build_dir} ]] || { 88 | echo >&2 "Error: failed to create build directory '${build_dir}'" 89 | return 1 90 | } 91 | 92 | _create_tarball_ ${pkg_name} ${build_dir} || { 93 | echo >&2 "Error: failed to create tarball" 94 | return 1 95 | } 96 | 97 | return 0 98 | } 99 | 100 | #=============================================================================== 101 | _main_ 102 | -------------------------------------------------------------------------------- /examples/template: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; -*- 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # template 26 | #------------------------------------------------------------------------------- 27 | # theme template for prompt. see CUSTOMIZING in the doc directory for details. 28 | #=============================================================================== 29 | 30 | THEME=template 31 | 32 | #=============================================================================== 33 | # 'prompt template' 34 | # [09/02 17:15:50][...src/apps/]$ 35 | function prompt_template_theme() 36 | { 37 | # override and customize defaults with dotfile 38 | [[ -f ~/.prompt-themes.d/conf/${THEME}.theme ]] || { 39 | mkdir -p ~/.prompt-themes.d/conf 40 | cat > ~/.prompt-themes.d/conf/${THEME}.theme < 4 | 5 | This file is part of the bash-color-tools 6 | 7 | bash-color-tools is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | ================================================================================ 21 | 22 | QUICK START 23 | 24 | * get code (git or tarball) 25 | * as root, run: 26 | root@box# /path/to/code/install 27 | * then, as each user that wants a color prompt, run: 28 | user@box$ setup-prompt 29 | * follow instructions printed on the screen 30 | 31 | 32 | DETAILED INSTALLATION INSTRUCTIONS 33 | 34 | From cloned GitHub repo: 35 | ~~~~~~~~~~~~~~~~~~~~~~~~ 36 | To install bash-color-tools just run './install' from the cloned repo 37 | as root. This will install the absolute latest code system-wide, so 38 | everyone on the box can use it, each with their own personal settings. 39 | 40 | To install a particular version, use git describe to identify the 41 | available version tags, then checkout that tag to a branch with: 42 | 43 | me@box$ git checkout -b 44 | 45 | Then run ./install as root. 46 | 47 | 48 | From zipfile downloaded from GitHub: 49 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 50 | For a specific tagged release rather than master, select the tag in 51 | GitHub's interface, then select the Zip button and download it. 52 | 53 | Unzip it: 54 | 55 | me@box$ unzip bash-color-tools-.zip 56 | 57 | ...then install as root 58 | 59 | root@box# cd /path/to/bash-color-tools- 60 | root@box# ./install 61 | 62 | By default, this will install the code to: 63 | 64 | /usr/share/bash-color-tools/ 65 | 66 | and the docs to: 67 | 68 | /usr/share/doc/bash-color-tools/ 69 | 70 | symlinks for the face and print-face-colors commands will be installed 71 | into /usr/bin/. 72 | 73 | 74 | OTHER INSTALL LOCATIONS 75 | 76 | If you perfer to install into a different install root than /usr, for 77 | instance to say /usr/local, or even your own home directory, set the 78 | PREFIX var prior to installing, like: 79 | 80 | root@box# PREFIX=/usr/local ./install 81 | 82 | Or 83 | 84 | me@box$ PREFIX=~ ./install 85 | 86 | NOTE: keep in mind that executables will have symlinks created in 87 | ${PREFIX}/bin. If that bin dir is not in your path, stuff won't 88 | work. If it's not in the path, then add it to your startup script 89 | (e.g. ~/.bashrc) with: 90 | 91 | PATH=${PATH}:/the/prefix/you/used/bin 92 | export PATH 93 | 94 | install will bark at you after installing if that bin dir is not in 95 | the PATH 96 | 97 | 98 | UNINSTALLATION INSTRUCTIONS 99 | 100 | To uninstall, as root (typically) run the uninstall script located in 101 | the installation libexec directory, which by default is located at: 102 | 103 | root@box# /usr/share/bash-color-tools/libexec/uninstall 104 | 105 | You'll need to manually remove any personal dotfiles and themes in 106 | your home directory, located in ~/.prompt-themes.d/, as well as either 107 | comment out or remove any startup lines in user's .bashrc files. 108 | 109 | 110 | -------------------------------------------------------------------------------- /src/themes/vms: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; -*- 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # vms 26 | #------------------------------------------------------------------------------- 27 | # vms theme for prompt 28 | #=============================================================================== 29 | 30 | THEME=vms 31 | 32 | #=============================================================================== 33 | # 'prompt vms' 34 | # [bob@host][...src/apps/]:: 35 | function prompt_vms_theme() 36 | { 37 | # override and customize defaults with dotfile 38 | [[ -f ~/.prompt-themes.d/conf/${THEME}.theme ]] || { 39 | mkdir -p ~/.prompt-themes.d/conf 40 | cat >~/.prompt-themes.d/conf/${THEME}.theme < 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # git 26 | #------------------------------------------------------------------------------- 27 | # git theme for prompt 28 | #=============================================================================== 29 | 30 | THEME=git 31 | 32 | #=============================================================================== 33 | # 'prompt git' 34 | # [master][...src/apps/]$ 35 | function prompt_git_theme() 36 | { 37 | # override and customize defaults with dotfile 38 | [[ -f ~/.prompt-themes.d/conf/${THEME}.theme ]] || { 39 | mkdir -p ~/.prompt-themes.d/conf 40 | cat > ~/.prompt-themes.d/conf/${THEME}.theme </dev/null)" =~ [*][[:blank:]]([-a-zA-Z0-9_. ]+) ]] 90 | then 91 | gb="${BASH_REMATCH[1]}" 92 | prompt_truncate ${PROMPT_MAXBRANCHLEN} "${gb}" 93 | else 94 | prompt_truncate ${PROMPT_MAXBRANCHLEN} "${PROMPT_NOGIT_CHAR}" 95 | fi 96 | 97 | return 0 98 | } 99 | # short alias 100 | function pgb() { prompt_git_branch "${@}"; } 101 | 102 | 103 | # init globals 104 | prompt_git_theme 105 | 106 | # set colors 107 | l=${PROMPT_LOW_CLR:+l} 108 | lb="$(_face -P${l}nf ${PROMPT_BRKT_CLR} "${PROMPT_LBRKT_CHAR}")" 109 | rb="$(_face -P${l}nf ${PROMPT_BRKT_CLR} "${PROMPT_RBRKT_CHAR}")" 110 | sc="$(_face -P${l}nf ${PROMPT_SYM_CLR} "${PROMPT_SYM_CHAR}")" 111 | # the following two arrays elements wrap the 112 | # calculated branch and dir in color escape codes 113 | d=( $(_face -P${l}nf ${PROMPT_DIR_CLR} " ") ) 114 | b=( $(_face -P${l}nf ${PROMPT_GITBRANCH_CLR} " ") ) 115 | 116 | # set the prompt 117 | [[ ${PROMPT_LOW_CLR} ]] && { 118 | # remove xterm titlebar code in console mode 119 | PS1="${lb}${b[0]}\$(pgb)${b[1]}${rb}${lb}${d[0]}\$(pgp)${d[1]}${rb}${sc}" 120 | } || { 121 | PS1="${xt[0]}\u@\H:\w${xt[1]}${lb}${b[0]}\$(pgb)${b[1]}${rb}${lb}${d[0]}\$(pgp)${d[1]}${rb}${sc}" 122 | } 123 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | # Bash Color Tools 3 | 4 | bash-color-tools was created to solve a two problems that there were 5 | no simple existing solutions for: 6 | 7 | ### Bash Prompt Color Themes 8 | * I wanted an easy way to modify, set, and save Color Bash Prompt 9 | setups. The standard 8 colors are simply ugly, so being able to have 10 | hundreds of colors to choose from was a must. Plus, being able to 11 | easily and simply change the colors at will, ideally by X Color 12 | Name, or a standard hex or decimal value would also be great. 13 | 14 | ### Color Echo command 15 | * I wanted an easy to use full-color echo command for use in scripts 16 | that worked just like echo, but could output in full color - not 17 | just the boring 8 colors that most HOW-TOs would teach you how to 18 | generate. And it had to insulate me from those horrible escape 19 | codes! Ideally, it could output those codes un-evaluated, for 20 | setting into variables if desired, say to put into the $PS1 21 | variable. 22 | 23 | I tried a few python color prompt scripts first. They looked pretty 24 | cool, but the lag was unbearable. It needed it to be lightweight and 25 | fast. It definitely shouldn't need to load another separate script 26 | interpreter to execute it. It simply had to be in clean, tight bash to 27 | give the lowest latency script performance possible. 28 | 29 | 30 | So, this is exactly what bash-color-tools sets out to provide: 31 | 32 | ### 'prompt' 33 | * A full-color Bash Prompt theme framework that's easily customizable, 34 | and uses theme plugins to allow you to easily change the colors of 35 | every prompt string element, extend existing themes, or even create 36 | your own themes by starting off with the provided theme template and 37 | going from there. There's instructions in the examples directory to 38 | help you with that. Provides the ability to quickly toggle between 39 | the different themes. Also allows low-color mode themes for the 40 | Linux Terminal. If you create a cool theme, let me know and I'll add 41 | it in. 42 | 43 | ### 'face' 44 | * A full-color echo-like command with all the semantics of echo, plus 45 | extensions for background and forground color designation, and can 46 | even output raw escape coded strings if you need them (which, as it 47 | turns out, prompt does). 48 | 49 | ### '_face' 50 | * A sourceable library for your scripts, so all invocations of face 51 | come from memory, rather than running the command off disk. 52 | 53 | 54 | ## Standard Color Bash Prompt Themes: 55 | 56 | * 'progit' is the default theme, and provides a very full-featured git 57 | status dashboard when inside a repository, and the date/time and 58 | current system load data when in a regular directory. It 59 | automatically 'fuzzy-truncates' (adjustable length and fuzzyness 60 | values) both the current dir path and the branch names to keep the 61 | prompt at a resonable length. The git dashboard shows the number of 62 | untracked files, index vs. tree status, merge status, commit status, 63 | etc., and the branch field will indicate if the remote is out of 64 | sync with your current tree. When your tree is up to date, it shows 65 | the current branch, and the standard time/date and system load 66 | header. This is quite possibly the most extensive git info in any 67 | prompt anywhere, while still being very fast and unobtrusive. 68 | 69 | * 'git' is progit's predecessor, and not quite as fully featured. It 70 | does provide the basics though, and is a bit faster if you have a 71 | low powered machine. 72 | 73 | * 'giles' is an homage to Giles Orr, the original Bash Prompt Howto 74 | author. 75 | 76 | * 'vms' is an homage to the VMS Operating System I used so many years 77 | ago. 78 | 79 | 80 | ## Screenshots 81 | 82 | ![prompt image 1](/screenshots/screenshot-1.png?raw=true "Inside an up to date repo") 83 | 84 | ![prompt image 2](/screenshots/screenshot-2.png?raw=true "Untracked file added to repo") 85 | 86 | ![prompt image 3](/screenshots/screenshot-3.png?raw=true "Files staged") 87 | 88 | ![prompt image 4](/screenshots/screenshot-4.png?raw=true "Push puts remote in sync") 89 | 90 | ![prompt image 5](/screenshots/screenshot-5.png?raw=true "Git commit") 91 | 92 | ![prompt image 6](/screenshots/screenshot-6.png?raw=true "less -R shows 'face' palletes") 93 | 94 | ![prompt image 7](/screenshots/screenshot-7.png?raw=true "face pallette 1") 95 | 96 | ![prompt image 8](/screenshots/screenshot-8.png?raw=true "face pallette 2") 97 | 98 | ![prompt image 9](/screenshots/screenshot-9.png?raw=true "face pallette 3") 99 | 100 | ![prompt image 10](/screenshots/screenshot-10.png?raw=true "Using face to echo color strings") 101 | 102 | ![prompt image 11](/screenshots/screenshot-11.png?raw=true "Showing all of the color definition methods") 103 | 104 | 105 | Manpage 106 | 107 | Tested on Linux and Mac OSX (after installing bash v4.x) 108 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Bash Color Tools 3 | 4 | bash-color-tools was created to solve a two problems that there were 5 | no simple existing solutions for: 6 | 7 | ### Bash Prompt Color Themes 8 | * I wanted an easy way to modify, set, and save Color Bash Prompt 9 | setups. The standard 8 colors are simply ugly, so being able to have 10 | hundreds of colors to choose from was a must. Plus, being able to 11 | easily and simply change the colors at will, ideally by X Color 12 | Name, or a standard hex or decimal value would also be great. 13 | 14 | ### Color Echo command 15 | * I wanted an easy to use full-color echo command for use in scripts 16 | that worked just like echo, but could output in full color - not 17 | just the boring 8 colors that most HOW-TOs would teach you how to 18 | generate. And it had to insulate me from those horrible escape 19 | codes! Ideally, it could output those codes un-evaluated, for 20 | setting into variables if desired, say to put into the $PS1 21 | variable. 22 | 23 | I tried a few python color prompt scripts first. They looked pretty 24 | cool, but the lag was unbearable. It needed it to be lightweight and 25 | fast. It definitely shouldn't need to load another separate script 26 | interpreter to execute it. It simply had to be in clean, tight bash to 27 | give the lowest latency script performance possible. 28 | 29 | 30 | So, this is exactly what bash-color-tools sets out to provide: 31 | 32 | ### 'prompt' 33 | * A full-color Bash Prompt theme framework that's easily customizable, 34 | and uses theme plugins to allow you to easily change the colors of 35 | every prompt string element, extend existing themes, or even create 36 | your own themes by starting off with the provided theme template and 37 | going from there. There's instructions in the examples directory to 38 | help you with that. Provides the ability to quickly toggle between 39 | the different themes. Also allows low-color mode themes for the 40 | Linux Terminal. If you create a cool theme, let me know and I'll add 41 | it in. 42 | 43 | ### 'face' 44 | * A full-color echo-like command with all the semantics of echo, plus 45 | extensions for background and forground color designation, and can 46 | even output raw escape coded strings if you need them (which, as it 47 | turns out, prompt does). 48 | 49 | ### '_face' 50 | * A sourceable library for your scripts, so all invocations of face 51 | come from memory, rather than running the command off disk. 52 | 53 | 54 | ## Standard Color Bash Prompt Themes: 55 | 56 | * 'progit' is the default theme, and provides a very full-featured git 57 | status dashboard when inside a repository, and the date/time and 58 | current system load data when in a regular directory. It 59 | automatically 'fuzzy-truncates' (adjustable length and fuzzyness 60 | values) both the current dir path and the branch names to keep the 61 | prompt at a resonable length. The git dashboard shows the number of 62 | untracked files, index vs. tree status, merge status, commit status, 63 | etc., and the branch field will indicate if the remote is out of 64 | sync with your current tree. When your tree is up to date, it shows 65 | the current branch, and the standard time/date and system load 66 | header. This is quite possibly the most extensive git info in any 67 | prompt anywhere, while still being very fast and unobtrusive. 68 | 69 | * 'git' is progit's predecessor, and not quite as fully featured. It 70 | does provide the basics though, and is a bit faster if you have a 71 | low powered machine. 72 | 73 | * 'giles' is an homage to Giles Orr, the original Bash Prompt Howto 74 | author. 75 | 76 | * 'vms' is an homage to the VMS Operating System I used so many years 77 | ago. 78 | 79 | 80 | ## Screenshots 81 | 82 | ![prompt image 1](/screenshots/screenshot-1.png?raw=true "Inside an up to date repo") 83 | 84 | ![prompt image 2](/screenshots/screenshot-2.png?raw=true "Untracked file added to repo") 85 | 86 | ![prompt image 3](/screenshots/screenshot-3.png?raw=true "Files staged") 87 | 88 | ![prompt image 4](/screenshots/screenshot-4.png?raw=true "Push puts remote in sync") 89 | 90 | ![prompt image 5](/screenshots/screenshot-5.png?raw=true "Git commit") 91 | 92 | ![prompt image 6](/screenshots/screenshot-6.png?raw=true "less -R shows 'face' palletes") 93 | 94 | ![prompt image 7](/screenshots/screenshot-7.png?raw=true "face pallette 1") 95 | 96 | ![prompt image 8](/screenshots/screenshot-8.png?raw=true "face pallette 2") 97 | 98 | ![prompt image 9](/screenshots/screenshot-9.png?raw=true "face pallette 3") 99 | 100 | ![prompt image 10](/screenshots/screenshot-10.png?raw=true "Using face to echo color strings") 101 | 102 | ![prompt image 11](/screenshots/screenshot-11.png?raw=true "Showing all of the color definition methods") 103 | 104 | 105 | Manpage 106 | 107 | Tested on Linux and Mac OSX (after installing bash v4.x) 108 | -------------------------------------------------------------------------------- /src/libexec/prompt: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; -*- 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # prompt 26 | #------------------------------------------------------------------------------- 27 | # generate theme-able and customizable shell prompts 28 | #=============================================================================== 29 | 30 | (( ${BASH_VERSINFO:-0} >= 4 )) || { 31 | echo "Sorry, gotta have bash version >= 4 to run this." 32 | exit 1 33 | } 34 | 35 | declare THEME_DIR=/usr/share/bash-color-tools/themes 36 | export THEME_DIR 37 | 38 | #=============================================================================== 39 | # set the prompt 40 | function prompt() 41 | { 42 | (( ${#} == 0 )) && { 43 | echo "Usage: prompt " 44 | echo "'prompt save' to modify ~/.bctrc to autostart current theme" 45 | return 1 46 | } 47 | 48 | # make various functions accessible to all themes 49 | [[ -f ${THEME_DIR%/*}/libexec/functions ]] && { 50 | source ${THEME_DIR%/*}/libexec/functions 51 | } || { 52 | echo "${THEME_DIR%/*}/libexec/functions lib missing. cannot continue." 53 | return 1 54 | } 55 | case ${1} in 56 | 57 | list) 58 | prompt_theme_list || { 59 | echo "hmm. no themes appear to be installed. try re-installing." 60 | return 1 61 | } 62 | return 0 63 | ;; 64 | 65 | save) 66 | prompt_save_to_bctrc || { 67 | echo "unable to save settings to ~/.bctrc" 68 | return 1 69 | } 70 | echo "theme '${THEME:-builtin}' is set to autostart" 71 | return 0 72 | ;; 73 | esac 74 | 75 | # find and load the specified theme in following order. 76 | # personal, standard, then contrib version 77 | # first found with same name wins 78 | if [[ -f ~/.prompt-themes.d/${1} ]]; then 79 | source ~/.prompt-themes.d/${1} 80 | elif [[ -f ${THEME_DIR}/${1} ]]; then 81 | source ${THEME_DIR}/${1} 82 | elif [[ -f ${THEME_DIR%/*}/contrib/${1} ]]; then 83 | source ${THEME_DIR%/*}/contrib/${1} 84 | else 85 | THEME=builtin 86 | [[ "${1}" != "${THEME}" ]] && { 87 | echo "theme '${1}' not found. using builtin defaults." 88 | echo "use 'prompt list' to view available themes" 89 | echo "see CUSTOMIZING for how to customize" 90 | } 91 | # max length of path to display 92 | PROMPT_MAXPATHLEN=20 93 | # default color rgb for prompt elements 94 | case ${TERM} in 95 | Linux) 96 | PROMPT_LOW_CLR=1 97 | PROMPT_USER_CLR=cyan 98 | PROMPT_AT_CLR=gray 99 | PROMPT_HOST_CLR=cyan 100 | PROMPT_DIR_CLR=blue 101 | PROMPT_SYM_CLR=brightblue 102 | ;; 103 | *) 104 | PROMPT_USER_CLR=011 105 | PROMPT_AT_CLR=122 106 | PROMPT_HOST_CLR=011 107 | PROMPT_DIR_CLR=135 108 | PROMPT_SYM_CLR=025 109 | ;; 110 | esac 111 | (( $(id -u) == 0 )) && { 112 | PROMPT_SYM_CHAR='# ' 113 | } || { 114 | PROMPT_SYM_CHAR='$ ' 115 | } 116 | l=${PROMPT_LOW_CLR:+l} 117 | u="$(_face -P${l}nf ${PROMPT_USER_CLR} "$(whoami)")" 118 | a="$(_face -P${l}nf ${PROMPT_AT_CLR} "@")" 119 | h="$(_face -P${l}nf ${PROMPT_HOST_CLR} "${HOSTNAME}:")" 120 | rb="$(_face -P${l}nf ${PROMPT_BRKT_CLR} "${PROMPT_RBRKT_CHAR}")" 121 | sc="$(_face -P${l}nf ${PROMPT_SYM_CLR} "${PROMPT_SYM_CHAR}")" 122 | # the following array wraps the 123 | # calculated dir in color escape codes 124 | d=( $(_face -P${l}nf ${PROMPT_DIR_CLR} " ") ) 125 | 126 | # set the default prompt 127 | [[ ${PROMPT_LOW_CLR} ]] && { 128 | PS1="${xt[1]}${u}${a}${h}${d[0]}\$(pgp)${d[1]}${sc}" 129 | } || { 130 | PS1="${xt[0]}\u@\h:\w${xt[1]}${u}${a}${h}${d[0]}\$(pgp)${d[1]}${sc}" 131 | } 132 | fi 133 | 134 | } 135 | 136 | export -f prompt 137 | -------------------------------------------------------------------------------- /examples/how-it-all-works: -------------------------------------------------------------------------------- 1 | bash-color-tools 2 | ================================================================================ 3 | Copyright 2007-2012 Christopher Barry 4 | 5 | This file is part of the bash-color-tools 6 | 7 | bash-color-tools is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | ================================================================================ 21 | 22 | How It All Works 23 | ~~~~~~~~~~~~~~~~ 24 | 25 | bash-color-tools is essentially two major components: 26 | 27 | * face - a colorizing echo command, and 28 | * prompt - a plugin-based, theme-able, bash shell color prompt framework. 29 | 30 | 31 | face 32 | ~~~~ 33 | face works like echo, but in hundreds of colors. 34 | face can be run standalone as a simple command. 35 | 36 | If you've installed bash-color-tools, cut and paste these into your 37 | terminal to see what they do: 38 | 39 | face -f 555 -b 500 " WARNING! " 40 | face -f 050 "Success" 41 | face -f 540 "this is a string with forground color" 42 | face -f 540 -b 300 "this is a string with forground and background color" 43 | color ---^^^----^^^- is represented as an 'rgb' value triplet. In light, 44 | the three primary colors are Red, Green and Blue (rgb). 45 | 46 | -f sets forground color 47 | -b sets background color 48 | Use -H for more help with face 49 | 50 | https://en.wikipedia.org/wiki/List_of_software_palettes#6_level_RGB 51 | describes the indexed type of color used in color generating engine. 52 | 53 | 540 means red=5,green=4,blue=0. Each of r, g and b can be a value of 0 54 | thru 5, e.g. r=(0 thru 5), g=(0 thru 5) and b=(0 thru 5), so the total 55 | range is 000 (black) to 555 (white). The displayed color is the 56 | *combination* of those three color values - just like mixing colored 57 | light (not paint!). Try adjusting the rgb values of the examples above 58 | in your terminal to see how the colors change. 59 | 60 | Run the following to show a (non-exhaustive) demo of various colors 61 | and their associated 'rgb' values: 62 | 63 | face -v colors 64 | 65 | 66 | Using face in scripts 67 | ~~~~~~~~~~~~~~~~~~~~~ 68 | face can also be used as a library, meaning it's function can be kept 69 | in the environment so it works faster. To do this, it's sourced with 70 | the 'libmode' parameter: 71 | 72 | source /path/to/face libmode 73 | 74 | Then, from your scripts it's called using the function name '_face' 75 | instead of the script file name 'face'. All of the same options apply 76 | (see face -H for details). 77 | 78 | 79 | 80 | prompt 81 | ~~~~~~ 82 | prompt uses face as it's core library to create hi-color bash shell 83 | prompts. In normal 'echo' mode, face produces terminal 'escape' 84 | sequences that generate color directly in the terminal. In 'prompt 85 | string' mode (-P), face produces specially escaped strings that can be 86 | assigned to the PS1 variable. The shell writes the contents of the PS1 87 | variable to the screen each time enter is pressed. A typical prompt 88 | looks like: 89 | 90 | user@host:/some/directory$ 91 | 92 | A prompt generated using 'prompt' can be in any color or combination 93 | of colors, and generally includes other handy infomation as well, such 94 | as: 95 | * date / time 96 | * current git branch 97 | * auto-trimmed current directory name 98 | 99 | Here's an example of the 'giles' prompt theme: 100 | 101 | (@monolith)-(17:19 / Wed Sep 12) 102 | [-][~]:: cd src/bash-color-tools/ 103 | (@monolith)-(17:20 / Wed Sep 12) 104 | [master][.../src/bash-color-tools]:: 105 | 106 | It's a two-line prompt theme, and it looks a little bit 'busy' without 107 | color here in this file. Notice that before I changed directories, 108 | the basic cmdline portion looked like: 109 | 110 | [-][~]:: 111 | 112 | then, after I went into a git source-controlled directory, it changed 113 | to: 114 | 115 | [master][.../src/bash-color-tools]:: 116 | 117 | Notice also that the current directory portion has been trimmed to 118 | keep it at a resonable length. This is a tunable length that is set in 119 | in each theme configuration file, which are located in: 120 | 121 | ~/.prompt-themes.d/conf/.theme 122 | 123 | The above configuration files also allow the setting of colors and 124 | characters and anything else the theme author allows you to set - it's 125 | very flexible. 126 | 127 | The 'giles' theme uses a 'fuzzy' string truncation function that tries 128 | to slice the string on a delimiter, if a delimiter is within a 129 | fuzzfactor length on either side of the maximum length specified. 130 | 131 | The same fuzzy truncation happens for the branch names as well in the 132 | 'giles' theme. Other themes here currently just use a hard length to 133 | truncate at, but all of this is easily customizable. 134 | 135 | See CUSTOMIZING for details on creating your own themes. 136 | -------------------------------------------------------------------------------- /man/face: -------------------------------------------------------------------------------- 1 | face(8) 2 | 3 | NAME 4 | face - output colored text to a terminal or to an escape-code formated string. 5 | Optionally face can be sourced and used as a library, or generate color 6 | pallette output to the screen. 7 | 8 | SYNOPSIS 9 | face <-h|-H> 10 | 11 | face <[-P] [-l] [-n] [-e] [-f ] [-b ] 'message'> 12 | color-format := color-name|face-rgb|hex-rgb|dec-rgb 13 | 14 | face <[-v] colors> 15 | 16 | source /path/to/face 17 | 18 | 19 | DESCRIPTION 20 | Outputs colored text to the screen, or alternatively outputs a string formated 21 | for use in the $PS1 prompt variable. Optionally can be sourced and used as a 22 | library using 'libmode'. Optionally, can output color pallettes to the screen. 23 | 24 | color-format: 25 | color-format can be in one of four possible input formats: 26 | * 'color-name', 'face-rgb', 'hex-rgb', or 'dec-rgb' 27 | 28 | 'color-name' follows the single-word X Consortium color naming conv- 29 | entions, such as 'salmon' and 'DarkGoldenrod'. These colors will be 30 | approximated. 'color-name', when used in low-color mode (-l) is 31 | limited to the standard console colors; 32 | white, black, red, green, blue, yellow, purple and gray, plus enhanced 33 | versions for forground only (e.g. bright). 34 | 35 | 'face-rgb' is a triplet of three numbers, each zero-thru-5, where each 36 | number represents the color saturation of the color it represents. 37 | For example, 500 represent a red value of 5, and green and blue values 38 | of zero, representing pure red. 050 would be pure green, and 005 would 39 | be pure blue. These 3 numbers in combination can produce up to 216 40 | colors. When the numbers are all the same, as in 333, they represent 41 | six shades of the grayscale, where 000 is black, and 555 is white. 42 | 43 | 'hex-rgb' follows the standard hexadecimal rgb format without the '#' 44 | prefix, such that FF0000 is red, 00FF00 is green and 0000FF is blue. 45 | 46 | 'dec-rgb' follows the standard comma-separated decimal triplet format 47 | such that 255,0,0 is red, 0,255,0 is green and 0,0,255 is blue. 48 | 49 | NOTES: 50 | * Invalid specifications will be rendered neutral gray. 51 | * color-name, hex-rgb, and dec-rgb are approximations due to limited 52 | color space available in the shell 53 | 54 | -b 55 | Set background color. 56 | 57 | -e 58 | Process escape sequences in the string to be output, such as \t or \n. 59 | When used with -P, will preserve the sequence in the output. 60 | 61 | -f 62 | Set foreground color. 63 | 64 | -h, -H 65 | Terse and verbose help text, respectively. 66 | 67 | -l 68 | Use low-color mode. Low-color mode is limited to the standard console 69 | color pallet consisting of the following normal and enhanced (bold) 70 | colors: 71 | 72 | Background: white, black, red, green, blue, yellow, purple and gray. 73 | 74 | Foreground: All the background colors, plus the enhanced (bold) versions, 75 | identified by the 'bright' prefix, e.g 'brightred'. 76 | 77 | Only 'color-name' color-format is valid in low-color mode. 78 | 79 | -n 80 | Supresses newline at end of output. 81 | 82 | -P 83 | Outputs a non-evaluated, escape-code formatted string suitable for 84 | use in $PS1 prompt strings. 85 | 86 | -v 87 | Used with 'colors' parameter to output 'face-rgb' triplets with the 88 | color pallette output. 89 | 90 | colors 91 | Generate color pallette examples to the screen. 92 | 93 | libmode 94 | When sourced with only the 'libmode' parameter, installs the function 95 | _face() into the environment to be called via script. This speeds up 96 | operation as the file 'face' does not need to be loaded on each 97 | invocation. 98 | 99 | EXAMPLES 100 | In an xterm (hi-color mode), these all output white text on a red background 101 | face -f white -b red ' here is my message ' 102 | face -f 555 -b 500 ' here is my message ' 103 | face -f 000000 -b FF0000 ' here is my message ' 104 | face -f 255,255,255 -b 255,0,0 ' here is my message ' 105 | 106 | Or in low color mode for the Linux console... 107 | face -lf white -b red ' here is my message ' 108 | 109 | Generate parts of a built-up prompt string for use with \$PS1 110 | str1=$(face -Pnf 237 'my prompt string part') 111 | ... 112 | PS1="${str1}...${strN}" 113 | 114 | Use as a library from scripts... 115 | source /path/to/face libmode 116 | Then substitute '_face' for 'face', and all the same options apply. 117 | 118 | Output several funky made-up color pallettes to the screen 119 | face colors 120 | include the 'face-rgb' input triple for each color 121 | face -v colors 122 | 123 | AUTHOR 124 | Written by Christopher R. Barry 125 | 126 | REPORTING BUGS 127 | Report face bugs to 128 | 129 | COPYRIGHT 130 | Copyright © 2007-2014 Christopher R. Barry 131 | License GPLv3+ GNU GPL version 3 or later 132 | . 133 | 134 | This is free software: you are free to change and redistribute it. 135 | There is NO WARRANTY, to the extent permitted by law. 136 | 137 | SEE ALSO 138 | prompt - a themable bash shell prompt framework 139 | 140 | 141 | bash-color-tools February 2014 face(8) 142 | -------------------------------------------------------------------------------- /src/themes/giles: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; -*- 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # giles 26 | #------------------------------------------------------------------------------- 27 | # homage to Giles Orr, with a little git thrown in 28 | #=============================================================================== 29 | 30 | THEME=giles 31 | 32 | #=============================================================================== 33 | # 'prompt giles' 34 | # (@mybox)-(12:34 / Mon Nov 27) 35 | # [master][...src/apps/]:: 36 | function prompt_giles_theme() 37 | { 38 | # override and customize defaults with dotfile 39 | [[ -f ~/.prompt-themes.d/conf/${THEME}.theme ]] || { 40 | mkdir -p ~/.prompt-themes.d/conf 41 | cat > ~/.prompt-themes.d/conf/${THEME}.theme </dev/null)" =~ [*][[:blank:]]([-a-zA-Z0-9_. ]+) ]] 121 | then 122 | gb="${BASH_REMATCH[1]}" 123 | prompt_fuzzy_truncate ${PROMPT_MAXBRANCHLEN} ${PROMPT_BRANCH_FUZZFACTOR} ${PROMPT_BRANCH_DELIM} "${gb}" 124 | else 125 | prompt_fuzzy_truncate ${PROMPT_MAXBRANCHLEN} ${PROMPT_BRANCH_FUZZFACTOR} ${PROMPT_BRANCH_DELIM} "${PROMPT_NOGIT_CHAR}" 126 | fi 127 | 128 | return 0 129 | } 130 | # short alias 131 | function pgfb() { prompt_git_fuzzy_branch "${@}"; } 132 | 133 | 134 | # init globals 135 | prompt_giles_theme 136 | 137 | # set low color mode if needed 138 | l=${PROMPT_LOW_CLR:+l} 139 | # set colors 140 | lb="$(_face -P${l}nf ${PROMPT_BRKT_CLR} "${PROMPT_LBRKT_CHAR}")" 141 | rb="$(_face -P${l}nf ${PROMPT_BRKT_CLR} "${PROMPT_RBRKT_CHAR}")" 142 | lp="$(_face -P${l}nf ${PROMPT_PAREN_CLR} "${PROMPT_LPAREN_CHAR}")" 143 | rp="$(_face -P${l}nf ${PROMPT_PAREN_CLR} "${PROMPT_RPAREN_CHAR}")" 144 | da="$(_face -P${l}nf ${PROMPT_DASH_CLR} "${PROMPT_DASH_CHAR}")" 145 | sl="$(_face -P${l}nf ${PROMPT_SLASH_CLR} "${PROMPT_SLASH_CHAR}")" 146 | at="$(_face -P${l}nf ${PROMPT_AT_CLR} "${PROMPT_AT_CHAR}")" 147 | sc="$(_face -P${l}nf ${PROMPT_SYM_CLR} "${PROMPT_SYM_CHAR}")" 148 | 149 | # the following arrays elements wrap the 150 | # calculated values in color escape codes 151 | h=( $(_face -P${l}nf ${PROMPT_HOST_CLR} " ") ) 152 | tm=( $(_face -P${l}nf ${PROMPT_TIME_CLR} " ") ) 153 | dt=( $(_face -P${l}nf ${PROMPT_DATE_CLR} " ") ) 154 | b=( $(_face -P${l}nf ${PROMPT_GITBRANCH_CLR} " ") ) 155 | d=( $(_face -P${l}nf ${PROMPT_DIR_CLR} " ") ) 156 | 157 | # set the prompt 158 | [[ ${PROMPT_LOW_CLR} ]] && { 159 | PS1="${lp}${at}${h[0]}\H${h[1]}${rp}${da}${lp}${tm[0]}\$(date '+%R')${tm[1]} ${sl} ${dt[0]}\d${dt[1]}${rp}\n${lb}${b[0]}\$(pgfb)${b[1]}${rb}${lb}${d[0]}\$(pgfp)${d[1]}${rb}${sc}" 160 | } || { 161 | PS1="${xt[0]}\u@\h:\w${xt[1]}${lp}${at}${h[0]}\H${h[1]}${rp}${da}${lp}${tm[0]}\$(date '+%R')${tm[1]} ${sl} ${dt[0]}\d${dt[1]}${rp}\n${lb}${b[0]}\$(pgfb)${b[1]}${rb}${lb}${d[0]}\$(pgfp)${d[1]}${rb}${sc}" 162 | } 163 | -------------------------------------------------------------------------------- /src/libexec/print-face-colors: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # print-face-colors 26 | #------------------------------------------------------------------------------- 27 | # prints various and sundry color pallettes and their rgb values for 'face' 28 | # 29 | # not an exhaustive or even technically correct set of pallettes, it simply 30 | # dumps a bunch of colored blocks and shows the rgb numbers to produce them. 31 | #=============================================================================== 32 | 33 | (( ${BASH_VERSINFO:-0} >= 4 )) || { 34 | echo "Sorry, gotta have bash version >= 4 to run this." 35 | exit 1 36 | } 37 | 38 | #------------------------------------------------------------------------------- 39 | # rgb mode (highcolor) demo for 'face' command 40 | # quasi-random pallette-like thingies... 41 | #------------------------------------------------------------------------------- 42 | function pallette() 43 | { 44 | echo " HiColor Output" 45 | echo 46 | local r=1 g=1 b=1 47 | echo " Primary Pallette" 48 | 49 | until (( ${r} == 6 )); do 50 | pallette_row ${r}00 51 | ((r++)) 52 | done 53 | until (( ${g} == 6 )); do 54 | pallette_row 0${g}0 55 | ((g++)) 56 | done 57 | until (( ${b} == 6 )); do 58 | pallette_row 00${b} 59 | ((b++)) 60 | done 61 | echo 62 | 63 | echo " Secondary Pallette" 64 | 65 | local r=1 g=0 b=1 66 | until (( ${b} == 6 )); do 67 | pallette_row ${r}0${b} 68 | ((r++)) 69 | ((b++)) 70 | done 71 | local r=1 g=1 b=0 72 | until (( ${r} == 6 )); do 73 | pallette_row ${r}${g}0 74 | ((r++)) 75 | ((g++)) 76 | done 77 | local r=0 g=1 b=1 78 | until (( ${g} == 6 )); do 79 | pallette_row 0${g}${b} 80 | ((g++)) 81 | ((b++)) 82 | done 83 | echo 84 | 85 | echo " Nested loop" 86 | local r=0 g=0 b=0 87 | for r in {1..5}; do 88 | pallette_row ${r}${g}${b} 89 | for g in {1..5}; do 90 | pallette_row ${r}${g}${b} 91 | for b in {1..5}; do 92 | pallette_row ${r}${g}${b} 93 | done 94 | done 95 | done 96 | echo 97 | 98 | echo " Red Cummulative loop" 99 | local r=0 g=0 b=0 100 | for r in {1..5}; do 101 | pallette_row ${r}${g}${b} 102 | done 103 | for g in {1..5}; do 104 | pallette_row ${r}${g}${b} 105 | done 106 | for b in {1..5}; do 107 | pallette_row ${r}${g}${b} 108 | done 109 | echo 110 | 111 | echo " Green Cummulative loop" 112 | local r=0 g=0 b=0 113 | for g in {1..5}; do 114 | pallette_row ${r}${g}${b} 115 | done 116 | for b in {1..5}; do 117 | pallette_row ${r}${g}${b} 118 | done 119 | for r in {1..5}; do 120 | pallette_row ${r}${g}${b} 121 | done 122 | echo 123 | 124 | echo " Blue Cummulative loop" 125 | local r=0 g=0 b=0 126 | for b in {1..5}; do 127 | pallette_row ${r}${g}${b} 128 | done 129 | for r in {1..5}; do 130 | pallette_row ${r}${g}${b} 131 | done 132 | for g in {1..5}; do 133 | pallette_row ${r}${g}${b} 134 | done 135 | [[ ${VERBOSE} ]] || { 136 | echo 137 | echo " Try also: ${0##*/} -v ${CMD_NAME}" 138 | echo " to show rgb numeric values" 139 | echo 140 | } 141 | } 142 | 143 | #------------------------------------------------------------------------------- 144 | # for use on the console 145 | function low_pallette() 146 | { 147 | echo 148 | echo "LowColor Foreground Colors (Linux console)" 149 | echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 150 | echo "Basic Colors" 151 | echo 152 | for c in red green blue purple yellow cyan; do 153 | _face -lnf ${c} " ${c}" 154 | done 155 | echo 156 | echo 157 | echo "Enhanced Colors" 158 | echo 159 | for c in brightred brightgreen brightblue brightpurple brightyellow brightcyan; do 160 | _face -lnf ${c} " ${c}" 161 | done 162 | echo 163 | echo 164 | echo "black thru white" 165 | echo 166 | for c in black gray brightgray white; do 167 | _face -lnf ${c} " ${c}" 168 | done 169 | echo 170 | echo 171 | echo "LowColor Background Colors (Linux console)" 172 | echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 173 | echo "Basic Colors" 174 | echo 175 | for c in red green blue purple yellow cyan; do 176 | _face -lnb ${c} ' '"${c}"' ' 177 | done 178 | echo 179 | echo 180 | echo "black and white" 181 | echo 182 | for c in black white; do 183 | _face -lnb ${c} ' '"${c}"' ' 184 | done 185 | echo 186 | } 187 | 188 | 189 | #------------------------------------------------------------------------------- 190 | # draw a row of color out to white in increments 191 | # beginning at the highest saturation of the hue 192 | # and containing in the row the specified rgb. 193 | function pallette_row() 194 | { 195 | local rgb=${1} 196 | local r=${rgb:0:1} 197 | local g=${rgb:1:1} 198 | local b=${rgb:2:1} 199 | local -a a_rgb=() 200 | 201 | until (( ${r} == 0 )) || (( ${g} == 0 )) || (( ${b} == 0 )); do 202 | (( ${r} > 0 )) && ((r--)) 203 | (( ${g} > 0 )) && ((g--)) 204 | (( ${b} > 0 )) && ((b--)) 205 | done 206 | 207 | a_rgb=( ${r}${g}${b} ) 208 | 209 | until (( ${r}${g}${b} == 555 )); do 210 | (( ${r} < 5 )) && ((r++)) 211 | (( ${g} < 5 )) && ((g++)) 212 | (( ${b} < 5 )) && ((b++)) 213 | a_rgb+=( ${r}${g}${b} ) 214 | done 215 | 216 | [[ ${VERBOSE} ]] && { 217 | for (( c=0; c < ${#a_rgb[@]}; c++ )); do 218 | echo -n " ${a_rgb[c]} " 219 | done 220 | echo 221 | } 222 | for (( c=0; c<${#a_rgb[@]}; c++ )); do 223 | _face -n -b ${a_rgb[c]} ' ' 224 | done 225 | echo 226 | } 227 | 228 | # if we're being run standalone 229 | if [[ "${0##*/}" != "face" ]]; then 230 | [[ -f ${0%/*}/face ]] && { 231 | [[ "${1}" == "-v" ]] && VERBOSE=1 CMD_NAME= 232 | source ${0%/*}/face libmode 233 | case $TERM in 234 | linux) 235 | low_pallette 236 | ;; 237 | *) 238 | pallette 239 | ;; 240 | esac 241 | } || { 242 | echo >&2 "cannot locate: ${0%/*}face" 243 | echo >&2 "this file is required to generate color pallettes" 244 | exit 1 245 | } 246 | fi 247 | -------------------------------------------------------------------------------- /src/libexec/functions: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; -*- 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | # xterm titlebar escape array 25 | # use like: PS1="${xt[0]},functions, macros or text to put in title bar${xt[1]}..." 26 | xt=( '\[\033]0;' '\007\]' ) 27 | 28 | #=============================================================================== 29 | # functions 30 | #------------------------------------------------------------------------------- 31 | # function lib available to all prompt themes 32 | #=============================================================================== 33 | 34 | #=============================================================================== 35 | # prompt functions embedded in PS1 string, marked by a 'short alias' 36 | #=============================================================================== 37 | 38 | #------------------------------------------------------------------------------- 39 | # output the sized current directory 40 | function prompt_get_pwd() 41 | { 42 | prompt_truncate ${PROMPT_MAXPATHLEN:-20} "${PWD}" 43 | } 44 | # short alias 45 | function pgp() { prompt_get_pwd "${@}"; } 46 | 47 | #------------------------------------------------------------------------------- 48 | # output the sized current directory 49 | function prompt_get_fuzzy_pwd() 50 | { 51 | [[ "${PWD}" =~ (^${HOME})(.*) ]] && { 52 | str="~${BASH_REMATCH[2]}" 53 | } 54 | prompt_fuzzy_truncate ${PROMPT_MAXPATHLEN:-20} ${PROMPT_DIR_FUZZFACTOR:-8} '/' "${str:-${PWD}}" 55 | } 56 | # short alias 57 | function pgfp() { prompt_get_fuzzy_pwd "${@}"; } 58 | 59 | #------------------------------------------------------------------------------- 60 | # output a date/time string like: "09/02 17:53:13" 61 | function prompt_date_time() 62 | { 63 | date +%m"/"%d" "%T 64 | } 65 | # short alias 66 | function pdt() { prompt_date_time; } 67 | 68 | #------------------------------------------------------------------------------- 69 | # output if we're shelled out of Midnight Commander or not 70 | function in_midnight_commander() 71 | { 72 | (( SHLVL > 1 )) && [[ ${MC_SID} ]] && [[ ${MC_TMPDIR} ]] && { 73 | echo -e ${PROMPT_MC_CHAR} 74 | } || { 75 | echo "" 76 | } 77 | } 78 | # short alias 79 | function imc() { in_midnight_commander; } 80 | 81 | #=============================================================================== 82 | # utility functions used by other function lib functions - no aliases 83 | #=============================================================================== 84 | 85 | #------------------------------------------------------------------------------- 86 | # truncate the front of a string, returning the specified length prefixed by ... 87 | # prompt_truncate <"string"> 88 | function prompt_truncate() 89 | { 90 | (( ${#} >= 2 )) || { echo "${FUNCNAME}: bad arglist: '${@}'"; return 1; } 91 | local len=${1}; shift 92 | local str="${*}" 93 | (( ${#str} <= ${len} )) || (( ${len} <= 0 )) && { 94 | echo "${str}" 95 | } || { 96 | echo "...${str: -${len}}" 97 | } 98 | } 99 | 100 | #------------------------------------------------------------------------------- 101 | # fuzzily truncate based on delimiter, a max length and a fuzzy value 102 | # the idea is to break on a delimiter if possible 103 | function prompt_fuzzy_truncate() 104 | { 105 | (( ${#} >= 3 )) || { echo "${FUNCNAME}: bad arglist: '${@}'"; return 1; } 106 | local -i maxlen=${1} 107 | local -i fuzzfactor=${2} # Mr. Sulu... 108 | local delim=${3}; shift 3 109 | local arg="${*}" 110 | 111 | local -i fuzzlow=$(( maxlen - fuzzfactor )) 112 | (( ${#arg} < ${fuzzlow} )) && fuzzlow=0 113 | local -i fuzzhigh=$(( maxlen + fuzzfactor )) 114 | 115 | # greater than maxlen? return immediately 116 | if (( ${#arg} <= ${maxlen} )); then 117 | echo "${arg}" 118 | return 0 119 | fi 120 | 121 | # pre-front-trim the string to fuzzhigh length 122 | (( ${#arg} < ${fuzzhigh} )) && fuzzhigh=${#arg} 123 | arg=${arg: -${fuzzhigh}} 124 | 125 | # walk right looking for delim 126 | for (( i = 0; i < ( ${#arg} - ${fuzzlow} ); i++ )); do 127 | [[ "${arg:$i:1}" == "${delim}" ]] && { 128 | echo "...${arg:$i}" 129 | return 0 130 | } 131 | done 132 | 133 | # if we get here, just dump it @ maxlen 134 | echo "...${arg: -${maxlen}}" 135 | 136 | return 0 137 | } 138 | 139 | 140 | #------------------------------------------------------------------------------- 141 | # Utilities / prompt commands 142 | #------------------------------------------------------------------------------- 143 | 144 | #------------------------------------------------------------------------------- 145 | function prompt_print_theme_list() 146 | { 147 | echo 148 | _face -nf 012 "${1} " 149 | _face -f 111 "${2}" 150 | local -a p_theme=( $(ls -1 ${2} | grep -v conf) ) 151 | (( ${#p_theme[@]} > 0 )) || p_theme=( 'none available' ) 152 | printf "$(_face -f 013 "*") %s\n" "${p_theme[@]}" 153 | } 154 | 155 | #------------------------------------------------------------------------------- 156 | # generate list of installed themes 157 | function prompt_theme_list() 158 | { 159 | _face -f 030 "Current:" 160 | _face -nf 030 "*"; _face -f 030 " ${THEME:-none active}" 161 | 162 | [[ -d ~/.prompt-themes.d ]] && { 163 | prompt_print_theme_list "Personal:" ~/.prompt-themes.d/ 164 | } 165 | [[ -d ${THEME_DIR} ]] && { 166 | prompt_print_theme_list "Standard:" "${THEME_DIR}/" 167 | } || return 1 168 | [[ -d ${THEME_DIR%/*}/contrib ]] && { 169 | prompt_print_theme_list "Contrib:" "${THEME_DIR%/*}/contrib/" 170 | } 171 | echo 172 | _face -f 222 "run: 'prompt ' to set theme." 173 | _face -f 222 "run: 'prompt save' to set current theme as default." 174 | _face -f 222 "edit: ~/.prompt-themes.d/conf/.theme to customize theme colors" 175 | echo 176 | 177 | return 0 178 | } 179 | 180 | #------------------------------------------------------------------------------- 181 | function prompt_save_to_bctrc() 182 | { 183 | local inst_prefix=$(echo ${THEME_DIR} | sed 's,/share/bash-color-tools/themes,,') 184 | 185 | cat > ~/.bctrc <>~/.bashrc 214 | echo "# initialize bash-color-tools prompt code" >>~/.bashrc 215 | echo "source ~/.bctrc" >>~/.bashrc 216 | 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # install 26 | #------------------------------------------------------------------------------- 27 | # installation script for bash-color-tools 28 | #=============================================================================== 29 | 30 | (( ${BASH_VERSINFO:-0} >= 4 )) || { 31 | echo "Sorry, gotta have bash version >= 4 to run bash-color-tools." 32 | exit 1 33 | } 34 | 35 | #------------------------------------------------------------------------------- 36 | function _install_() 37 | { 38 | local inst_prefix=${1} 39 | local pkg_dir=${0%/*} 40 | 41 | mkdir -p ${inst_prefix}/share{/doc,}/bash-color-tools 2>/dev/null || { 42 | echo "you do not have permission to install in ${inst_prefix}/share/." 43 | return 1 44 | } 45 | rsync -a ${pkg_dir}/src/{contrib,libexec,themes} ${inst_prefix}/share/bash-color-tools/ || return 1 46 | rsync -a ${pkg_dir}/install ${inst_prefix}/share/bash-color-tools/libexec/ || return 1 47 | chmod 755 ${inst_prefix}/share/bash-color-tools/libexec/{face,print-face-colors,install} || return 1 48 | (cd ${inst_prefix}/share/bash-color-tools/libexec; ln -sf install uninstall) || return 1 49 | 50 | rsync -a ${pkg_dir}/examples ${inst_prefix}/share/doc/bash-color-tools/ || return 1 51 | rsync -a ${pkg_dir}/man ${inst_prefix}/share/doc/bash-color-tools/ || return 1 52 | rsync -a $(find ${pkg_dir} -maxdepth 1 -type f -a -not -name install 2>/dev/null) \ 53 | ${inst_prefix}/share/doc/bash-color-tools/ || return 1 54 | 55 | find ${inst_prefix}/share{/doc,}/bash-color-tools -type f 2>/dev/null \ 56 | >${inst_prefix}/share/doc/bash-color-tools/MANIFEST 57 | } 58 | 59 | #------------------------------------------------------------------------------- 60 | function _uninstall_() 61 | { 62 | local inst_prefix=${1} 63 | local -a inst_files=( $(<${inst_prefix}/share/doc/bash-color-tools/MANIFEST) ) 64 | local -a files=() 65 | 66 | for f in "${inst_files[@]}"; do 67 | rm -f ${f} 68 | done 69 | 70 | files=( $(find ${inst_prefix}/share/bash-color-tools -type f) ) 71 | [[ ${#files[@]} -gt 0 ]] && { 72 | echo "directory ${inst_prefix}/share/bash-color-tools is not empty, so not deleting it." 73 | } || { 74 | rm -rf ${inst_prefix}/share/bash-color-tools 75 | } 76 | 77 | files=( $(find ${inst_prefix}/share/doc/bash-color-tools -type f) ) 78 | [[ ${#files[@]} -gt 0 ]] && { 79 | echo "directory ${inst_prefix}/share/doc/bash-color-tools is not empty, so not deleting it." 80 | } || { 81 | rm -rf ${inst_prefix}/share/doc/bash-color-tools 82 | } 83 | 84 | [[ -f /etc/profile.d/bash-color-tools.sh ]] && rm -f /etc/profile.d/bash-color-tools.sh 85 | 86 | # remove all functions and vars from environment 87 | unset -f $(typeset -F | grep prompt_ | cut -d' ' -f3) 2>/dev/null 88 | unset $(set | grep PROMPT_ | awk -F= '{ print $1 }') 2>/dev/null 89 | unset THEME THEME_DIR 90 | 91 | sed -i "s,^\(.*/bctrc$\),#\1," ~/.bashrc 92 | 93 | return 0 94 | } 95 | 96 | #------------------------------------------------------------------------------- 97 | function _install_links_() 98 | { 99 | local inst_prefix=${1} 100 | ( 101 | mkdir -p ${inst_prefix}/bin 102 | cd ${inst_prefix}/bin 103 | ln -sf ${inst_prefix}/share/bash-color-tools/libexec/face || return 1 104 | ln -sf ${inst_prefix}/share/bash-color-tools/libexec/print-face-colors || return 1 105 | ln -sf ${inst_prefix}/share/bash-color-tools/libexec/install setup-prompt || return 1 106 | ) 107 | } 108 | 109 | #------------------------------------------------------------------------------- 110 | function _uninstall_links_() 111 | { 112 | local inst_prefix=${1} 113 | [[ -f ${inst_prefix}/bin/face ]] && rm -f ${inst_prefix}/bin/face 114 | [[ -f ${inst_prefix}/bin/print-face-colors ]] && rm -f ${inst_prefix}/bin/print-face-colors 115 | [[ -f ${inst_prefix}/bin/setup-prompt ]] && rm -f ${inst_prefix}/bin/setup-prompt 116 | } 117 | 118 | #------------------------------------------------------------------------------- 119 | function _set_themes_dir_() 120 | { 121 | local inst_prefix=${1} 122 | sed -i "s,^declare THEME_DIR=.*$,declare THEME_DIR=${inst_prefix}/share/bash-color-tools/themes," \ 123 | ${inst_prefix}/share/bash-color-tools/libexec/prompt || return 1 124 | } 125 | 126 | #------------------------------------------------------------------------------- 127 | function _set_man_dir_() 128 | { 129 | local inst_prefix=${1} 130 | sed -i "s,^PREFIX=.*$,PREFIX=${inst_prefix}/share," \ 131 | ${inst_prefix}/share/bash-color-tools/libexec/face || return 1 132 | } 133 | 134 | #------------------------------------------------------------------------------- 135 | function _setup_etc_profile_() 136 | { 137 | local inst_prefix=${1} 138 | 139 | if _verify_permissions_ /etc/profile.d; then 140 | # we can setup global source of libs 141 | cat > /etc/profile.d/bash-color-tools.sh < ~/.bctrc <>~/.bashrc 197 | echo "# initialize bash-color-tools prompt code" >>~/.bashrc 198 | echo "source ~/.bctrc" >>~/.bashrc 199 | 200 | } 201 | } 202 | 203 | #------------------------------------------------------------------------------- 204 | function _welcome_output_() 205 | { 206 | local inst_prefix=${1} 207 | 208 | [[ -e ${inst_prefix}/share/doc/bash-color-tools/release-notes ]] && { 209 | less ${inst_prefix}/share/doc/bash-color-tools/release-notes 210 | } 211 | 212 | ${inst_prefix}/bin/face -f 042 "bash-color-tools are installed" 213 | ${inst_prefix}/bin/face -nf 015 "see " 214 | ${inst_prefix}/bin/face -nf 033 "${inst_prefix}/share/doc/bash-color-tools/* " 215 | ${inst_prefix}/bin/face -f 015 "for more info" 216 | ${inst_prefix}/bin/face -nf 015 "run: " 217 | ${inst_prefix}/bin/face -nf 033 ". ~/.bashrc" 218 | ${inst_prefix}/bin/face -nf 015 " to load the libs, then run: " 219 | ${inst_prefix}/bin/face -f 033 "prompt list" 220 | ${inst_prefix}/bin/face -f 015 "for a list of available prompt themes" 221 | echo 222 | 223 | } 224 | 225 | #------------------------------------------------------------------------------- 226 | # make sure we can access this prefix location 227 | function _verify_permissions_() 228 | { 229 | local inst_prefix=${1} 230 | local tstfn="${inst_prefix}/${RANDOM}-${RANDOM}-${RANDOM}" 231 | touch "${tstfn}" 2>/dev/null && { 232 | rm -f "${tstfn}" 233 | } || { 234 | return 1 235 | } 236 | return 0 237 | } 238 | 239 | #=============================================================================== 240 | # (un)install bash-color-tools 241 | [[ ${PREFIX} ]] || PREFIX=/usr 242 | 243 | case ${0##*/} in 244 | 245 | install) 246 | _verify_permissions_ ${PREFIX} || { 247 | echo "Oops! you do not have permission to install into ${PREFIX}." 248 | echo "use sudo, or: 'PREFIX=/a/dir/you/own ./install' for non-privileged installations" 249 | exit 1 250 | } 251 | [[ "${0}" =~ ${PREFIX} ]] && { echo "uninstall, then install from the original package."; exit 1; } 252 | _install_ ${PREFIX} || { echo "installation failed."; exit 1; } 253 | _install_links_ ${PREFIX} || { echo "installation of links failed."; exit 1; } 254 | _set_themes_dir_ ${PREFIX} || { echo "configuring prompt themes directory failed."; exit 1; } 255 | _set_man_dir_ ${PREFIX} || { echo "configuring face man directory failed."; exit 1; } 256 | _setup_etc_profile_ ${PREFIX} || { 257 | echo "permissions prevent installing global settings in:" 258 | echo "/etc/profile.d/bash-color-tools.sh" 259 | } 260 | _setup_bashrc_ ${PREFIX} 261 | _welcome_output_ ${PREFIX} 262 | echo 263 | ${PREFIX}/bin/face -f 015 "run: 'setup-prompt' as each user to set prompt to autostart" 264 | [[ "$(which print-face-colors)" ]] || { 265 | ${PREFIX}/bin/face -f red "dont forget to add '${PREFIX}/bin' to your PATH variable in ~/.bashrc" 266 | } 267 | ;; 268 | 269 | uninstall) 270 | PREFIX=$(echo ${0} | sed 's,/share/bash-color-tools/libexec/uninstall,,') 271 | [[ -f ${PREFIX}/share/doc/bash-color-tools/MANIFEST ]] || { echo "bash-color-tools is not correctly installed in ${PREFIX}/share. quitting."; exit 1; } 272 | _verify_permissions_ ${PREFIX} || { echo "you do not have permission to uninstall from ${PREFIX}."; exit 1; } 273 | ( 274 | cd /tmp 275 | _uninstall_links_ ${PREFIX} || { echo "uninstallation of links failed."; exit 1; } 276 | _uninstall_ ${PREFIX} || { echo "uninstallation failed."; exit 1; } 277 | echo "bash-color-tools have been uninstalled" 278 | ) 279 | ;; 280 | 281 | setup-prompt) 282 | PREFIX=$(echo ${0} | sed 's,/bin/setup-prompt,,') 283 | _setup_bashrc_ ${PREFIX} 284 | _welcome_output_ ${PREFIX} 285 | ;; 286 | 287 | esac 288 | -------------------------------------------------------------------------------- /src/libexec/face: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # face 26 | #------------------------------------------------------------------------------- 27 | # face is a colorizing echo command/lib for bash 28 | #=============================================================================== 29 | 30 | (( ${BASH_VERSINFO:-0} >= 4 )) || { 31 | echo "Sorry, gotta have bash version >= 4 to run this." 32 | exit 1 33 | } 34 | 35 | PREFIX=/usr/share 36 | 37 | #------------------------------------------------------------------------------- 38 | # Usage 39 | function face_usage() 40 | { 41 | echo >&2 "USAGE:" 42 | echo >&2 " face <[OPTS] 'string'>||<[-v] colors>" 43 | echo >&2 44 | echo >&2 " face <-h|-H>" 45 | echo >&2 46 | echo >&2 " face <[-P] [-l] [-n] [-e] \\" 47 | echo >&2 " [-f |||] \\" 48 | echo >&2 " [-b |||] 'message'>" 49 | echo >&2 50 | echo >&2 " face <[-v] colors>" 51 | echo >&2 52 | echo >&2 " source /path/to/face " 53 | echo >&2 54 | echo >&2 " use: 'face -h and -H' for color echo command help and usage" 55 | echo >&2 " use: 'source /path/to/face libmode' to use _face function in scripts" 56 | echo >&2 " use: 'face [-v] colors' to print color pallettes, and optionally their rgb values" 57 | } 58 | function face_help() 59 | { 60 | [[ -f ${PREFIX}/doc/bash-color-tools/man/face ]] && { 61 | less ${PREFIX}/doc/bash-color-tools/man/face 62 | } || { 63 | echo >&2 "Full help file missing." 64 | echo >&2 "${PREFIX}/doc/bash-color-tools/man/face not found." 65 | face_usage 66 | } 67 | } 68 | 69 | #------------------------------------------------------------------------------- 70 | # color echo function 71 | function _face() 72 | { 73 | OPTIND= 74 | while getopts ":HPb:ef:hln" opt 75 | do 76 | case ${opt} in 77 | H) face_help; exit 1 ;; # verbose help 78 | P) local PS1_mode=1 ;; # use additional escapes for prompt mode 79 | b) local -l bg_color=${OPTARG} ;; # background color rgb/name 80 | e) local E=e ;; # process escapes codes in the message 81 | f) local -l fg_color=${OPTARG} ;; # foreground color rgb/name 82 | h) face_usage; exit 1 ;; # basic help 83 | l) local mode=lowcolor ;; # low-color mode 84 | n) local N=n ;; # no newline 85 | *) : ;; # ignore unknown params 86 | esac 87 | done 88 | 89 | # reset to normal 90 | shift $((${OPTIND}-1)) 91 | [[ ${PS1_mode} ]] && { 92 | # for PS1 93 | local norm="\[\033[0m\]"; echo -n "${norm}" 94 | } || { 95 | # for color echoing 96 | local norm="\033[0m"; echo -ne "${norm}" 97 | } 98 | 99 | case ${mode} in 100 | 101 | lowcolor) # low-color mode: console mode w/o framebuffer requires this mode [-l] 102 | 103 | [[ ${PS1_mode} ]] && { 104 | 105 | # for PS1 prompt strings 106 | # forground 107 | local -A foreground_color_names=( 108 | [white]='\[\033[1;37m\]' [black]='\[\033[0;30m\]' 109 | [gray]='\[\033[1;30m\]' [brightgray]='\[\033[0;37m\]' 110 | [red]='\[\033[0;31m\]' [brightred]='\[\033[1;31m\]' 111 | [green]='\[\033[0;32m\]' [brightgreen]='\[\033[1;32m\]' 112 | [yellow]='\[\033[0;33m\]' [brightyellow]='\[\033[1;33m\]' 113 | [blue]='\[\033[0;34m\]' [brightblue]='\[\033[1;34m\]' 114 | [purple]='\[\033[0;35m\]' [brightpurple]='\[\033[1;35m\]' 115 | [cyan]='\[\033[0;36m\]' [brightcyan]='\[\033[1;36m\]' 116 | [none]='\[\033[0;37m\]' 117 | ) 118 | # background 119 | local -A background_color_names=( 120 | [white]='\[\033[47m\]' [black]='\[\033[40m\]' 121 | [red]='\[\033[41m\]' [green]='\[\033[42m\]' 122 | [yellow]='\[\033[43m\]' [blue]='\[\033[44m\]' 123 | [purple]='\[\033[45m\]' [cyan]='\[\033[46m\]' 124 | [none]='\[\033[40m\]' 125 | ) 126 | 127 | } || { 128 | 129 | # for color echoing 130 | # forground 131 | local -A foreground_color_names=( 132 | [white]='\033[1;37m' [black]='\033[0;30m' 133 | [gray]='\033[1;30m' [brightgray]='\033[0;37m' 134 | [red]='\033[0;31m' [brightred]='\033[1;31m' 135 | [green]='\033[0;32m' [brightgreen]='\033[1;32m' 136 | [yellow]='\033[0;33m' [brightyellow]='\033[1;33m' 137 | [blue]='\033[0;34m' [brightblue]='\033[1;34m' 138 | [purple]='\033[0;35m' [brightpurple]='\033[1;35m' 139 | [cyan]='\033[0;36m' [brightcyan]='\033[1;36m' 140 | [none]='\033[0;37m' 141 | ) 142 | # background 143 | local -A background_color_names=( 144 | [white]='\033[47m' [black]='\033[40m' 145 | [red]='\033[41m' [green]='\033[42m' 146 | [yellow]='\033[43m' [blue]='\033[44m' 147 | [purple]='\033[45m' [cyan]='\033[46m' 148 | [none]='\033[40m' 149 | ) 150 | } 151 | 152 | [[ ${fg_color} ]] && [[ "${!foreground_color_names[@]}" =~ (^|[\ ]*)${fg_color}($|[\ ]*) ]] && fg="${foreground_color_names[${fg_color}]}" 153 | [[ ${bg_color} ]] && [[ "${!background_color_names[@]}" =~ (^|[\ ]*)${bg_color}($|[\ ]*) ]] && bg="${background_color_names[${bg_color}]}" 154 | [[ ${bg_color} ]] || bg="${background_color_names[none]}" 155 | 156 | # setup low colors for next print 157 | [[ ${PS1_mode} ]] && { 158 | # for PS1 159 | echo -n "${fg}${bg}" 160 | } || { 161 | # for color echoing 162 | echo -ne "${fg}${bg}" 163 | } 164 | 165 | ;; 166 | 167 | *) #------------------------------------------------------------------------------- 168 | # default high-color mode: requires an xterm or framebuffer 169 | 170 | # check for the color name hash 171 | [[ ${FACECOLORS[salmon]} ]] || { 172 | source ${PREFIX}/bash-color-tools/libexec/facecolors.rgb 173 | } 174 | 175 | function hex2rgb() 176 | { 177 | local r=${1:0:2} g=${1:2:2} b=${1:4:2} 178 | r=$(( ( 0x${r} / 42 ) - 1 )); [[ ${r} -lt 0 ]] && r=0 179 | g=$(( ( 0x${g} / 42 ) - 1 )); [[ ${g} -lt 0 ]] && g=0 180 | b=$(( ( 0x${b} / 42 ) - 1 )); [[ ${b} -lt 0 ]] && b=0 181 | echo ${r}${g}${b} 182 | } 183 | 184 | function dec2rgb() 185 | { 186 | local rgb=( ${1//,/ } ) 187 | local r="${rgb[0]}" g="${rgb[1]}" b="${rgb[2]}" 188 | r=$(( ( ${r} / 42 ) - 1 )); [[ ${r} -lt 0 ]] && r=0 189 | g=$(( ( ${g} / 42 ) - 1 )); [[ ${g} -lt 0 ]] && g=0 190 | b=$(( ( ${b} / 42 ) - 1 )); [[ ${b} -lt 0 ]] && b=0 191 | echo ${r}${g}${b} 192 | } 193 | 194 | function convert2rgb() 195 | { 196 | local colorid=${1} 197 | # already in face rgb format, return 198 | [[ ${colorid} =~ ^[0-5]{3}$ ]] && { echo ${colorid}; return 0; } 199 | # in hex format, convert 200 | [[ ${colorid} =~ ^[0-9a-f]{6}$ ]] && { hex2rgb ${colorid}; return 0; } 201 | # in decimal format, convert 202 | #colorid=223,122,12 203 | [[ ${colorid} =~ ^[[:digit:]]+,[[:digit:]]+,[[:digit:]]+$ ]] && { 204 | local decs=( ${colorid//,/ } ) 205 | local -i invalid 206 | for d in ${decs[@]}; do 207 | (( d > 255 )) && ((invalid++)) 208 | done 209 | [[ ! ${invalid} ]] && { dec2rgb ${colorid}; return 0; } 210 | } 211 | # in color name format, get from hash 212 | [[ "${!FACECOLORS[@]}" =~ (^|[\ ]*)${colorid}($|[\ ]*) ]] && { echo ${FACECOLORS[${colorid}]}; return 0; } 213 | # fallthrough to medium gray if format was wrong 214 | echo 333; return 0 215 | } 216 | 217 | function rgb2idx() { echo -n "$((16+${1:0:1}*36+${1:1:1}*6+${1:2:1}))m"; } 218 | 219 | function color() 220 | { 221 | [[ ${PS1_mode} ]] && { 222 | # for PS1 223 | echo -n "\[\033[${1}8;5;$(rgb2idx ${2})\]" 224 | } || { 225 | # for color echoing 226 | echo -ne "\033[${1}8;5;$(rgb2idx ${2})" 227 | } 228 | } 229 | 230 | # setup high colors for next print 231 | local fg_idx=3 bg_idx=4 232 | [[ ${fg_color} ]] && color ${fg_idx} $(convert2rgb ${fg_color}) 233 | [[ ${bg_color} ]] && color ${bg_idx} $(convert2rgb ${bg_color}) 234 | 235 | ;; 236 | 237 | esac 238 | 239 | #--------------------------------------------------------------------------- 240 | # print the text 241 | echo -n ${E:+ -${E}} "${*}" 242 | 243 | #--------------------------------------------------------------------------- 244 | # reset to normal 245 | [[ ${PS1_mode} ]] && { 246 | # for PS1 247 | echo ${N:+ -${N}} "${norm}" 248 | } || { 249 | # for color echoing 250 | echo -e ${N:+ -${N}} "${norm}" 251 | } 252 | 253 | return 0 254 | } 255 | 256 | 257 | #=============================================================================== 258 | # use as lib, color pallette demo, or simple colorizing echo command 259 | [[ "${1}" == "-v" ]] && { VERBOSE=1; shift; } 260 | case "${1}" in 261 | 262 | "") 263 | face_usage 264 | ;; 265 | 266 | libmode) 267 | export -f _face 268 | [[ ${FACECOLORS[salmon]} ]] || { 269 | source ${PREFIX}/bash-color-tools/libexec/facecolors.rgb 270 | } 271 | ;; 272 | 273 | colors) 274 | [[ -f ${0%/*}/print-face-colors ]] && { 275 | CMD_NAME=colors 276 | source ${0%/*}/print-face-colors 277 | [[ $TERM == linux ]] && low_pallette || pallette 278 | : 279 | } || { 280 | echo >&2 "cannot locate: '${0%/*}/print-face-colors'" 281 | echo >&2 "this file is required to generate color pallettes" 282 | exit 1 283 | } 284 | ;; 285 | 286 | *) 287 | _face "${@}" 288 | ;; 289 | esac 290 | -------------------------------------------------------------------------------- /examples/CUSTOMIZING: -------------------------------------------------------------------------------- 1 | bash-color-tools 2 | ================================================================================ 3 | Copyright 2007-2012 Christopher Barry 4 | 5 | This file is part of the bash-color-tools 6 | 7 | bash-color-tools is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | ================================================================================ 21 | 22 | INTRODUCTION 23 | 24 | Customizing 'prompt' to your needs is fairly simple, and there's a 25 | couple of basic ways to go about it: 26 | 27 | * simply modify the colors in the config files for the existing themes 28 | located (once you run them) in your home directory in 29 | ~/.prompt-themes.d/conf/.theme. 30 | 31 | Or, for the adventurous: 32 | 33 | * create a new theme based on the theme template located in 34 | ${INSTALL_PREFIX}/share/doc/bash-color-tools/examples/template. Your 35 | themes can either be personal, or system-wide, depending on where 36 | they're located in the filesystem. 37 | 38 | 39 | Setting the colors is simple, as prompt uses 'face' to generate the 40 | color strings for the PS1 prompt variable. Each color is defined by a 41 | numeric triplet, or rgb value. The first number of the triplet is red, 42 | the second is green and the third is blue. Each numeric element has a 43 | range of valid values from 0-5. So 500 is full-on red, 050 is full-on 44 | green, and 005 is full-on blue. 000 is full-on black, and 555 is 45 | full-on white. 46 | 47 | If you run 'face -v colors' in an xterm, it will dump a bunch of 48 | example pallettes with their corresponding rgb values to help you 49 | decide which numbers to use in your configurations. 50 | 51 | 52 | If you want to dive into creating your own theme yourself, rather than 53 | just tweaking colors of the existing themes, I suggest you have a look 54 | at the various themes in: 55 | 56 | ${INSTALL_PREFIX}/share/bash-color-tools/themes 57 | 58 | and either copy one of these, or the template in: 59 | 60 | ${INSTALL_PREFIX}/share/doc/bash-color-tools/examples/template 61 | 62 | to your personal theme directory located at: 63 | 64 | ~/.prompt-themes.d/. 65 | 66 | 67 | UNDERSTANDING THEMES 68 | 69 | Themes are basically just script snippets that get sourced into the 70 | prompt framework. The theme itself is what actually sets the PS1 71 | variable when the command 'prompt ' is run. 72 | 73 | Themes can use any of the various pre-defined functions that are 74 | located in: 75 | 76 | ${INSTALL_PREFIX}/share/bash-color-tools/libexec/functions 77 | 78 | And themes can also define their own specific functions in the theme 79 | file itself. 80 | 81 | Each theme snippet has a certain format that needs to be 82 | followed. Below is an annotated version of the 'template' theme. I 83 | will explain how to create your own theme by disecting and explaining 84 | this theme. This template is a great starting place to create your 85 | own. 86 | 87 | I suggest you open up the real template in another window now, so you 88 | can see the unannotated version right next to this document at the 89 | same time. Trust me, it'll help you see what's annotation and what's 90 | actually in the template. You can find it by default here: 91 | 92 | /usr/share/doc/bash-color-tools/examples/template 93 | 94 | 95 | Coding style rules 96 | ~~~~~~~~~~~~~~~~~~ 97 | * There can be NO TABS anywhere in the file, set your editor for 98 | 4-space, space-filled tabs. 99 | 100 | * NO CamelCase ANYWHERE! 101 | 102 | * global vars are UPPERCASE, prefixed with 'PROMPT_', and underscore 103 | delimited. 104 | 105 | * local vars are lowercase, underscore delimited. 106 | 107 | * function defs begin with the keyword 'function', are prefixed with 108 | 'prompt_', are all lowercase, underscore delimited, and have '()' 109 | tight to the end of their names. 110 | 111 | * functions that are embedded in the PS1 string are called with a 112 | short alias, typically only a few letters. (generally just the first 113 | letters of each function_name word, but watch out for collisions) 114 | 115 | * I'm sure I have other pet peeves I can't think of right now... ;) 116 | 117 | 118 | OK, on to the analysis: 119 | 120 | First, there's the header, and it needs to be in the theme if you want 121 | your theme to be included in the distribution (and I encourage you to 122 | submit your cool themes). Add a new: 123 | 124 | Copyright 125 | 126 | to the license, directly below mine. 127 | 128 | # -*- mode: sh; -*- 129 | #=============================================================================== 130 | :< 133 | 134 | This file is part of the bash-color-tools 135 | 136 | bash-color-tools is free software: you can redistribute it and/or modify 137 | it under the terms of the GNU General Public License as published by 138 | the Free Software Foundation, either version 3 of the License, or 139 | (at your option) any later version. 140 | 141 | This program is distributed in the hope that it will be useful, 142 | but WITHOUT ANY WARRANTY; without even the implied warranty of 143 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 144 | GNU General Public License for more details. 145 | 146 | You should have received a copy of the GNU General Public License 147 | along with this program. If not, see . 148 | 149 | LICENSE 150 | 151 | 152 | Next, there's the titleblock. change 'template' to your theme's 153 | name. Expand the lower section down as required to describe what your 154 | theme does, etc. Do not write lines in the block beyond 80 chars. 155 | 156 | #=============================================================================== 157 | # template 158 | #------------------------------------------------------------------------------- 159 | # theme template for prompt. see CUSTOMIZING in the doc directory for details. 160 | #=============================================================================== 161 | 162 | Then, set the THEME variable to your theme's name (no spaces in the name) 163 | 164 | THEME=template 165 | 166 | Then, there's the command to set it, followed by an example of what it 167 | looks like. 168 | 169 | #=============================================================================== 170 | # 'prompt template' 171 | # [09/02 17:15:50][...src/apps/]$ 172 | 173 | Then there's the init function, which by convention is named: 174 | 175 | prompt__theme 176 | 177 | The purpose of this function is to source your personal color settings 178 | if you have a settings file, and to generate a default file if you 179 | don't, and then source that. If you ever screw up your personal 180 | configuration file, simply deleting it will reset it to the defaults 181 | the next time you load the theme. 182 | 183 | Some variables below, like PROMPT_MAXPATHLEN, are used by generic 184 | functions found in the 'functions' file discussed above, so peruse the 185 | existing functions and use what you want. Consider placing genrically 186 | useful functions in the global functions file, and submitting that for 187 | inclusion as well. That will allow all users to take advantage of them 188 | in their themes. 189 | 190 | function prompt_template_theme() 191 | { 192 | # override and customize defaults with dotfile 193 | [[ -f ~/.prompt-themes.d/conf/${THEME}.theme ]] || { 194 | mkdir -p ~/.prompt-themes.d/conf 195 | cat >> ~/.prompt-themes.d/conf/${THEME}.theme <_CLR 208 | 209 | 210 | # default color rgb values for prompt elements 211 | PROMPT_BRKT_CLR=011 212 | PROMPT_DATE_CLR=110 213 | PROMPT_DIR_CLR=024 214 | PROMPT_SYM_CLR=133 215 | 216 | By convention, character element vars are named: 217 | 218 | PROMPT__CHAR 219 | 220 | # default prompt elements 221 | PROMPT_LBRKT_CHAR='[' 222 | PROMPT_RBRKT_CHAR=']' 223 | [[ \$(id -u) -eq 0 ]] && { 224 | PROMPT_SYM_CHAR='# ' 225 | } || { 226 | PROMPT_SYM_CHAR='\$ ' 227 | } 228 | 229 | EOF 230 | 231 | echo "edit ~/.prompt-themes.d/conf/${THEME}.theme to modify colors, etc." 232 | } 233 | source ~/.prompt-themes.d/conf/${THEME}.theme 234 | 235 | return 0 236 | } 237 | # 238 | 239 | If you have any theme specific functions, define them here. 240 | 241 | First thing in the theme snippet, we init all the global theme config 242 | vars by running the prompt_<${THEME}>_theme function. 243 | 244 | # init globals 245 | prompt_template_theme 246 | 247 | 248 | Next, we set 'very' short prompt-string varnames to the output of the 249 | face command. 250 | 251 | # set colors 252 | lb="$(_face -P${l}nf ${PROMPT_BRKT_CLR} "${PROMPT_LBRKT_CHAR}")" 253 | 254 | Let's break down what just happened in the line above: face was called 255 | with 3 switches, -P which puts face in 'prompt string' output mode, -n 256 | which, like echo, inhibits newlines, and -f which requires a 257 | forground_color rgb parameter. Without variables, the command would 258 | look like: 259 | face -Pnf 011 "[" 260 | try that now on the cmmand line to see what it's doing. scary, eh? 261 | 262 | OK, so same thing for the two vars below; we're simply wrapping the 263 | character elements in escape codes used by the terminal to generate 264 | color text. 265 | 266 | rb="$(_face -P${l}nf ${PROMPT_BRKT_CLR} "${PROMPT_RBRKT_CHAR}")" 267 | sc="$(_face -P${l}nf ${PROMPT_SYM_CLR} "${PROMPT_SYM_CHAR}")" 268 | 269 | Here's where it gets a bit tricky. Whenever you run a function inline 270 | in the PS1 to do things like output the current directory, the current 271 | git branch you're on, or the current date and time or whatever, those 272 | output strings need to be wrapped by escape codes as well. You might 273 | say to yourself, "self, I think I'll just use face in my function!", 274 | but you would be dissapointed if you did that, because it'll gag the 275 | PS1 var and confuse the terminal about line-wrap length. 276 | 277 | The way to wrap the function's output string is to create an array of 278 | two color escape code elements: element[0] is used to set up the color 279 | for the string, and element[1] is used to set it back to normal. 280 | 281 | Here, we're using face to set the foreground 'color' of a space 282 | character inside an array definition. This has the handy side effect 283 | of creating two colorizing escape strings in the array, which we'll 284 | use to color, then reset to normal, the function's output. 285 | 286 | # the following two arrays elements wrap the 287 | # calculated date and dir in color escape codes 288 | dt=( $(_face -P${l}nf ${PROMPT_DATE_CLR} " ") ) 289 | d=( $(_face -P${l}nf ${PROMPT_DIR_CLR} " ") ) 290 | 291 | Now, the moment you've all been waiting for - the &$^%#$# prompt string! 292 | 293 | # set the prompt 294 | PS1="${lb}${dt[0]}\$(pdt)${dt[1]}${rb}${lb}${d[0]}\$(pgp)${d[1]}${rb}${sc}" 295 | 296 | Let's break it down, piece by piece. 297 | 298 | ${lb} is a string representing the left bracket character, wrapped 299 | with color escape codes. It's the bizzare output you saw in your 300 | terminal earlier, e.g. "\[\033[38;3;23m\][\[\033[0m\]" and it's used 301 | twice in this simple prompt. 302 | 303 | ${dt[0]} is the color escape code for the date and time string, 304 | that's generated by 'pdt', the short alias for the prompt_date_time 305 | function found in the generic function lib. Notice that the '$' 306 | characters of the function calls are escaped with a '\' so that it's 307 | not evaluated now, but rather each time PS1 gets printed. 308 | 309 | ${dt[1]} finalizes the coloration of the date and time by reseting the 310 | forground color back to normal. In command mode, (no -P) face generates 311 | a color code, sets that color 'active', prints your text, and then 312 | resets the code to normal on every invocation. 313 | 314 | The rest of the prompt is fairly self explanitory, as it follows the 315 | same rules as these vars and functions above. 316 | 317 | So, there you have it. Now go play and make some cool prompt themes 318 | and send them in for inclusion in bash-color-tools. Display latency 319 | can be a bitch if you go too crazy with embedded functions, but I can 320 | imagine that there's lots of things like cpu temp, wireless quality, 321 | number of active users on the box, etc., that can be easily put in a 322 | prompt. And now that changing prompts is as easy as 'prompt name', 323 | switching around between different ones is fast and painless. But 324 | that's for your imagination. Me, I need to go get another beer. 325 | 326 | Cheers, 327 | -C 328 | -------------------------------------------------------------------------------- /src/libexec/facecolors.rgb: -------------------------------------------------------------------------------- 1 | declare -A FACECOLORS=( 2 | [aliceblue]=445 3 | [antiquewhite1]=544 4 | [antiquewhite2]=443 5 | [antiquewhite3]=333 6 | [antiquewhite4]=221 7 | [antiquewhite]=444 8 | [aquamarine1]=254 9 | [aquamarine2]=143 10 | [aquamarine3]=133 11 | [aquamarine4]=021 12 | [aquamarine]=254 13 | [azure1]=455 14 | [azure2]=444 15 | [azure3]=333 16 | [azure4]=222 17 | [azure]=455 18 | [beige]=444 19 | [bisque1]=543 20 | [bisque2]=443 21 | [bisque3]=332 22 | [bisque4]=211 23 | [bisque]=543 24 | [black]=000 25 | [blanchedalmond]=543 26 | [blue1]=005 27 | [blue2]=004 28 | [blue3]=003 29 | [blue4]=002 30 | [blue]=005 31 | [blueviolet]=204 32 | [brown1]=500 33 | [brown2]=400 34 | [brown3]=300 35 | [brown4]=200 36 | [brown]=200 37 | [burlywood1]=542 38 | [burlywood2]=432 39 | [burlywood3]=331 40 | [burlywood4]=211 41 | [burlywood]=432 42 | [cadetblue1]=245 43 | [cadetblue2]=244 44 | [cadetblue3]=133 45 | [cadetblue4]=022 46 | [cadetblue]=122 47 | [chartreuse1]=250 48 | [chartreuse2]=140 49 | [chartreuse3]=130 50 | [chartreuse4]=020 51 | [chartreuse]=250 52 | [chocolate1]=520 53 | [chocolate2]=410 54 | [chocolate3]=310 55 | [chocolate4]=200 56 | [chocolate]=410 57 | [coral1]=511 58 | [coral2]=410 59 | [coral3]=310 60 | [coral4]=200 61 | [coral]=520 62 | [cornflowerblue]=124 63 | [cornsilk1]=544 64 | [cornsilk2]=443 65 | [cornsilk3]=333 66 | [cornsilk4]=221 67 | [cornsilk]=544 68 | [cyan1]=055 69 | [cyan2]=044 70 | [cyan3]=033 71 | [cyan4]=022 72 | [cyan]=055 73 | [darkblue]=002 74 | [darkcyan]=022 75 | [darkgoldenrod1]=530 76 | [darkgoldenrod2]=430 77 | [darkgoldenrod3]=320 78 | [darkgoldenrod4]=210 79 | [darkgoldenrod]=320 80 | [darkgray]=333 81 | [darkgreen]=010 82 | [darkgrey]=333 83 | [darkkhaki]=331 84 | [darkmagenta]=202 85 | [darkolivegreen1]=351 86 | [darkolivegreen2]=341 87 | [darkolivegreen3]=231 88 | [darkolivegreen4]=120 89 | [darkolivegreen]=110 90 | [darkorange1]=520 91 | [darkorange2]=410 92 | [darkorange3]=310 93 | [darkorange4]=200 94 | [darkorange]=520 95 | [darkorchid1]=305 96 | [darkorchid2]=304 97 | [darkorchid3]=203 98 | [darkorchid4]=102 99 | [darkorchid]=203 100 | [darkred]=200 101 | [darksalmon]=421 102 | [darkseagreen1]=353 103 | [darkseagreen2]=343 104 | [darkseagreen3]=232 105 | [darkseagreen4]=121 106 | [darkseagreen]=232 107 | [darkslateblue]=002 108 | [darkslategray1]=255 109 | [darkslategray2]=244 110 | [darkslategray3]=133 111 | [darkslategray4]=022 112 | [darkslategray]=000 113 | [darkslategrey]=000 114 | [darkturquoise]=033 115 | [darkviolet]=204 116 | [deeppink1]=502 117 | [deeppink2]=402 118 | [deeppink3]=301 119 | [deeppink4]=200 120 | [deeppink]=502 121 | [deepskyblue1]=035 122 | [deepskyblue2]=034 123 | [deepskyblue3]=023 124 | [deepskyblue4]=012 125 | [deepskyblue]=035 126 | [dimgray]=111 127 | [dimgrey]=111 128 | [dodgerblue1]=025 129 | [dodgerblue2]=024 130 | [dodgerblue3]=013 131 | [dodgerblue4]=002 132 | [dodgerblue]=025 133 | [firebrick1]=500 134 | [firebrick2]=400 135 | [firebrick3]=300 136 | [firebrick4]=200 137 | [firebrick]=300 138 | [floralwhite]=544 139 | [forestgreen]=020 140 | [gainsboro]=444 141 | [ghostwhite]=445 142 | [gold1]=540 143 | [gold2]=430 144 | [gold3]=330 145 | [gold4]=210 146 | [gold]=540 147 | [goldenrod1]=530 148 | [goldenrod2]=430 149 | [goldenrod3]=320 150 | [goldenrod4]=210 151 | [goldenrod]=420 152 | [gray0]=000 153 | [gray100]=555 154 | [gray10]=000 155 | [gray11]=000 156 | [gray12]=000 157 | [gray13]=000 158 | [gray14]=000 159 | [gray15]=000 160 | [gray16]=000 161 | [gray17]=000 162 | [gray18]=000 163 | [gray19]=000 164 | [gray1]=000 165 | [gray20]=000 166 | [gray21]=000 167 | [gray22]=000 168 | [gray23]=000 169 | [gray24]=000 170 | [gray25]=000 171 | [gray26]=000 172 | [gray27]=000 173 | [gray28]=000 174 | [gray29]=000 175 | [gray2]=000 176 | [gray30]=000 177 | [gray31]=000 178 | [gray32]=000 179 | [gray33]=111 180 | [gray34]=111 181 | [gray35]=111 182 | [gray36]=111 183 | [gray37]=111 184 | [gray38]=111 185 | [gray39]=111 186 | [gray3]=000 187 | [gray40]=111 188 | [gray41]=111 189 | [gray42]=111 190 | [gray43]=111 191 | [gray44]=111 192 | [gray45]=111 193 | [gray46]=111 194 | [gray47]=111 195 | [gray48]=111 196 | [gray49]=111 197 | [gray4]=000 198 | [gray50]=222 199 | [gray51]=222 200 | [gray52]=222 201 | [gray53]=222 202 | [gray54]=222 203 | [gray55]=222 204 | [gray56]=222 205 | [gray57]=222 206 | [gray58]=222 207 | [gray59]=222 208 | [gray5]=000 209 | [gray60]=222 210 | [gray61]=222 211 | [gray62]=222 212 | [gray63]=222 213 | [gray64]=222 214 | [gray65]=222 215 | [gray66]=333 216 | [gray67]=333 217 | [gray68]=333 218 | [gray69]=333 219 | [gray6]=000 220 | [gray70]=333 221 | [gray71]=333 222 | [gray72]=333 223 | [gray73]=333 224 | [gray74]=333 225 | [gray75]=333 226 | [gray76]=333 227 | [gray77]=333 228 | [gray78]=333 229 | [gray79]=333 230 | [gray7]=000 231 | [gray80]=333 232 | [gray81]=333 233 | [gray82]=333 234 | [gray83]=444 235 | [gray84]=444 236 | [gray85]=444 237 | [gray86]=444 238 | [gray87]=444 239 | [gray88]=444 240 | [gray89]=444 241 | [gray8]=000 242 | [gray90]=444 243 | [gray91]=444 244 | [gray92]=444 245 | [gray93]=444 246 | [gray94]=444 247 | [gray95]=444 248 | [gray96]=444 249 | [gray97]=444 250 | [gray98]=444 251 | [gray99]=555 252 | [gray9]=000 253 | [gray]=333 254 | [green1]=050 255 | [green2]=040 256 | [green3]=030 257 | [green4]=020 258 | [green]=050 259 | [greenyellow]=350 260 | [grey0]=000 261 | [grey100]=555 262 | [grey10]=000 263 | [grey11]=000 264 | [grey12]=000 265 | [grey13]=000 266 | [grey14]=000 267 | [grey15]=000 268 | [grey16]=000 269 | [grey17]=000 270 | [grey18]=000 271 | [grey19]=000 272 | [grey1]=000 273 | [grey20]=000 274 | [grey21]=000 275 | [grey22]=000 276 | [grey23]=000 277 | [grey24]=000 278 | [grey25]=000 279 | [grey26]=000 280 | [grey27]=000 281 | [grey28]=000 282 | [grey29]=000 283 | [grey2]=000 284 | [grey30]=000 285 | [grey31]=000 286 | [grey32]=000 287 | [grey33]=111 288 | [grey34]=111 289 | [grey35]=111 290 | [grey36]=111 291 | [grey37]=111 292 | [grey38]=111 293 | [grey39]=111 294 | [grey3]=000 295 | [grey40]=111 296 | [grey41]=111 297 | [grey42]=111 298 | [grey43]=111 299 | [grey44]=111 300 | [grey45]=111 301 | [grey46]=111 302 | [grey47]=111 303 | [grey48]=111 304 | [grey49]=111 305 | [grey4]=000 306 | [grey50]=222 307 | [grey51]=222 308 | [grey52]=222 309 | [grey53]=222 310 | [grey54]=222 311 | [grey55]=222 312 | [grey56]=222 313 | [grey57]=222 314 | [grey58]=222 315 | [grey59]=222 316 | [grey5]=000 317 | [grey60]=222 318 | [grey61]=222 319 | [grey62]=222 320 | [grey63]=222 321 | [grey64]=222 322 | [grey65]=222 323 | [grey66]=333 324 | [grey67]=333 325 | [grey68]=333 326 | [grey69]=333 327 | [grey6]=000 328 | [grey70]=333 329 | [grey71]=333 330 | [grey72]=333 331 | [grey73]=333 332 | [grey74]=333 333 | [grey75]=333 334 | [grey76]=333 335 | [grey77]=333 336 | [grey78]=333 337 | [grey79]=333 338 | [grey7]=000 339 | [grey80]=333 340 | [grey81]=333 341 | [grey82]=333 342 | [grey83]=444 343 | [grey84]=444 344 | [grey85]=444 345 | [grey86]=444 346 | [grey87]=444 347 | [grey88]=444 348 | [grey89]=444 349 | [grey8]=000 350 | [grey90]=444 351 | [grey91]=444 352 | [grey92]=444 353 | [grey93]=444 354 | [grey94]=444 355 | [grey95]=444 356 | [grey96]=444 357 | [grey97]=444 358 | [grey98]=444 359 | [grey99]=555 360 | [grey9]=000 361 | [grey]=333 362 | [honeydew1]=454 363 | [honeydew2]=444 364 | [honeydew3]=333 365 | [honeydew4]=222 366 | [honeydew]=454 367 | [hotpink1]=513 368 | [hotpink2]=412 369 | [hotpink3]=312 370 | [hotpink4]=201 371 | [hotpink]=513 372 | [indianred1]=511 373 | [indianred2]=411 374 | [indianred3]=311 375 | [indianred4]=200 376 | [indianred]=311 377 | [ivory1]=554 378 | [ivory2]=444 379 | [ivory3]=333 380 | [ivory4]=222 381 | [ivory]=554 382 | [khaki1]=542 383 | [khaki2]=442 384 | [khaki3]=331 385 | [khaki4]=220 386 | [khaki]=442 387 | [lavender]=444 388 | [lavenderblush1]=544 389 | [lavenderblush2]=444 390 | [lavenderblush3]=333 391 | [lavenderblush4]=222 392 | [lavenderblush]=544 393 | [lawngreen]=150 394 | [lemonchiffon1]=543 395 | [lemonchiffon2]=443 396 | [lemonchiffon3]=332 397 | [lemonchiffon4]=221 398 | [lemonchiffon]=543 399 | [lightblue1]=345 400 | [lightblue2]=344 401 | [lightblue3]=233 402 | [lightblue4]=122 403 | [lightblue]=344 404 | [lightcoral]=422 405 | [lightcyan1]=455 406 | [lightcyan2]=344 407 | [lightcyan3]=333 408 | [lightcyan4]=122 409 | [lightcyan]=455 410 | [lightgoldenrod1]=542 411 | [lightgoldenrod2]=442 412 | [lightgoldenrod3]=331 413 | [lightgoldenrod4]=220 414 | [lightgoldenrod]=442 415 | [lightgoldenrodyellow]=444 416 | [lightgray]=444 417 | [lightgreen]=242 418 | [lightgrey]=444 419 | [lightpink1]=533 420 | [lightpink2]=423 421 | [lightpink3]=322 422 | [lightpink4]=211 423 | [lightpink]=533 424 | [lightsalmon1]=521 425 | [lightsalmon2]=421 426 | [lightsalmon3]=321 427 | [lightsalmon4]=210 428 | [lightsalmon]=521 429 | [lightseagreen]=033 430 | [lightskyblue1]=345 431 | [lightskyblue2]=244 432 | [lightskyblue3]=233 433 | [lightskyblue4]=112 434 | [lightskyblue]=234 435 | [lightslateblue]=215 436 | [lightslategray]=122 437 | [lightslategrey]=122 438 | [lightsteelblue1]=345 439 | [lightsteelblue2]=344 440 | [lightsteelblue3]=233 441 | [lightsteelblue4]=112 442 | [lightsteelblue]=334 443 | [lightyellow1]=554 444 | [lightyellow2]=443 445 | [lightyellow3]=333 446 | [lightyellow4]=221 447 | [lightyellow]=554 448 | [limegreen]=030 449 | [linen]=444 450 | [magenta1]=505 451 | [magenta2]=404 452 | [magenta3]=303 453 | [magenta4]=202 454 | [magenta]=505 455 | [maroon1]=503 456 | [maroon2]=402 457 | [maroon3]=302 458 | [maroon4]=201 459 | [maroon]=301 460 | [mediumaquamarine]=133 461 | [mediumblue]=003 462 | [mediumorchid1]=415 463 | [mediumorchid2]=314 464 | [mediumorchid3]=303 465 | [mediumorchid4]=102 466 | [mediumorchid]=314 467 | [mediumpurple1]=325 468 | [mediumpurple2]=214 469 | [mediumpurple3]=213 470 | [mediumpurple4]=102 471 | [mediumpurple]=214 472 | [mediumseagreen]=031 473 | [mediumslateblue]=114 474 | [mediumspringgreen]=042 475 | [mediumturquoise]=033 476 | [mediumvioletred]=302 477 | [midnightblue]=001 478 | [mintcream]=454 479 | [mistyrose1]=544 480 | [mistyrose2]=444 481 | [mistyrose3]=333 482 | [mistyrose4]=211 483 | [mistyrose]=544 484 | [moccasin]=543 485 | [navajowhite1]=543 486 | [navajowhite2]=432 487 | [navajowhite3]=332 488 | [navajowhite4]=211 489 | [navajowhite]=543 490 | [navy]=002 491 | [navyblue]=002 492 | [oldlace]=544 493 | [olivedrab1]=350 494 | [olivedrab2]=340 495 | [olivedrab3]=230 496 | [olivedrab4]=120 497 | [olivedrab]=120 498 | [orange1]=520 499 | [orange2]=420 500 | [orange3]=320 501 | [orange4]=210 502 | [orange]=520 503 | [orangered1]=500 504 | [orangered2]=400 505 | [orangered3]=300 506 | [orangered4]=200 507 | [orangered]=500 508 | [orchid1]=524 509 | [orchid2]=414 510 | [orchid3]=313 511 | [orchid4]=202 512 | [orchid]=414 513 | [palegoldenrod]=443 514 | [palegreen1]=252 515 | [palegreen2]=242 516 | [palegreen3]=131 517 | [palegreen4]=121 518 | [palegreen]=242 519 | [paleturquoise1]=355 520 | [paleturquoise2]=344 521 | [paleturquoise3]=233 522 | [paleturquoise4]=122 523 | [paleturquoise]=344 524 | [palevioletred1]=523 525 | [palevioletred2]=412 526 | [palevioletred3]=312 527 | [palevioletred4]=201 528 | [palevioletred]=412 529 | [papayawhip]=544 530 | [peachpuff1]=543 531 | [peachpuff2]=433 532 | [peachpuff3]=332 533 | [peachpuff4]=211 534 | [peachpuff]=543 535 | [peru]=320 536 | [pink1]=533 537 | [pink2]=433 538 | [pink3]=322 539 | [pink4]=211 540 | [pink]=533 541 | [plum1]=535 542 | [plum2]=434 543 | [plum3]=323 544 | [plum4]=212 545 | [plum]=424 546 | [powderblue]=344 547 | [purple1]=205 548 | [purple2]=204 549 | [purple3]=103 550 | [purple4]=102 551 | [purple]=204 552 | [red1]=500 553 | [red2]=400 554 | [red3]=300 555 | [red4]=200 556 | [red]=500 557 | [rosybrown1]=533 558 | [rosybrown2]=433 559 | [rosybrown3]=322 560 | [rosybrown4]=211 561 | [rosybrown]=322 562 | [royalblue1]=015 563 | [royalblue2]=014 564 | [royalblue3]=013 565 | [royalblue4]=002 566 | [royalblue]=014 567 | [saddlebrown]=200 568 | [salmon1]=521 569 | [salmon2]=421 570 | [salmon3]=311 571 | [salmon4]=200 572 | [salmon]=421 573 | [sandybrown]=421 574 | [seagreen1]=152 575 | [seagreen2]=042 576 | [seagreen3]=032 577 | [seagreen4]=021 578 | [seagreen]=021 579 | [seashell1]=544 580 | [seashell2]=444 581 | [seashell3]=333 582 | [seashell4]=222 583 | [seashell]=544 584 | [sienna1]=520 585 | [sienna2]=410 586 | [sienna3]=310 587 | [sienna4]=200 588 | [sienna]=200 589 | [skyblue1]=235 590 | [skyblue2]=234 591 | [skyblue3]=123 592 | [skyblue4]=012 593 | [skyblue]=234 594 | [slateblue1]=215 595 | [slateblue2]=114 596 | [slateblue3]=113 597 | [slateblue4]=002 598 | [slateblue]=113 599 | [slategray1]=345 600 | [slategray2]=344 601 | [slategray3]=233 602 | [slategray4]=112 603 | [slategray]=122 604 | [slategrey]=122 605 | [snow1]=544 606 | [snow2]=444 607 | [snow3]=333 608 | [snow4]=222 609 | [snow]=544 610 | [springgreen1]=052 611 | [springgreen2]=041 612 | [springgreen3]=031 613 | [springgreen4]=020 614 | [springgreen]=052 615 | [steelblue1]=135 616 | [steelblue2]=134 617 | [steelblue3]=023 618 | [steelblue4]=012 619 | [steelblue]=023 620 | [tan1]=520 621 | [tan2]=420 622 | [tan3]=320 623 | [tan4]=210 624 | [tan]=432 625 | [thistle1]=545 626 | [thistle2]=444 627 | [thistle3]=333 628 | [thistle4]=212 629 | [thistle]=434 630 | [tomato1]=510 631 | [tomato2]=410 632 | [tomato3]=300 633 | [tomato4]=200 634 | [tomato]=510 635 | [turquoise1]=045 636 | [turquoise2]=044 637 | [turquoise3]=033 638 | [turquoise4]=022 639 | [turquoise]=043 640 | [violet]=424 641 | [violetred1]=502 642 | [violetred2]=402 643 | [violetred3]=301 644 | [violetred4]=200 645 | [violetred]=302 646 | [wheat1]=543 647 | [wheat2]=443 648 | [wheat3]=332 649 | [wheat4]=221 650 | [wheat]=443 651 | [white]=555 652 | [whitesmoke]=444 653 | [yellow1]=550 654 | [yellow2]=440 655 | [yellow3]=330 656 | [yellow4]=220 657 | [yellow]=550 658 | [yellowgreen]=230 659 | ) 660 | -------------------------------------------------------------------------------- /src/themes/progit: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; -*- 2 | #=============================================================================== 3 | :< 6 | 7 | This file is part of the bash-color-tools 8 | 9 | bash-color-tools is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | LICENSE 23 | 24 | #=============================================================================== 25 | # progit 26 | #------------------------------------------------------------------------------- 27 | # power user's git theme 28 | #=============================================================================== 29 | 30 | THEME=progit 31 | 32 | #=============================================================================== 33 | # 'prompt progit' 34 | # when in a repository shows all relevent repo status indicators, 35 | # including local:remote commit status in the branch field: 36 | # (cbarry@mybox)-[Index not updated:4|Deleted in tree:2|Untracked:7] 37 | # [master 3:0][.../src/apps/]:: 38 | # 39 | # when outside a repository, or if repository is clean, show time, 40 | # date and 1, 5, and 15min load averages: 41 | # (cbarry@mybox)-(02:03 / Sun Jun 30)-(0.2|0.1|0.3) 42 | # [-][.../usr/local/sbin]:: 43 | # 44 | function prompt_progit_theme() 45 | { 46 | # override and customize defaults with dotfile 47 | [[ -f ~/.prompt-themes.d/conf/${THEME}.theme ]] || { 48 | mkdir -p ~/.prompt-themes.d/conf 49 | cat > ~/.prompt-themes.d/conf/${THEME}.theme </dev/null) 158 | [[ ${gb} ]] && { 159 | gb=${gb##*/} 160 | loc_rem="$(git rev-list --left-right ${gb}...origin/${gb} --count 2>/dev/null)" 161 | [[ ${?} -eq 0 ]] || loc_rem= 162 | [[ ! ${loc_rem} || "${loc_rem//[[:blank:]]/:}" == "0:0" ]] && { 163 | gb_data="${gb}" 164 | } || { 165 | gb_data="${gb} ${loc_rem//[[:blank:]]/:}" 166 | } 167 | prompt_fuzzy_truncate ${PROMPT_MAXBRANCHLEN} ${PROMPT_BRANCH_FUZZFACTOR} ${PROMPT_BRANCH_DELIM} "${gb_data}" 168 | } || { 169 | prompt_fuzzy_truncate ${PROMPT_MAXBRANCHLEN} ${PROMPT_BRANCH_FUZZFACTOR} ${PROMPT_BRANCH_DELIM} "${PROMPT_NOGIT_CHAR}" 170 | } 171 | 172 | return 0 173 | } 174 | # short alias 175 | function pgfb() { prompt_git_fuzzy_branch; } 176 | 177 | #------------------------------------------------------------------------------- 178 | function prompt_git_status() 179 | { 180 | local XY X Y out 181 | while IFS='' read line; do 182 | XY="${line:0:2}" 183 | [[ "${XY:0:1}" == " " ]] && X="_" || X="${XY:0:1}" 184 | [[ "${XY:1:1}" == " " ]] && Y="_" || Y="${XY:1:1}" 185 | out+=( "${X}${Y}" ) 186 | done < <(git status --porcelain 2>&1) 187 | echo "${out[@]}" 188 | } 189 | function pgs() { prompt_git_status; } 190 | 191 | #=============================================================================== 192 | # from man git-status 193 | :<<'DOCUMENT' 194 | ' ' = unmodified 195 | M = modified 196 | A = added 197 | D = deleted 198 | R = renamed 199 | C = copied 200 | U = updated but unmerged 201 | 202 | X Y Meaning 203 | ------------------------------------------------- 204 | [MD] not updated 205 | M [ MD] updated in index 206 | A [ MD] added to index 207 | D [ M] deleted from index 208 | R [ MD] renamed in index 209 | C [ MD] copied in index 210 | [MARC] index and work tree matches 211 | [ MARC] M work tree changed since index 212 | [ MARC] D deleted in work tree 213 | ------------------------------------------------- 214 | D D unmerged, both deleted 215 | A U unmerged, added by us 216 | U D unmerged, deleted by them 217 | U A unmerged, added by them 218 | D U unmerged, deleted by us 219 | A A unmerged, both added 220 | U U unmerged, both modified 221 | ------------------------------------------------- 222 | ? ? untracked 223 | ------------------------------------------------- 224 | DOCUMENT 225 | #=============================================================================== 226 | 227 | #------------------------------------------------------------------------------- 228 | function prompt_git_status_dashboard() 229 | { 230 | local -i not_updated updated_in_index added_to_index deleted_from_index renamed_in_index 231 | local -i copied_in_index index_and_work_tree_matches work_tree_changed_since_last_index 232 | local -i deleted_in_work_tree unmerged_both_deleted unmerged_added_by_us unmerged_deleted_by_them 233 | local -i unmerged_added_by_them unmerged_deleted_by_us unmerged_both_added unmerged_both_modified untracked 234 | local -i cnt dsh lavg 235 | local s= 236 | local -a dashboard=() loadavg=() 237 | 238 | len() { local t="$*"; echo ${#t}; } 239 | 240 | if git status -s &>/dev/null; then 241 | 242 | # parse the status, counting instances of each 243 | for s in $(prompt_git_status); do 244 | 245 | case ${s} in 246 | # normal status 247 | _[MD]) ((not_updated++)) ;;& 248 | M[_MD]) ((updated_in_index++)) ;;& 249 | A[_MD]) ((added_to_index++)) ;;& 250 | D[_M]) ((deleted_from_index++)) ;;& 251 | R[_MD]) ((renamed_in_index++)) ;;& 252 | C[_MD]) ((copied_in_index++)) ;;& 253 | [MARC]_) ((index_and_work_tree_matches++)) ;;& 254 | [_MARC]M) ((work_tree_changed_since_index++)) ;;& 255 | [_MARC]D) ((deleted_in_work_tree++)) ;;& 256 | # merge status 257 | DD) ((unmerged_both_deleted++)) ;;& 258 | AU) ((unmerged_added_by_us++)) ;;& 259 | UD) ((unmerged_deleted_by_them++)) ;;& 260 | UA) ((unmerged_added_by_them++)) ;;& 261 | DU) ((unmerged_deleted_by_us++)) ;;& 262 | AA) ((unmerged_both_added++)) ;;& 263 | UU) ((unmerged_both_modified++)) ;;& 264 | # untracked status 265 | \?\?) ((untracked++)) ;; 266 | esac 267 | 268 | done 269 | 270 | # remote status element 271 | 272 | # normal dashboard elements 273 | [[ ${not_updated} -gt 0 ]] && dashboard+=("Index not updated:${not_updated}") 274 | [[ ${updated_in_index} -gt 0 ]] && dashboard+=("Index updated:${updated_in_index}") 275 | [[ ${added_to_index} -gt 0 ]] && dashboard+=("Added to index:${added_to_index}") 276 | [[ ${deleted_from_index} -gt 0 ]] && dashboard+=("Deleted from index:${deleted_from_index}") 277 | [[ ${renamed_in_index} -gt 0 ]] && dashboard+=("Renamed in index:${renamed_in_index}") 278 | [[ ${copied_in_index} -gt 0 ]] && dashboard+=("Copied in index:${copied_in_index}") 279 | [[ ${index_and_work_tree_matches} -gt 0 ]] && dashboard+=("Index and tree in sync:${index_and_work_tree_matches}") 280 | [[ ${work_tree_changed_since_index} -gt 0 ]] && dashboard+=("Tree changed:${work_tree_changed_since_index}") 281 | [[ ${deleted_in_work_tree} -gt 0 ]] && dashboard+=("Deleted in tree:${deleted_in_work_tree}") 282 | # merge dashboard elements 283 | [[ ${unmerged_both_deleted} -gt 0 ]] && dashboard+=("Both deleted:${unmerged_both_deleted}") 284 | [[ ${unmerged_added_by_us} -gt 0 ]] && dashboard+=("Added here:${unmerged_added_by_us}") 285 | [[ ${unmerged_deleted_by_them} -gt 0 ]] && dashboard+=("Deleted there:${unmerged_deleted_by_them}") 286 | [[ ${unmerged_added_by_them} -gt 0 ]] && dashboard+=("Added there:${unmerged_added_by_them}") 287 | [[ ${unmerged_deleted_by_us} -gt 0 ]] && dashboard+=("Deleted here:${unmerged_deleted_by_us}") 288 | [[ ${unmerged_both_added} -gt 0 ]] && dashboard+=("Both added:${unmerged_both_added}") 289 | [[ ${unmerged_both_modified} -gt 0 ]] && dashboard+=("Both modified:${unmerged_both_modified}") 290 | # untracked dashboard element 291 | [[ ${untracked} -gt 0 ]] && dashboard+=("Untracked:${untracked}") 292 | 293 | fi 294 | 295 | _face -${l}nf ${PROMPT_MC_CLR} "$(in_midnight_commander)" 296 | _face -${l}nf ${PROMPT_PAREN_CLR} "${PROMPT_LPAREN_CHAR}" 297 | _face -${l}nf ${PROMPT_USER_CLR} "${USER}" 298 | _face -${l}nf ${PROMPT_AT_CLR} "${PROMPT_AT_CHAR}" 299 | _face -${l}nf ${PROMPT_HOST_CLR} "$(hostname -s)" 300 | _face -${l}nf ${PROMPT_PAREN_CLR} "${PROMPT_RPAREN_CHAR}" 301 | _face -${l}nf ${PROMPT_DASH_CLR} "${PROMPT_DASH_CHAR}" 302 | [[ ${#dashboard[@]} -gt 0 ]] && { 303 | _face -${l}nf ${PROMPT_BRKT_CLR} "${PROMPT_LBRKT_CHAR}" 304 | for (( dsh=0; dsh<${#dashboard[@]}; dsh++ )); do 305 | [[ ${cnt} ]] && _face -${l}nf ${PROMPT_DASHSEP_CLR} "${PROMPT_SEP_CHAR}" 306 | _face -${l}nf ${PROMPT_STATUS_TXT_CLR} "${dashboard[dsh]%:*}:" 307 | _face -${l}nf ${PROMPT_STATUS_NUM_CLR} "${dashboard[dsh]#*:}" 308 | ((cnt++)) 309 | done 310 | _face -${l}nf ${PROMPT_BRKT_CLR} "${PROMPT_RBRKT_CHAR}" 311 | } || { 312 | case ${PROMPT_PLATFORM_NAME} in 313 | Linux) loadavg=( $( 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------