Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jringle/file list #30

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion git-prompt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
### lines commented-out with double '##' are examples
###
### NOTE: this is bash syntax - no spaces around "="

###
### You can override on a git per-repo by creating a .git/.git-prompt.conf
### NOTE: If you do this, prefix any variable overrides with 'local'
### i.e.:
### local file_list_mode=fileonly
###
###########################################################

# error_bell=off # sound terminal bell when command return code is not zero. (use setterm to set pitch and duration)
# max_file_list_length=100 # in characters
# count_only=off # off - display file list; on - display file count
# rawhex_len=5 # length of git rawhex revision id display (use 0 to hide it)
# head_separator=' ' # separator between vcs info and dir info
## head_separator='\n' # put vcs info and dir info on separate lines
# file_list_mode=topdir # show top directory name of added/modified/untracked files
## file_list_mode=fileonly # show file names of added/modifed/untracked files
## file_list_mode=fulldir # show full directory name of added/modified/untracked files
## file_list_mode=fullpath # show full path to files of added/modified/untracked files

############################################################ MODULES

Expand Down
75 changes: 56 additions & 19 deletions git-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
virtualenv_module=${virtualenv_module:-on}
error_bell=${error_bell:-off}
cwd_cmd=${cwd_cmd:-\\w}

head_separator=${head_separator:- }
file_list_mode=${file_list_mode:-topdir}

#### dir, rc, root color
cols=`tput colors` # in emacs shell-mode tput colors returns -1
Expand All @@ -41,9 +42,9 @@
fi
unset cols

#### prompt character, for root/non-root
prompt_char=${prompt_char:-'>'}
root_prompt_char=${root_prompt_char:-'>'}
#### prompt character, for root/non-root
prompt_char=${prompt_char:-'>'}
root_prompt_char=${root_prompt_char:-'>'}

#### vcs colors
init_vcs_color=${init_vcs_color:-WHITE} # initial
Expand Down Expand Up @@ -329,7 +330,7 @@ set_shell_label() {

if [[ -n $id || -n $host ]] ; then
[[ -n $id && -n $host ]] && at='@' || at=''
color_who_where="${id}${host:+$host_color$at$host}${tty:+ $tty}"
color_who_where="${id//\\/\\\\}${host:+$host_color$at$host}${tty:+ $tty}"
plain_who_where="${id}$at$host"

# add trailing " "
Expand Down Expand Up @@ -407,7 +408,19 @@ parse_hg_status() {
fi
}

function longdir_or_filename()
{
local name="${1%${1##*/}}"
[[ "${name:=${1##*/}}" != "/" && name="${name%?}" ]]
echo "$name"
}

function shortdir_or_filename()
{
local name="${1%${1#*/}}"
[[ "${name:=${1##*/}}" != "/" && name="${name%?}" ]]
echo "$name"
}

parse_git_status() {

Expand All @@ -419,17 +432,22 @@ parse_git_status() {

[[ -n ${git_dir/./} ]] || return 1

# Allow per-repo configuration overrides
conf=${git_dir}/.git-prompt.conf;
[[ -r $conf ]] && . $conf
unset conf

vcs=git

########################################################## GIT STATUS
added_files=()
modified_files=()
untracked_files=()
added_files=()
modified_files=()
untracked_files=()
[[ $rawhex_len -gt 0 ]] && freshness="$dim="

unset branch status modified added clean init added mixed untracked op detached

# info not in porcelain status
# info not in porcelain status
eval " $(
git status 2>/dev/null |
sed -n '
Expand All @@ -442,7 +460,7 @@ parse_git_status() {
'
)"

# porcelain file list
# porcelain file list
# TODO: sed-less -- http://tldp.org/LDP/abs/html/arrays.html -- Example 27-5

# git bug: (was reported to [email protected] )
Expand All @@ -453,15 +471,33 @@ parse_git_status() {
# git status --porcelain
# A "with space" <------------- WITH QOUTES

unquoted_match='\([^\"].*\)$'
quoted_match='\"\(.*\)\"$'

case $file_list_mode in
fileonly)
func_match="\$(basename \"\1\")"
;;
fullpath)
func_match="\1"
;;
topdir)
func_match="\$(shortdir_or_filename \"\1\")"
;;
fulldir|*)
func_match="\$(longdir_or_filename \"\1\")"
;;
esac

eval " $(
git status --porcelain 2>/dev/null |
sed -n '
s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p
s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p
s,^.[MAU] \([^\"][^/]*/\?\).*, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p
s,^.[MAU] \"\([^/]\+/\?\).*\"$, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p
s,^?? \([^\"][^/]*/\?\).*, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p
s,^?? \"\([^/]\+/\?\).*\"$, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p
s,^[MARC]. '$quoted_match', added=added; [[ \" ${added_files[@]} \" =~ \" '"$func_match"' \" ]] || added_files[${#added_files[@]}]=\"'"$func_match"'\",p
s,^[MARC]. '$unquoted_match', added=added; [[ \" ${added_files[@]} \" =~ \" '"$func_match"' \" ]] || added_files[${#added_files[@]}]=\"'"$func_match"'\",p
s,^.[MAU] '$quoted_match', modified=modified; [[ \" ${modified_files[@]} \" =~ \" '"$func_match"' \" ]] || modified_files[${#modified_files[@]}]=\"'"$func_match"'\",p
s,^.[MAU] '$unquoted_match', modified=modified; [[ \" ${modified_files[@]} \" =~ \" '"$func_match"' \" ]] || modified_files[${#modified_files[@]}]=\"'"$func_match"'\",p
s,^?? '$quoted_match', untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" '"$func_match"' \" ]] || untracked_files[${#untracked_files[@]}]=\"'"$func_match"'\",p
s,^?? '$unquoted_match', untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" '"$func_match"' \" ]] || untracked_files[${#untracked_files[@]}]=\"'"$func_match"'\",p
' # |tee /dev/tty
)"

Expand Down Expand Up @@ -624,10 +660,10 @@ 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)$head_separator"

### fringes
head_local="${head_local+$vcs_color$head_local }"
head_local="${head_local+$vcs_color$head_local}"
#above_local="${head_local+$vcs_color$head_local\n}"
#tail_local="${tail_local+$vcs_color $tail_local}${dir_color}"
}
Expand Down Expand Up @@ -693,7 +729,7 @@ prompt_command_function() {
cwd=${PWD/$HOME/\~} # substitute "~"
set_shell_label "${cwd##[/~]*/}/" # default label - path last dir

parse_virtualenv_status
parse_virtualenv_status
parse_vcs_status

# autojump
Expand All @@ -704,6 +740,7 @@ prompt_command_function() {
# if cwd_cmd have back-slash, then assign it value to cwd
# else eval cwd_cmd, cwd should have path after exection
eval "${cwd_cmd/\\/cwd=\\\\}"
eval "${head_separator/\\/head_separator=\\\\}"

PS1="$colors_reset$rc$head_local$color_who_where$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset"

Expand Down