Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Who is sorting my completion results?



I'm trying to add reflog completion for git (nevermind what that is if you don't
know :), they look like foo@{1}, foo@{2}, etc. git reflog gives an
already sorted
list of reflog entries, but when I try my completion in the shell, they are re-
sorted as foo@{1}, foo@{10}, foo@{100}, foo@{2}, etc. Who and why is this list
resorted by? (+grammar).

(( $+functions[__git_heads] )) ||
__git_heads () {
  local expl
  declare -a branch_names_with_desc branch_names ref_with_desc ref

  if [[ $PREFIX = *@* ]]; then
    #XXX this gets sorted by sha1 at least from git-checkout which is
obviously bad...
    compset -P '*@'
    ref_with_desc=(${(f)"$(_call_program reflogentries git reflog show
${IPREFIX%@})"})
    __git_command_successful || return

    ref=(${ref_with_desc//(#b)*. (*\}):*/$match[1]})

    unset PREFIX IPREFIX

    _wanted reflog expl reflog-entry compadd $* -ld ref_with_desc - $ref

  else

    branch_names_with_desc=(${${(f)"$(_call_program headrefs git
for-each-ref --format='"%(refname) [%(subject)]"' refs/heads
refs/remotes 2>/dev/null)"}#refs/(heads|remotes)/})
    __git_command_successful || return

    branch_names=(${branch_names_with_desc// *})

    _wanted heads expl branch-name compadd $* -ld
branch_names_with_desc - $branch_names HEAD

  fi
}

-- 
Mikael Magnusson

PS I lied a bit in the description wrt this code, but it gets true if you
remove -ld ref_with_desc, the results are even worse with it since it gets
sorted by the sha1 hash of the commit. DS



Messages sorted by: Reverse Date, Date, Thread, Author