Skip to content

Instantly share code, notes, and snippets.

@hchbaw
Created April 7, 2010 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hchbaw/358895 to your computer and use it in GitHub Desktop.
Save hchbaw/358895 to your computer and use it in GitHub Desktop.
#autoload +X
__git_files () {
local expl files ls_opts opts gitdir gitcdup
zparseopts -D -E -a opts -- -cached -deleted -modified -others -ignored -unmerged -killed
gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
__git_command_successful || return
gitcdup=$(_call_program gitcdup git rev-parse --show-cdup 2>/dev/null)
__git_command_successful || return
ls_opts=("--exclude-per-directory=.gitignore")
[[ -f "$gitdir/info/exclude" ]] && ls_opts+="--exclude-from=$gitdir/info/exclude"
local pathspec="${gitcdup}${PREFIX}"
if [[ $#PREFIX -gt 0 ]]; then
pathspec=${pathspec}*
fi
files=$(_call_program files git ls-files -z --full-name $ls_opts $opts -- $pathspec 2>/dev/null)
__git_command_successful || return
files=(${(ps:\0:)"$(__git_files_relative $files)"})
__git_command_successful || return
local k
if [[ $#PREFIX -gt 0 ]]; then
(( k=${#${(s./.)PREFIX}} + 1 ))
else
k=1
fi
files=(${(uI:${k}:@)files/\/*//})
#_message $opts
_wanted files expl 'index file' _multi_parts $@ - / files
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment