diff --git a/.gitignore b/.gitignore index 827d95c..8d481d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.html +*swp # emacs backup and lock files *~ diff --git a/.gitremotes b/.gitremotes new file mode 100644 index 0000000..67cbb50 --- /dev/null +++ b/.gitremotes @@ -0,0 +1,4 @@ +lvv git://github.com/lvv/git-prompt.git (fetch) +lvv git://github.com/lvv/git-prompt.git (push) +origin git@github.com:juanpabloaj/git-prompt.git (fetch) +origin git@github.com:juanpabloaj/git-prompt.git (push) diff --git a/Makefile b/Makefile index 27631ce..a14d566 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,10 @@ -ifeq ($(USER),lvv) - HOMEDIR := /home/lvv/p/volnitsky.com/ - INCLUDE := $(HOMEDIR)/include.mk -else - INCLUDE := /dev/null -endif - -include $(INCLUDE) - - -COPY_LIST = git-prompt.sh - - install: - cp -v git-prompt.sh /etc/ - [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ - -tgit: - xclip -i git-demo - echo "ready to paste ..." - + [ -f $(HOME)/.git-prompt.conf ] || ln -vfn -s $(shell pwd)/git-prompt.conf $(HOME)/.git-prompt.conf + @echo + @echo 'add to ~/.bashrc' + @echo '[[ $$- == *i* ]] && . $(PWD)/git-prompt.sh' +clean: + [ -f $(HOME)/.git-prompt.conf ] && unlink $(HOME)/.git-prompt.conf + @echo + @echo 'remove in ~/.bashrc' + @echo '[[ $$- == *i* ]] && . $(PWD)/git-prompt.sh' diff --git a/README b/README deleted file mode 100644 index 0937cc0..0000000 --- a/README +++ /dev/null @@ -1,5 +0,0 @@ -GIT Prompt for BASH - -Screenshots and docs are at: http://volnitsky.com/project/git-prompt - - diff --git a/README.md b/README.md new file mode 100644 index 0000000..10b72a6 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# GIT Prompt for BASH + +Forked from [lvv-git-prompt](https://github.com/lvv/git-prompt) + +Screenshots and docs are at: [volnitsky.com](http://volnitsky.com/project/git-prompt) + +## Screenshots + +### prompt-git + +![prompt-git](https://github.com/juanpabloaj/git-prompt/raw/master/screenshot-prompt-git.png) + +### prompt-svn + +![prompt-svn](https://github.com/juanpabloaj/git-prompt/raw/master/screenshot-svn.png) diff --git a/git-prompt.conf b/git-prompt.conf index dee3c0c..c827dcc 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -15,10 +15,10 @@ ############################################################ MODULES -# git_module=on -# svn_module=off -# hg_module=on -# vim_module=on +git_module=on +svn_module=on +hg_module=on +vim_module=on # virtualenv_module=on @@ -31,15 +31,17 @@ ########################################################### Current Working Dir display # cwd_cmd='\w' # display full path -## cwd_cmd='\W' # display only last dir of path +cwd_cmd='\W' # display only last dir of path ## cwd_cmd='cwd_truncate 40' # display only last N chars of path ########################################################### ETC # Some don't like hostname in uppercase # upcase_hostname=on # =off +upcase_hostname=off # Some don't like long hostname # short_hostname=off # =on +short_hostname=on # Do not do VCS parsing for listed directories # useful for directories for which it is difficult to maintain .gitignore so @@ -50,12 +52,12 @@ ### directory, exit code, root color -# cols=`tput colors` + cols=`tput colors` # if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors - # dir_color=CYAN - # rc_color=red + dir_color=white + rc_color=red # virtualenv_color=green - # user_id_color=blue + user_id_color=white # root_id_color=magenta # else # B/W terminal # dir_color=bw_bold @@ -65,7 +67,7 @@ ### prompt character for root/non-root, default '>' for both # prompt_char='>' # root_prompt_char='>' -## prompt_char='$' +prompt_char='$' ## prompt_char='➔' ## root_prompt_char='#' diff --git a/git-prompt.sh b/git-prompt.sh index d1e88b3..9872f15 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -66,14 +66,14 @@ op_vcs_color=${op_vcs_color:-MAGENTA} detached_vcs_color=${detached_vcs_color:-RED} - hex_vcs_color=${hex_vcs_color:-BLACK} # gray + hex_vcs_color=${hex_vcs_color:-white} max_file_list_length=${max_file_list_length:-100} short_hostname=${short_hostname:-off} upcase_hostname=${upcase_hostname:-on} count_only=${count_only:-off} - rawhex_len=${rawhex_len:-5} + rawhex_len=${rawhex_len:-6} aj_max=20 @@ -323,6 +323,8 @@ set_shell_label() { color_index=(green yellow blue magenta cyan white) # FIXME: bw, color-256 host_color=${color_index[cksum_color_no]} fi + #host_color fix in white + host_color=white host_color=${!host_color} @@ -517,7 +519,35 @@ parse_git_status() { # branch="$(git describe --exact-match HEAD 2>/dev/null)" || \ # branch="$(cut -c1-7 "$git_dir/HEAD")..." fi - + if [[ $branch == "master" ]]; then + # Only work with master branch + # TODO : make this a module on/off + # hourly checks new commits in remotes + fetchUpdate=3600 + remotes=() + for remote in $(git remote) + do + if [[ ! -e $git_dir/FETCH_HEAD ]]; then + ( git fetch $remote >& /dev/null &) + else + fetchDate=$(date --utc --reference=$git_dir/FETCH_HEAD +%s) + now=$(date --utc +%s) + delta=$(( $now - $fetchDate )) + # if last update to .git/FETCH_HEAD file + if [[ $delta -gt $fetchUpdate ]]; then + ( git fetch $remote >& /dev/null &) + fi + fi + if [[ $(git branch -a | grep $remote) != "" ]]; then + nRemoteCommit=$(git log --oneline HEAD..$remote/master | wc -l) + if [[ -f $git_dir/FETCH_HEAD && $nRemoteCommit != "0" ]]; then + remotes+=" "${remote/origin/o}:$nRemoteCommit + fi + else + (git fetch $remote >& /dev/null &) + fi + done + fi #### GET GIT HEX-REVISION if [[ $rawhex_len -gt 0 ]] ; then @@ -564,6 +594,7 @@ parse_vcs_status() { unset vcs vcs_info unset status modified untracked added init detached unset file_list modified_files untracked_files added_files + unset remotes [[ $vcs_ignore_dir_list =~ $PWD ]] && return @@ -632,7 +663,7 @@ parse_vcs_status() { fi - head_local="$vcs_color(${vcs_info}$vcs_color${file_list}$vcs_color)" + head_local="$vcs_color(${vcs_info}$vcs_color${file_list}$vcs_color$remotes)" ### fringes head_local="${head_local+$vcs_color$head_local }" @@ -654,7 +685,6 @@ parse_virtualenv_status() { disable_set_shell_label() { trap - DEBUG >& /dev/null } - # show currently executed command in label enable_set_shell_label() { disable_set_shell_label @@ -684,11 +714,8 @@ j (){ done echo '?' } - alias jumpstart='echo ${aj_dir_list[@]}' - ###################################################################### PROMPT_COMMAND - prompt_command_function() { rc="$?" @@ -717,11 +744,7 @@ prompt_command_function() { unset head_local tail_local pwd } - PROMPT_COMMAND=prompt_command_function - enable_set_shell_label - unset rc id tty modified_files file_list - # vim: set ft=sh ts=8 sw=8 et: