From febd4043235dc8ca104efdc63b25295ed1e10329 Mon Sep 17 00:00:00 2001 From: Viktor Haag Date: Thu, 1 Dec 2016 13:59:27 -0500 Subject: [PATCH 1/4] fix version logic for major version > 0 --- src/_ag | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/_ag b/src/_ag index 6a41710..0e427dd 100644 --- a/src/_ag +++ b/src/_ag @@ -40,7 +40,7 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------ -_ag_version() { +_ag_minor_version() { local version version=( $($words[1] --version) ) version=${version[@]:2:1} @@ -48,6 +48,15 @@ _ag_version() { echo "${version[2]}" } +_ag_major_version() { + local version + version=( $($words[1] --version) ) + version=${version[@]:2:1} + version=( "${(@s/./)version}" ) + echo "${version[1]}" +} + + # Dynamically build the file type completion # Modifies the global $AG_OPTS array _ag_add_file_types() { @@ -69,9 +78,10 @@ _ag_add_file_types() { # Add version appropriate options above base # Modifies the global $AG_OPTS array _ag_add_version_opts() { - local minor=$(_ag_version) + local minor=$(_ag_minor_version) + local major=$(_ag_major_version) - if [[ $minor -gt 21 ]];then + if [[ $major -ge 1 || $minor -gt 21 ]];then _ag_add_file_types AG_OPTS+=( '(- 1 *)--list-file-types[list supported filetypes to search]' @@ -79,19 +89,19 @@ _ag_add_version_opts() { ) fi - if [[ $minor -gt 22 ]];then + if [[ $major -ge 1 || $minor -gt 22 ]];then AG_OPTS+=( '(-z --search-zip)'{-z,--search-zip}'[search contents of compressed files]' ) fi - if [[ $minor -le 24 ]];then + if [[ $major -lt 1 && $minor -le 24 ]];then AG_OPTS+=( '(-s --case-sensitive)'{-s,--case-sensitive}'[match case sensitively]' '(--noheading --heading)'{--noheading,--heading}'[print file names above matching contents]' ) fi - if [[ $minor -gt 24 ]];then + if [[ $major -ge 1 || $minor -gt 24 ]];then AG_OPTS+=( '(-s --case-sensitive)'{-s,--case-sensitive}'[Match case sensitively. Default on.]' '(-H --noheading --heading)'{-H,--noheading,--heading}'[print file names above matching contents]' @@ -99,18 +109,18 @@ _ag_add_version_opts() { ) fi - if [[ $minor -gt 26 ]];then + if [[ $major -ge 1 || $minor -gt 26 ]];then AG_OPTS+=( '(-0 --null --print0)'{-0,--null,--print0}'[separate the filenames with \\0, rather than \\n]' ) fi - if [[ $minor -le 27 ]];then + if [[ $major -lt 1 && $minor -le 27 ]];then AG_OPTS+=( '--depth[Search up to NUM directories deep. Default is 25.]:number' ) fi - if [[ $minor -gt 27 ]];then + if [[ $major -ge 1 || $minor -gt 27 ]];then AG_OPTS+=( '(-c --count)'{-c,--count}'[only print the number of matches in each file]' '--depth[Search up to NUM directories deep, -1 for unlimited. Default is 25.]:number' @@ -118,12 +128,12 @@ _ag_add_version_opts() { ) fi - if [[ $minor -le 28 ]];then + if [[ $major -lt 1 && $minor -le 28 ]];then AG_OPTS+=( '(--no-numbers)--no-numbers[don´t show line numbers]' ) fi - if [[ $minor -gt 28 ]];then + if [[ $major -ge 1 || $minor -gt 28 ]];then AG_OPTS+=( '(--nofilename --filename)'{--nofilename,--filename}'[Print file names. Default on, except when searching a single file.]' '(--nonumbers --numbers)'{--nonumbers,--numbers}'[Print line numbers. Default is to omit line numbers when searching streams]' From 080d0b70f1f4c86cf1d855830e055271d387f223 Mon Sep 17 00:00:00 2001 From: Viktor Haag Date: Thu, 1 Dec 2016 14:18:35 -0500 Subject: [PATCH 2/4] updated to use ack completion module style version checking -- instead of looking at major and minor, we'll do what the ack completion module does: produce an x.y version number that we then compare directly to, to avoid complicated "if major version OR minor version" checking --- src/_ag | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/_ag b/src/_ag index 0e427dd..3af4b00 100644 --- a/src/_ag +++ b/src/_ag @@ -40,20 +40,12 @@ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------ -_ag_minor_version() { - local version - version=( $($words[1] --version) ) - version=${version[@]:2:1} - version=( "${(@s/./)version}" ) - echo "${version[2]}" -} -_ag_major_version() { +_ag_version() { local version version=( $($words[1] --version) ) - version=${version[@]:2:1} - version=( "${(@s/./)version}" ) - echo "${version[1]}" + version=${${(z)${version[1]}}[2]} + echo $version } @@ -78,30 +70,30 @@ _ag_add_file_types() { # Add version appropriate options above base # Modifies the global $AG_OPTS array _ag_add_version_opts() { - local minor=$(_ag_minor_version) - local major=$(_ag_major_version) + local ag_version=$(_ag_version) - if [[ $major -ge 1 || $minor -gt 21 ]];then + if [[ ag_version > 0.22 ]]; then _ag_add_file_types AG_OPTS+=( '(- 1 *)--list-file-types[list supported filetypes to search]' '--silent[suppress all log messages, including errors]' ) fi + - if [[ $major -ge 1 || $minor -gt 22 ]];then + if [[ ag_version > 0.22 ]]; then AG_OPTS+=( '(-z --search-zip)'{-z,--search-zip}'[search contents of compressed files]' ) fi - if [[ $major -lt 1 && $minor -le 24 ]];then + if [[ ag_version <= 0.24 ]]; then AG_OPTS+=( '(-s --case-sensitive)'{-s,--case-sensitive}'[match case sensitively]' '(--noheading --heading)'{--noheading,--heading}'[print file names above matching contents]' ) fi - if [[ $major -ge 1 || $minor -gt 24 ]];then + if [[ ag_version > 0.24 ]]; then AG_OPTS+=( '(-s --case-sensitive)'{-s,--case-sensitive}'[Match case sensitively. Default on.]' '(-H --noheading --heading)'{-H,--noheading,--heading}'[print file names above matching contents]' @@ -109,18 +101,18 @@ _ag_add_version_opts() { ) fi - if [[ $major -ge 1 || $minor -gt 26 ]];then + if [[ ag_version > 0.26 ]]; then AG_OPTS+=( '(-0 --null --print0)'{-0,--null,--print0}'[separate the filenames with \\0, rather than \\n]' ) fi - if [[ $major -lt 1 && $minor -le 27 ]];then + if [[ ag_version <= 0.27 ]]; then AG_OPTS+=( '--depth[Search up to NUM directories deep. Default is 25.]:number' ) fi - if [[ $major -ge 1 || $minor -gt 27 ]];then + if [[ ag_version > 0.27 ]]; then AG_OPTS+=( '(-c --count)'{-c,--count}'[only print the number of matches in each file]' '--depth[Search up to NUM directories deep, -1 for unlimited. Default is 25.]:number' @@ -128,12 +120,12 @@ _ag_add_version_opts() { ) fi - if [[ $major -lt 1 && $minor -le 28 ]];then + if [[ ag_version <= 0.28 ]]; then AG_OPTS+=( '(--no-numbers)--no-numbers[don´t show line numbers]' ) fi - if [[ $major -ge 1 || $minor -gt 28 ]];then + if [[ ag_version > 0.28 ]]; then AG_OPTS+=( '(--nofilename --filename)'{--nofilename,--filename}'[Print file names. Default on, except when searching a single file.]' '(--nonumbers --numbers)'{--nonumbers,--numbers}'[Print line numbers. Default is to omit line numbers when searching streams]' From c802f5348b1188bd98904bff9e9b30da8e6ff58c Mon Sep 17 00:00:00 2001 From: Viktor Haag Date: Thu, 1 Dec 2016 14:26:58 -0500 Subject: [PATCH 3/4] vars need $ prefixes --- src/_ag | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/_ag b/src/_ag index 3af4b00..78e8f29 100644 --- a/src/_ag +++ b/src/_ag @@ -72,7 +72,7 @@ _ag_add_file_types() { _ag_add_version_opts() { local ag_version=$(_ag_version) - if [[ ag_version > 0.22 ]]; then + if [[ $ag_version > 0.22 ]]; then _ag_add_file_types AG_OPTS+=( '(- 1 *)--list-file-types[list supported filetypes to search]' @@ -81,19 +81,19 @@ _ag_add_version_opts() { fi - if [[ ag_version > 0.22 ]]; then + if [[ $ag_version > 0.22 ]]; then AG_OPTS+=( '(-z --search-zip)'{-z,--search-zip}'[search contents of compressed files]' ) fi - if [[ ag_version <= 0.24 ]]; then + if [[ $ag_version <= 0.24 ]]; then AG_OPTS+=( '(-s --case-sensitive)'{-s,--case-sensitive}'[match case sensitively]' '(--noheading --heading)'{--noheading,--heading}'[print file names above matching contents]' ) fi - if [[ ag_version > 0.24 ]]; then + if [[ $ag_version > 0.24 ]]; then AG_OPTS+=( '(-s --case-sensitive)'{-s,--case-sensitive}'[Match case sensitively. Default on.]' '(-H --noheading --heading)'{-H,--noheading,--heading}'[print file names above matching contents]' @@ -101,18 +101,18 @@ _ag_add_version_opts() { ) fi - if [[ ag_version > 0.26 ]]; then + if [[ $ag_version > 0.26 ]]; then AG_OPTS+=( '(-0 --null --print0)'{-0,--null,--print0}'[separate the filenames with \\0, rather than \\n]' ) fi - if [[ ag_version <= 0.27 ]]; then + if [[ $ag_version <= 0.27 ]]; then AG_OPTS+=( '--depth[Search up to NUM directories deep. Default is 25.]:number' ) fi - if [[ ag_version > 0.27 ]]; then + if [[ $ag_version > 0.27 ]]; then AG_OPTS+=( '(-c --count)'{-c,--count}'[only print the number of matches in each file]' '--depth[Search up to NUM directories deep, -1 for unlimited. Default is 25.]:number' @@ -120,12 +120,12 @@ _ag_add_version_opts() { ) fi - if [[ ag_version <= 0.28 ]]; then + if [[ $ag_version <= 0.28 ]]; then AG_OPTS+=( '(--no-numbers)--no-numbers[don´t show line numbers]' ) fi - if [[ ag_version > 0.28 ]]; then + if [[ $ag_version > 0.28 ]]; then AG_OPTS+=( '(--nofilename --filename)'{--nofilename,--filename}'[Print file names. Default on, except when searching a single file.]' '(--nonumbers --numbers)'{--nonumbers,--numbers}'[Print line numbers. Default is to omit line numbers when searching streams]' From c011691455a84eaaa213b4c863a1d46e5dc582de Mon Sep 17 00:00:00 2001 From: Viktor Haag Date: Thu, 1 Dec 2016 16:03:40 -0500 Subject: [PATCH 4/4] version should check > 21, not > 22 --- src/_ag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_ag b/src/_ag index 78e8f29..aba0715 100644 --- a/src/_ag +++ b/src/_ag @@ -72,7 +72,7 @@ _ag_add_file_types() { _ag_add_version_opts() { local ag_version=$(_ag_version) - if [[ $ag_version > 0.22 ]]; then + if [[ $ag_version > 0.21 ]]; then _ag_add_file_types AG_OPTS+=( '(- 1 *)--list-file-types[list supported filetypes to search]'