diff options
author | Leonid Volnitsky <Leonid@Volnitsky.com> | 2009-03-13 21:09:18 +0200 |
---|---|---|
committer | Leonid Volnitsky <Leonid@Volnitsky.com> | 2009-03-13 21:09:18 +0200 |
commit | 646ca93318631d89fb22d4c26ba1a60eaca2c204 (patch) | |
tree | c4635dd2c499e4ddae861add686cfac994749555 | |
parent | -- docs (diff) | |
download | git-prompt-646ca93318631d89fb22d4c26ba1a60eaca2c204.tar.gz git-prompt-646ca93318631d89fb22d4c26ba1a60eaca2c204.tar.bz2 git-prompt-646ca93318631d89fb22d4c26ba1a60eaca2c204.zip |
external config
Squashed commit of the following:
commit d2dd640947b803bfd0df4c68b841457ce543995d
Author: Leonid Volnitsky <Leonid@Volnitsky.com>
Date: Wed Mar 11 21:29:49 2009 +0200
-- if max_file_list_lenght==0 (disabled), then do not display "..."
commit 4dc94f9668b797142cbd525d2fc9137f615bc2db
Author: Leonid Volnitsky <Leonid@Volnitsky.com>
Date: Wed Mar 11 21:19:09 2009 +0200
-- switch git_module works
commit 7d7d3e1996d6834f2cccc900ac5bc626ff2ce6bb
Author: Leonid Volnitsky <Leonid@Volnitsky.com>
Date: Sun Mar 8 19:41:47 2009 +0200
-- colors are working
commit f1a8382bd7c4b2b1c27fc9908efa54f74290f06a
Merge: 876c85e 4a8777a
Author: Leonid Volnitsky <Leonid@Volnitsky.com>
Date: Sun Mar 8 18:25:52 2009 +0200
Merge branch 'master' into config
Conflicts:
index.txt
commit 876c85e87090c7de5740538666bdf558e30923b9
Author: Leonid Volnitsky <Leonid@Volnitsky.com>
Date: Fri Feb 20 13:44:52 2009 +0200
-- conf
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | demo-more-script | 37 | ||||
-rwxr-xr-x | demo-script | 40 | ||||
-rw-r--r-- | git-prompt.conf | 53 | ||||
-rw-r--r-- | git-prompt.sh | 147 | ||||
-rw-r--r-- | index.txt | 3 | ||||
-rw-r--r-- | labels-screenshot.png | bin | 0 -> 176893 bytes | |||
-rw-r--r-- | screenshot-prompt-basic.png | bin | 24791 -> 16849 bytes | |||
-rw-r--r-- | screenshot-prompt-git.png | bin | 201168 -> 147592 bytes | |||
-rw-r--r-- | svn-screenshot.png | bin | 0 -> 221287 bytes |
11 files changed, 218 insertions, 73 deletions
@@ -1,7 +1,7 @@ -#install: -# cp git-prompt.sh /etc/ -# [ -s /etc/prompt ] || ln -sf /etc/git-prompt.sh /etc/prompt +install: + cp -v git-prompt.{sh,conf} /etc/ + tgit: xclip -i git-demo echo "ready to paste ..." @@ -10,13 +10,13 @@ WEB_DESTDIR ?= /tmp/html ASCIIDOC ?= asciidoc -show: web_install +show: localweb firefox $(WEB_DESTDIR)/index.html index.html: index.txt $(ASCIIDOC) -o $@ $< -web_install: index.html *.png git-prompt.sh +localweb: index.html *.png git-prompt.sh mkdir -p $(WEB_DESTDIR) cp -uv $^ $(WEB_DESTDIR) @@ -30,6 +30,7 @@ DEPENDENCY TODO + - git locked state if .git/index.lock exist - external config at /etc/git-prompt.conf and ~/.git-prompt.conf - avoid wrapping to 2nd line if file list is too long - check current terminal width - new mail (howto at: http://kikhome.net/?p=11) diff --git a/demo-more-script b/demo-more-script new file mode 100644 index 0000000..ca33522 --- /dev/null +++ b/demo-more-script @@ -0,0 +1,37 @@ +set +xv +. /t/prompt/prompt +test -d demo && rm -rf demo/ +test -d ../demo && cd .. && rm -rf demo/ +clear +: ------------------------------------------------------------------------ +mkdir demo +cd demo +git init +echo 'main() {puts("Hello World!");}' > hello.c +make hello && ./hello +git add hello.c +git commit -q -m "1st hello" +git checkout -b universe; git clean -f +echo 'main() {puts("Hello Universe!");}' > hello.c +git add hello.c +echo "// FIXME: includes" >> hello.c +git add hello.c +git commit -q -m "notes to self" +git checkout master +cat hello.c +echo 'main() {puts("Hello Universe!"); exit(0);}' > hello.c +git add hello.c +git commit -q -m "fixed exit code" +git merge universe +git cat-file -p universe:hello.c > hello.c +git add hello.c +git commit -q -m "merged" +cat hello.c +git checkout HEAD^ +git checkout HEAD^ +cat hello.c +git checkout master +sleep 2; echo "this emulates unsaved vim session" > .hello.c.swp +git clean -f +: ------------------------------------------------------------------------ +cd .. diff --git a/demo-script b/demo-script new file mode 100755 index 0000000..1374a1f --- /dev/null +++ b/demo-script @@ -0,0 +1,40 @@ +cd p/git-prompt +. ./git-prompt.sh +cd +test -d demo && rm -rf demo/ +test -d ../demo && cd .. && rm -rf demo/ +clear +: ------------------------------------------------------------------------ +clear +mkdir demo +cd demo +git init +echo "1st line" > FOO +git add FOO +touch untracked.o +echo '*.o' >> .gitignore +git commit -q -m "1st line" FOO +git checkout -b test +echo "added 2nd line in test" >> FOO +git add FOO +echo "2nd in BAR" > BAR +git add BAR +echo "added 3nd line FOO" >> FOO +git add FOO +git commit -q -m "FOO moded, BAR added" +git checkout master +cat FOO +echo "now added 2nd line in master" >> FOO +git add FOO +git commit -q -m "2nd line" +git merge test +git cat-file -p test:FOO > FOO +git add FOO +git commit -q -m "merged" +cat FOO +git checkout HEAD^ +cat FOO +git checkout HEAD +git clean -f +: ------------------------------------------------------------------------ +cd .. diff --git a/git-prompt.conf b/git-prompt.conf new file mode 100644 index 0000000..3b29beb --- /dev/null +++ b/git-prompt.conf @@ -0,0 +1,53 @@ +# git-prompt.sh config +# +# commented-out variales are default values + + +##### MODULES +#git_module=on +#svn_module=off +#vim_module=on + + +### Default objects are not displayed +#default_user=lvv +#default_host="ahp" # remote host is always shown +#default_domain="lvvnet" + + +##### dir, exit code, root color +#if [ 0`tput colors` -ge 8 ]; then # if terminal supports colors + # dir_color=CYAN + # rc_color=red + # root_id_color=magenta +#else # B/W terminal + # dir_color=bw_bold + # rc_color=bw_bold +#fi + +##### Per host color .If not set, color derived from host-name checksum) +## variable name is uppercase-short-hostname with appended "_host_color" +## Per host color. If not set, color derived from host-name checksum) +## Example per-host-color config: +## +## TASHA_host_color=cyan +## AL_host_color=green +## LVV_host_color=blue +## AHP_host_color=white + + + +##### VCS state colors +# init_vcs_color=WHITE # initial +# clean_vcs_color=blue # nothing to commit (working directory clean) +# modified_vcs_color=red # Changed but not updated: +# added_vcs_color=green # Changes to be committed: +# mixed_vcs_color=yellow # +# untracked_vcs_color=BLUE # Untracked files: +# op_vcs_color=MAGENTA +# detached_vcs_color=RED + +# max_file_list_length=100 + + +: vim:ft=sh: diff --git a/git-prompt.sh b/git-prompt.sh index 9866d04..1b9736f 100644 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -1,49 +1,51 @@ # don't set prompt if this is not interactive shell -# it is better if this test is done before git-prompt.sh is sources for performance reasons. -[[ $- != *i* ]] && return +# it is better if this test is done before git-prompt.sh is source-ed for performance reasons. +[[ $- != *i* ]] && return -##################################################################### CONFIG - default_user=lvv # default user is not displayed - default_host="ahp" # default host is not displayed - default_domain="lvvnet" # default domain is not displayed, remote host is always shown +################################################################### CONFIG - # dir, rc, root color + ##### read config file if any. + + unset dir_color rc_color root_id_color init_vcs_color clean_vcs_color modified_vcs_color added_vcs_color mixed_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color + + conf=git-prompt.conf; [[ -r $conf ]] && . $conf + conf=/etc/git-prompt.conf; [[ -r $conf ]] && . $conf + conf=~/.git-prompt.conf; [[ -r $conf ]] && . $conf + unset conf + + ##### set defaults if not set + + git_module=${git_module:-on} + svn_module=${svn_module:-off} + vim_module=${vim_module:-on} + + + #### dir, rc, root color if [ 0`tput colors` -ge 8 ]; then # if terminal supports colors - dir_color='CYAN' - rc_color='red' - root_id_color='magenta' + dir_color=${dir_color:-CYAN} + rc_color=${rc_color:-red} + root_id_color=${root_id_color:-magenta} else # only B/W - dir_color='bw_bold' - rc_color='bw_bold' + dir_color=${dir_color:-bw_bold} + rc_color=${rc_color:-bw_bold} fi - # where is user color? - - # per host color - TOSHA_host_color=yellow - TASHA_host_color=cyan - AL_host_color=green - SH_host_color=blue - LVV_host_color=blue - AHP_host_color=white - - # vcs state colors - init_vcs_color=WHITE # initial - clean_vcs_color=blue # nothing to commit (working directory clean) - modified_vcs_color=red # Changed but not updated: - added_vcs_color=green # Changes to be committed: - mixed_vcs_color=yellow # - untracked_vcs_color=BLUE # Untracked files: - op_vcs_color=MAGENTA - detached_vcs_color=RED - - #max_untracked=2 - #max_modified=4 - #max_added=4 - max_file_list_length=100 - - ##################################################################### post config + #### vcs state colors + init_vcs_color=${init_vcs_color:-WHITE} # initial + clean_vcs_color=${clean_vcs_color:-blue} # nothing to commit (working directory clean) + modified_vcs_color=${modified_vcs_color:-red} # Changed but not updated: + added_vcs_color=${added_vcs_color:-green} # Changes to be committed: + mixed_vcs_color=${mixed_vcs_color:-yellow} + untracked_vcs_color=${untracked_vcs_color:-BLUE} # Untracked files: + op_vcs_color=${op_vcs_color:-MAGENTA} + detached_vcs_color=${detached_vcs_color:-RED} + + max_file_list_length=${max_file_list_length:-100} + + + +##################################################################### post config ################# terminfo colors-16 # @@ -115,7 +117,6 @@ label=${1:+$1 } - # echo "*** /etc/prompt on A, TERM=$TERM" unset PROMPT_COMMAND ####### work around for MC bug @@ -127,6 +128,9 @@ export who_where + on='' + off=': ' + set_shell_title() { @@ -148,7 +152,7 @@ set_shell_title() { xterm* | rxvt* | gnome-terminal | konsole | eterm | wterm ) # is there a capability which we can to test - # for "set term title-bat" and its escapes? + # for "set term title-bar" and its escapes? #echo -n "]2;$label$plain_who_where $1" xterm_title "$label$plain_who_where $@" ;; @@ -194,7 +198,7 @@ set_shell_title() { # How to find out if session is local or remote? Working with "su -", ssh-agent, and so on ? ## is sshd our parent? - # if { for ((pid=$$; $pid != 1 ; pid=`ps h -o pid --ppid $pid`)); do ps h -o command -p $pid; done | grep -q sshd } + # if { for ((pid=$$; $pid != 1 ; pid=`ps h -o pid --ppid $pid`)); do ps h -o command -p $pid; done | grep -q sshd && echo == REMOTE ==; } #then host=${HOSTNAME} #host=`hostname --short` @@ -244,7 +248,7 @@ set_shell_title() { parse_svn_dir() { - if [[ ! -d .svn || $HOME == $PWD ]]; then # if home dir under svn - don't clutter home dir prompt + if [[ $svn_module = "off" || ! -d .svn || $HOME == $PWD ]]; then # if home dir under svn - don't clutter home dir prompt return 1 fi @@ -277,9 +281,11 @@ parse_svn_dir() { parse_git_dir() { - git_dir=`git rev-parse --git-dir 2> /dev/null` + git_dir=`[[ $git_module = "on" ]] && git rev-parse --git-dir 2> /dev/null` + #git_dir=`eval \$$git_module git rev-parse --git-dir 2> /dev/null` + #git_dir=` git rev-parse --git-dir 2> /dev/null` - [[ -n ${git_dir/./} ]] || return 1 + [[ -n ${git_dir/./} ]] || return 1 vcs=git @@ -319,7 +325,9 @@ parse_git_dir() { detached=detached fi - ### OP + + ################# GET GIT OP + unset op if [[ -d "$git_dir/.dotest" ]] ; then @@ -355,7 +363,8 @@ parse_git_dir() { # branch="$(cut -c1-7 "$git_dir/HEAD")..." fi - ##################################################################### + + #### GET GIT HEX-REVISION rawhex=`git rev-parse HEAD 2>/dev/null` rawhex=${rawhex/HEAD/} @@ -391,6 +400,7 @@ parse_git_dir() { fi } + parse_vcs_dir() { unset file_list modified_files untracked_files added_files @@ -418,18 +428,20 @@ parse_vcs_dir() { ### VIM ( not yet works for multiple files ) - unset vim_glob vim_file vim_files - old_nullglob=`shopt -p nullglob` - shopt -s nullglob - vim_glob=`echo .*.swp` - eval $old_nullglob - - if [[ $vim_glob ]]; then - vim_file=${vim_glob#.} - vim_file=${vim_file%.swp} - # if swap is newer, then unsaved vim session - [[ .${vim_file}.swp -nt $vim_file ]] && vim_files=$vim_file - fi + if [[ $vim_module = "on" ]] ; then + unset vim_glob vim_file vim_files + old_nullglob=`shopt -p nullglob` + shopt -s nullglob + vim_glob=`echo .*.swp` + eval $old_nullglob + + if [[ $vim_glob ]]; then + vim_file=${vim_glob#.} + vim_file=${vim_file%.swp} + # if swap is newer, then unsaved vim session + [[ .${vim_file}.swp -nt $vim_file ]] && vim_files=$vim_file + fi + fi ### file list @@ -442,7 +454,9 @@ parse_vcs_dir() { if [[ ${#file_list} -gt $max_file_list_length ]] ; then file_list=${file_list:0:$max_file_list_length} - file_list="${file_list% *} ..." + if [[ $max_file_list_length -gt 0 ]] ; then + file_list="${file_list% *} ..." + fi fi @@ -475,14 +489,15 @@ prompt_command_function() { # front=7 # head=${PWD:0:$front}"..." - parse_vcs_dir - ######################### - # PS1="$label$rc'$color_who_where$dir_color'${head:10*(${#PWD}<max)}${PWD:(${#PWD}>max)*(${#PWD}-max):max}> '$colors_reset'" - - PS1="$head_local$colors_reset$label$rc$color_who_where$dir_color\w$tail_local$dir_color> $colors_reset" - - unset head_local tail_local + parse_vcs_dir + + ######################### + # PS1="$label$rc'$color_who_where$dir_color'${head:10*(${#PWD}<max)}${PWD:(${#PWD}>max)*(${#PWD}-max):max}> '$colors_reset'" + + PS1="$head_local$colors_reset$label$rc$color_who_where$dir_color\w$tail_local$dir_color> $colors_reset" + + unset head_local tail_local } @@ -10,8 +10,7 @@ image:screenshot-prompt-basic.png[basic usage] -Digit [red]*1* on 3rd line is `false(1)` exit code. Host names are colored -according to config or from hostname checksum if not in config. +Digit [red]*1* on 3rd line is `false(1)` exit code. == GIT diff --git a/labels-screenshot.png b/labels-screenshot.png Binary files differnew file mode 100644 index 0000000..273c552 --- /dev/null +++ b/labels-screenshot.png diff --git a/screenshot-prompt-basic.png b/screenshot-prompt-basic.png Binary files differindex 9a0cbfe..237e0ec 100644 --- a/screenshot-prompt-basic.png +++ b/screenshot-prompt-basic.png diff --git a/screenshot-prompt-git.png b/screenshot-prompt-git.png Binary files differindex b9a4421..eccbc3e 100644 --- a/screenshot-prompt-git.png +++ b/screenshot-prompt-git.png diff --git a/svn-screenshot.png b/svn-screenshot.png Binary files differnew file mode 100644 index 0000000..da76080 --- /dev/null +++ b/svn-screenshot.png |