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

[(I)-foo] subscripting in _git



I noticed while looking at _git-add that _git does a lot of this type of thing:
if (( words[(I)-n|--dry-run] )); then
that particular example is fine, but further down is this
if [[ -n ${line[(I)-f|--force]} ]]; then
which seems to have two problems, first it uses line instead of words,
so it never matches. Second it uses [[ -n ]] which will always be true
as (I) returns a 0 when it didn't match. There appears to be other
occurences of this pattern in the file, and before I go changing all
of them I wanted to ask if I missed something obvious? It also looks
like _arguments changes $words, as I had to do this to make it work.

@@ -38,6 +38,8 @@
 _git-add () {
   local curcontext=$curcontext state line
   declare -A opt_args
+  local -a owords
+  owords=($words)
@@ -63,7 +65,7 @@ _git-add () {
     (file)
       # TODO: Use __git_ignore_line_inside_arguments.
       declare -a ignored_files_alternatives
-      if [[ -n ${line[(I)-f|--force]} ]]; then
+      if (( ${owords[(I)-f|--force]} )); then
         ignored_files_alternatives=(


-- 
Mikael Magnusson



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