From 511a4fa64b1458bc42f9b74d33d660c21ae14bc0 Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Mon, 20 May 2024 08:18:36 -0600 Subject: [PATCH 01/24] style(completions): wrap into a function --- completions/_abbr | 375 +++++++++++++++++++++++----------------------- 1 file changed, 188 insertions(+), 187 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index dddc2b9..81f5100 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -10,197 +10,198 @@ # # ------------------------------------------------------------------------------ +_abbr (){ + local state line -local state line + local -i ret -local -i ret + ret=1 -ret=1 + _arguments -C \ + '1: :->cmds' \ + '*:: :->args' && ret=0 -_arguments -C \ - '1: :->cmds' \ - '*:: :->args' && ret=0 - -case $state in - cmds) - _values "abbr command" \ - "a[Add a new abbreviation.]" \ - "add[Add a new abbreviation.]" \ - "c[Erase all session abbreviations.]" \ - "clear-session[Erase all session abbreviations.]" \ - "e[Erase an abbreviation.]" \ - "erase[Erase an abbreviation.]" \ - "x[Output the ABBREVIATION's EXPANSION.]" \ - "expand[Output the ABBREVIATION's EXPANSION.]" \ - "export-aliases[Export abbreviations as alias commands.]" \ - "g[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]" \ - "git[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]" \ - "help[Show the manpage.]" \ - "--help[Show the manpage.]" \ - "import-aliases[Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session.]" \ - "import-fish[Import fish abbr-syntax abbreviations.]" \ - "import-git-aliases[Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git\[Space\].]" \ - "list[List the abbreviations with their expansions.]" \ - "l[List the abbreviations only.]" \ - "list-abbreviations[List the abbreviations only.]" \ - "list-commands[List as commands suitable for export.]" \ - "profile[Log profile information for debugging.]" \ - "R[Rename an abbreviation.]" \ - "rename[Rename an abbreviation.]" \ - "version[Show the current version.]" \ - "-v[Show the current version.]" \ - "--version[Show the current version.]" - ret=0 - ;; - args) - case $line[1] in - a|\ - add) - # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION - _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in this session]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" - ret=0 - ;; - e|\ - erase) - # [] [] [--dry-run] [--quiet] ABBREVIATION - _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--quiet)--quiet[silence success output]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in this session]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" - ret=0 - ;; - export-aliases|\ - list|\ - l|\ - list-abbreviations|\ - L|\ - list-commands) - # [] [] - _arguments \ - "(--global)--global[expand everywhere]" \ - "(-g)-g[expand everywhere]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in all sessions]" \ - "(--user)--user[available in all sessions]" \ - "(-U)-U[available in all sessions]" + case $state in + cmds) + _values "abbr command" \ + "a[Add a new abbreviation.]" \ + "add[Add a new abbreviation.]" \ + "c[Erase all session abbreviations.]" \ + "clear-session[Erase all session abbreviations.]" \ + "e[Erase an abbreviation.]" \ + "erase[Erase an abbreviation.]" \ + "x[Output the ABBREVIATION's EXPANSION.]" \ + "expand[Output the ABBREVIATION's EXPANSION.]" \ + "export-aliases[Export abbreviations as alias commands.]" \ + "g[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]" \ + "git[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]" \ + "help[Show the manpage.]" \ + "--help[Show the manpage.]" \ + "import-aliases[Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session.]" \ + "import-fish[Import fish abbr-syntax abbreviations.]" \ + "import-git-aliases[Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git\[Space\].]" \ + "list[List the abbreviations with their expansions.]" \ + "l[List the abbreviations only.]" \ + "list-abbreviations[List the abbreviations only.]" \ + "list-commands[List as commands suitable for export.]" \ + "profile[Log profile information for debugging.]" \ + "R[Rename an abbreviation.]" \ + "rename[Rename an abbreviation.]" \ + "version[Show the current version.]" \ + "-v[Show the current version.]" \ + "--version[Show the current version.]" + ret=0 + ;; + args) + case $line[1] in + a|\ + add) + # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION + _arguments \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f)-f[ignore warnings]" \ + "(--force)--force[ignore warnings]" \ + "(-g)-g[expand everywhere]" \ + "(--global)--global[expand everywhere]" \ + "(-q)-q[silence success output]" \ + "(--qq)--qq[silence success output and warnings]" \ + "(--quiet)--quiet[silence success output]" \ + "(--quieter)--quieter[silence success output and warnings]" \ + "(-r)-r[expand at the start of the line]" \ + "(--regular)--regular[expand at the start of the line]" \ + "(-S)-S[available in this session]" \ + "(--session)--session[available in this session]" \ + "(-U)-U[available in all sessions]" \ + "(--user)--user[available in all sessions]" + ret=0 + ;; + e|\ + erase) + # [] [] [--dry-run] [--quiet] ABBREVIATION + _arguments \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-g)-g[expand everywhere]" \ + "(--global)--global[expand everywhere]" \ + "(-q)-q[silence success output]" \ + "(--quiet)--quiet[silence success output]" \ + "(-r)-r[expand at the start of the line]" \ + "(--regular)--regular[expand at the start of the line]" \ + "(-S)-S[available in this session]" \ + "(--session)--session[available in this session]" \ + "(-U)-U[available in all sessions]" \ + "(--user)--user[available in all sessions]" + ret=0 + ;; + export-aliases|\ + list|\ + l|\ + list-abbreviations|\ + L|\ + list-commands) + # [] [] + _arguments \ + "(--global)--global[expand everywhere]" \ + "(-g)-g[expand everywhere]" \ + "(-r)-r[expand at the start of the line]" \ + "(--regular)--regular[expand at the start of the line]" \ + "(-S)-S[available in this session]" \ + "(--session)--session[available in all sessions]" \ + "(--user)--user[available in all sessions]" \ + "(-U)-U[available in all sessions]" + ;; + git) + # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION + _arguments \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f)-f[ignore warnings]" \ + "(--force)--force[ignore warnings]" \ + "(-q)-q[silence success output]" \ + "(--qq)--qq[silence success output and warnings]" \ + "(--quiet)--quiet[silence success output]" \ + "(--quieter)--quieter[silence success output and warnings]" \ + "(-S)-S[available in this session]" \ + "(--session)--session[available in all sessions]" \ + "(-U)-U[available in all sessions]" \ + "(--user)--user[available in all sessions]" + ret=0 + ;; + import-aliases) + # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] + _arguments \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f)-f[ignore warnings]" \ + "(--force)--force[ignore warnings]" \ + "(-g)-g[expand everywhere]" \ + "(--global)--global[expand everywhere]" \ + "(-q)-q[silence success output]" \ + "(--qq)--qq[silence success output and warnings]" \ + "(--quiet)--quiet[silence success output]" \ + "(--quieter)--quieter[silence success output and warnings]" \ + "(-r)-r[expand at the start of the line]" \ + "(--regular)--regular[expand at the start of the line]" + ;; + import-fish) + # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] FILE + _arguments \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f)-f[ignore warnings]" \ + "(--force)--force[ignore warnings]" \ + "(-q)-q[silence success output]" \ + "(--qq)--qq[silence success output and warnings]" \ + "(--quiet)--quiet[silence success output]" \ + "(--quieter)--quieter[silence success output and warnings]" \ + "(-S)-S[available in this session]" \ + "(--session)--session[available in this session]" \ + "(-U)-U[available in all sessions]" \ + "(--user)--user[available in all sessions]" + ret=0 + ;; + import-git-aliases) + # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] [--file ] [--prefix ] + _arguments \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(--file)--file[path to a Git config file]:file:_files -/" \ + "(-f)-f[ignore warnings]" \ + "(--force)--force[ignore warnings]" \ + "(-g)-g[expand everywhere]" \ + "(--global)--global[expand everywhere]" \ + "(-q)-q[silence success output]" \ + "(--prefix)--prefix[prefix added to the ABBREVIATIONs]" \ + "(--qq)--qq[silence success output and warnings]" \ + "(--quiet)--quiet[silence success output]" \ + "(--quieter)--quieter[silence success output and warnings]" \ + "(-r)-r[expand at the start of the line]" \ + "(--regular)--regular[expand at the start of the line]" \ + "(-S)-S[available in this session]" \ + "(--session)--session[available in all sessions]" \ + "(-U)-U[available in all sessions]" \ + "(--user)--user[available in all sessions]" + ret=0 ;; - git) - # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION - _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in all sessions]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" - ret=0 - ;; - import-aliases) - # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] - _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" + R|\ + rename) + # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] OLD NEW + _arguments \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f)-f[ignore warnings]" \ + "(--force)--force[ignore warnings]" \ + "(-g)-g[expand everywhere]" \ + "(--global)--global[expand everywhere]" \ + "(-q)-q[silence success output]" \ + "(--qq)--qq[silence success output and warnings]" \ + "(--quiet)--quiet[silence success output]" \ + "(--quieter)--quieter[silence success output and warnings]" \ + "(-r)-r[expand at the start of the line]" \ + "(--regular)--regular[expand at the start of the line]" \ + "(-S)-S[available in this session]" \ + "(--session)--session[available in this session]" \ + "(-U)-U[available in all sessions]" \ + "(--user)--user[available in all sessions]" + ret=0 ;; - import-fish) - # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] FILE - _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in this session]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" - ret=0 - ;; - import-git-aliases) - # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] [--file ] [--prefix ] - _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(--file)--file[path to a Git config file]:file:_files -/" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--prefix)--prefix[prefix added to the ABBREVIATIONs]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in all sessions]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" - ret=0 - ;; - R|\ - rename) - # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] OLD NEW - _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in this session]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" - ret=0 - ;; - esac - ;; -esac + esac + ;; + esac -return ret + return ret +} From 1e9e3fd48ab4318d5b0448c21f454a8a30d77009 Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Mon, 20 May 2024 08:29:48 -0600 Subject: [PATCH 02/24] style(completions): use double quotes only when necessary --- completions/_abbr | 248 +++++++++++++++++++++++----------------------- 1 file changed, 124 insertions(+), 124 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 81f5100..dc124b8 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -23,33 +23,33 @@ _abbr (){ case $state in cmds) - _values "abbr command" \ - "a[Add a new abbreviation.]" \ - "add[Add a new abbreviation.]" \ - "c[Erase all session abbreviations.]" \ - "clear-session[Erase all session abbreviations.]" \ - "e[Erase an abbreviation.]" \ - "erase[Erase an abbreviation.]" \ + _values 'abbr command' \ + 'a[Add a new abbreviation.]' \ + 'add[Add a new abbreviation.]' \ + 'c[Erase all session abbreviations.]' \ + 'clear-session[Erase all session abbreviations.]' \ + 'e[Erase an abbreviation.]' \ + 'erase[Erase an abbreviation.]' \ "x[Output the ABBREVIATION's EXPANSION.]" \ "expand[Output the ABBREVIATION's EXPANSION.]" \ - "export-aliases[Export abbreviations as alias commands.]" \ - "g[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]" \ - "git[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]" \ - "help[Show the manpage.]" \ - "--help[Show the manpage.]" \ - "import-aliases[Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session.]" \ - "import-fish[Import fish abbr-syntax abbreviations.]" \ - "import-git-aliases[Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git\[Space\].]" \ - "list[List the abbreviations with their expansions.]" \ - "l[List the abbreviations only.]" \ - "list-abbreviations[List the abbreviations only.]" \ - "list-commands[List as commands suitable for export.]" \ - "profile[Log profile information for debugging.]" \ - "R[Rename an abbreviation.]" \ - "rename[Rename an abbreviation.]" \ - "version[Show the current version.]" \ - "-v[Show the current version.]" \ - "--version[Show the current version.]" + 'export-aliases[Export abbreviations as alias commands.]' \ + 'g[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]' \ + 'git[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]' \ + 'help[Show the manpage.]' \ + '--help[Show the manpage.]' \ + 'import-aliases[Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session.]' \ + 'import-fish[Import fish abbr-syntax abbreviations.]' \ + 'import-git-aliases[Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git\[Space\].]' \ + 'list[List the abbreviations with their expansions.]' \ + 'l[List the abbreviations only.]' \ + 'list-abbreviations[List the abbreviations only.]' \ + 'list-commands[List as commands suitable for export.]' \ + 'profile[Log profile information for debugging.]' \ + 'R[Rename an abbreviation.]' \ + 'rename[Rename an abbreviation.]' \ + 'version[Show the current version.]' \ + '-v[Show the current version.]' \ + '--version[Show the current version.]' ret=0 ;; args) @@ -58,38 +58,38 @@ _abbr (){ add) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in this session]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" + '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ + '(-f)-f[ignore warnings]' \ + '(--force)--force[ignore warnings]' \ + '(-g)-g[expand everywhere]' \ + '(--global)--global[expand everywhere]' \ + '(-q)-q[silence success output]' \ + '(--qq)--qq[silence success output and warnings]' \ + '(--quiet)--quiet[silence success output]' \ + '(--quieter)--quieter[silence success output and warnings]' \ + '(-r)-r[expand at the start of the line]' \ + '(--regular)--regular[expand at the start of the line]' \ + '(-S)-S[available in this session]' \ + '(--session)--session[available in this session]' \ + '(-U)-U[available in all sessions]' \ + '(--user)--user[available in all sessions]' ret=0 ;; e|\ erase) # [] [] [--dry-run] [--quiet] ABBREVIATION _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--quiet)--quiet[silence success output]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in this session]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" + '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ + '(-g)-g[expand everywhere]' \ + '(--global)--global[expand everywhere]' \ + '(-q)-q[silence success output]' \ + '(--quiet)--quiet[silence success output]' \ + '(-r)-r[expand at the start of the line]' \ + '(--regular)--regular[expand at the start of the line]' \ + '(-S)-S[available in this session]' \ + '(--session)--session[available in this session]' \ + '(-U)-U[available in all sessions]' \ + '(--user)--user[available in all sessions]' ret=0 ;; export-aliases|\ @@ -100,103 +100,103 @@ _abbr (){ list-commands) # [] [] _arguments \ - "(--global)--global[expand everywhere]" \ - "(-g)-g[expand everywhere]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in all sessions]" \ - "(--user)--user[available in all sessions]" \ - "(-U)-U[available in all sessions]" + '(--global)--global[expand everywhere]' \ + '(-g)-g[expand everywhere]' \ + '(-r)-r[expand at the start of the line]' \ + '(--regular)--regular[expand at the start of the line]' \ + '(-S)-S[available in this session]' \ + '(--session)--session[available in all sessions]' \ + '(--user)--user[available in all sessions]' \ + '(-U)-U[available in all sessions]' ;; git) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in all sessions]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" + '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ + '(-f)-f[ignore warnings]' \ + '(--force)--force[ignore warnings]' \ + '(-q)-q[silence success output]' \ + '(--qq)--qq[silence success output and warnings]' \ + '(--quiet)--quiet[silence success output]' \ + '(--quieter)--quieter[silence success output and warnings]' \ + '(-S)-S[available in this session]' \ + '(--session)--session[available in all sessions]' \ + '(-U)-U[available in all sessions]' \ + '(--user)--user[available in all sessions]' ret=0 ;; import-aliases) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" + '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ + '(-f)-f[ignore warnings]' \ + '(--force)--force[ignore warnings]' \ + '(-g)-g[expand everywhere]' \ + '(--global)--global[expand everywhere]' \ + '(-q)-q[silence success output]' \ + '(--qq)--qq[silence success output and warnings]' \ + '(--quiet)--quiet[silence success output]' \ + '(--quieter)--quieter[silence success output and warnings]' \ + '(-r)-r[expand at the start of the line]' \ + '(--regular)--regular[expand at the start of the line]' ;; import-fish) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] FILE _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in this session]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" + '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ + '(-f)-f[ignore warnings]' \ + '(--force)--force[ignore warnings]' \ + '(-q)-q[silence success output]' \ + '(--qq)--qq[silence success output and warnings]' \ + '(--quiet)--quiet[silence success output]' \ + '(--quieter)--quieter[silence success output and warnings]' \ + '(-S)-S[available in this session]' \ + '(--session)--session[available in this session]' \ + '(-U)-U[available in all sessions]' \ + '(--user)--user[available in all sessions]' ret=0 ;; import-git-aliases) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] [--file ] [--prefix ] _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(--file)--file[path to a Git config file]:file:_files -/" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--prefix)--prefix[prefix added to the ABBREVIATIONs]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in all sessions]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" + '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ + '(--file)--file[path to a Git config file]:file:_files -/' \ + '(-f)-f[ignore warnings]' \ + '(--force)--force[ignore warnings]' \ + '(-g)-g[expand everywhere]' \ + '(--global)--global[expand everywhere]' \ + '(-q)-q[silence success output]' \ + '(--prefix)--prefix[prefix added to the ABBREVIATIONs]' \ + '(--qq)--qq[silence success output and warnings]' \ + '(--quiet)--quiet[silence success output]' \ + '(--quieter)--quieter[silence success output and warnings]' \ + '(-r)-r[expand at the start of the line]' \ + '(--regular)--regular[expand at the start of the line]' \ + '(-S)-S[available in this session]' \ + '(--session)--session[available in all sessions]' \ + '(-U)-U[available in all sessions]' \ + '(--user)--user[available in all sessions]' ret=0 ;; R|\ rename) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] OLD NEW _arguments \ - "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ - "(-f)-f[ignore warnings]" \ - "(--force)--force[ignore warnings]" \ - "(-g)-g[expand everywhere]" \ - "(--global)--global[expand everywhere]" \ - "(-q)-q[silence success output]" \ - "(--qq)--qq[silence success output and warnings]" \ - "(--quiet)--quiet[silence success output]" \ - "(--quieter)--quieter[silence success output and warnings]" \ - "(-r)-r[expand at the start of the line]" \ - "(--regular)--regular[expand at the start of the line]" \ - "(-S)-S[available in this session]" \ - "(--session)--session[available in this session]" \ - "(-U)-U[available in all sessions]" \ - "(--user)--user[available in all sessions]" + '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ + '(-f)-f[ignore warnings]' \ + '(--force)--force[ignore warnings]' \ + '(-g)-g[expand everywhere]' \ + '(--global)--global[expand everywhere]' \ + '(-q)-q[silence success output]' \ + '(--qq)--qq[silence success output and warnings]' \ + '(--quiet)--quiet[silence success output]' \ + '(--quieter)--quieter[silence success output and warnings]' \ + '(-r)-r[expand at the start of the line]' \ + '(--regular)--regular[expand at the start of the line]' \ + '(-S)-S[available in this session]' \ + '(--session)--session[available in this session]' \ + '(-U)-U[available in all sessions]' \ + '(--user)--user[available in all sessions]' ret=0 ;; esac From dadae45d25ef1c0a8003f7d5e0b8ed82b6e8b01b Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Mon, 20 May 2024 08:39:02 -0600 Subject: [PATCH 03/24] style(completions): separate options from commands --- completions/_abbr | 59 ++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index dc124b8..14a1e83 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -18,38 +18,39 @@ _abbr (){ ret=1 _arguments -C \ - '1: :->cmds' \ - '*:: :->args' && ret=0 + '--help[Show the manpage.]' \ + '(-v --version)'{-v,--version}'[Show the current version.]' \ + '1: :->cmds' \ + '*:: :->args' && ret=0 case $state in cmds) - _values 'abbr command' \ - 'a[Add a new abbreviation.]' \ - 'add[Add a new abbreviation.]' \ - 'c[Erase all session abbreviations.]' \ - 'clear-session[Erase all session abbreviations.]' \ - 'e[Erase an abbreviation.]' \ - 'erase[Erase an abbreviation.]' \ - "x[Output the ABBREVIATION's EXPANSION.]" \ - "expand[Output the ABBREVIATION's EXPANSION.]" \ - 'export-aliases[Export abbreviations as alias commands.]' \ - 'g[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]' \ - 'git[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]' \ - 'help[Show the manpage.]' \ - '--help[Show the manpage.]' \ - 'import-aliases[Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session.]' \ - 'import-fish[Import fish abbr-syntax abbreviations.]' \ - 'import-git-aliases[Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git\[Space\].]' \ - 'list[List the abbreviations with their expansions.]' \ - 'l[List the abbreviations only.]' \ - 'list-abbreviations[List the abbreviations only.]' \ - 'list-commands[List as commands suitable for export.]' \ - 'profile[Log profile information for debugging.]' \ - 'R[Rename an abbreviation.]' \ - 'rename[Rename an abbreviation.]' \ - 'version[Show the current version.]' \ - '-v[Show the current version.]' \ - '--version[Show the current version.]' + local commands; commands=( + 'a:Add a new abbreviation.' + 'add:Add a new abbreviation.' + 'c:Erase all session abbreviations.' + 'clear-session:Erase all session abbreviations.' + 'e:Erase an abbreviation.' + 'erase:Erase an abbreviation.' + "x:Output the ABBREVIATION's EXPANSION." + "expand:Output the ABBREVIATION's EXPANSION." + 'export-aliases:Export abbreviations as alias commands.' + 'g:Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.' + 'git:Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.' + 'help:Show the manpage.' + 'import-aliases:Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session.' + 'import-fish:Import fish abbr-syntax abbreviations.' + 'import-git-aliases:Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git[Space].' + 'list:List the abbreviations with their expansions.' + 'l:List the abbreviations only.' + 'list-abbreviations:List the abbreviations only.' + 'list-commands:List as commands suitable for export.' + 'profile:Log profile information for debugging.' + 'R:Rename an abbreviation.' + 'rename:Rename an abbreviation.' + 'version:Show the current version.' + ) + _describe 'abbr commands' commands ret=0 ;; args) From cd0e5cfbd4c8c1dbe78dfd81137fb4383bdad01e Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Mon, 20 May 2024 10:23:44 -0600 Subject: [PATCH 04/24] feat(completions): list abbreviations for erase and rename commands --- completions/_abbr | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 14a1e83..fbe0b79 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -90,7 +90,8 @@ _abbr (){ '(-S)-S[available in this session]' \ '(--session)--session[available in this session]' \ '(-U)-U[available in all sessions]' \ - '(--user)--user[available in all sessions]' + '(--user)--user[available in all sessions]' \ + '1: :__abbr_abbreviations' ret=0 ;; export-aliases|\ @@ -197,7 +198,8 @@ _abbr (){ '(-S)-S[available in this session]' \ '(--session)--session[available in this session]' \ '(-U)-U[available in all sessions]' \ - '(--user)--user[available in all sessions]' + '(--user)--user[available in all sessions]' \ + '1: :__abbr_abbreviations' ret=0 ;; esac @@ -206,3 +208,23 @@ _abbr (){ return ret } + +(( $+functions[__abbr_extract_abbreviations] )) || +__abbr_extract_abbreviations() { + local -a tmp + + tmp=(${${(f)"$(_call_program abbreviations abbr list 2>/dev/null)"}//\"/}) + if (( ${#tmp} > 0 )); then + abbreviations=(${^tmp/=/:}) + else + abbreviations=() + fi +} + +(( $+functions[__abbr_abbreviations] )) || +__abbr_abbreviations() { + local -a abbreviations + __abbr_extract_abbreviations + + _describe -t abbreviations 'abbr abbreviations' abbreviations +} From 2605e60fda8d539c76de0a6e1ac519831456efbb Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Mon, 20 May 2024 10:40:21 -0600 Subject: [PATCH 05/24] fix(completions): show correctly double quotes --- completions/_abbr | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index fbe0b79..1f03d54 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -211,11 +211,16 @@ _abbr (){ (( $+functions[__abbr_extract_abbreviations] )) || __abbr_extract_abbreviations() { - local -a tmp + local -a tmp_abbr tmp_expd - tmp=(${${(f)"$(_call_program abbreviations abbr list 2>/dev/null)"}//\"/}) - if (( ${#tmp} > 0 )); then - abbreviations=(${^tmp/=/:}) + tmp_abbr=(${${(f)"$(_call_program abbreviations abbr list-abbreviations 2>/dev/null)"}//\"/}) + tmp_expd=(${${${${(f)"$(_call_program abbreviations abbr list 2>/dev/null)"}#*=}#\"}%\"}) + + if (( ${#ABBR_REGULAR_USER_ABBREVIATIONS} )); then + local len=${#tmp_abbr} + for (( i = 1; i <= len; i++ )); do + abbreviations+=(${tmp_abbr[$i]}:${tmp_expd[$i]}) + done else abbreviations=() fi From 115ce50e832df299efe63aa1cb7fe1fb657d1460 Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Mon, 20 May 2024 10:47:57 -0600 Subject: [PATCH 06/24] feat(completions): group related options so it won't show them if an option from a group is already chosen --- completions/_abbr | 141 ++++++++++++++++------------------------------ 1 file changed, 49 insertions(+), 92 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 1f03d54..db2ba02 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -59,38 +59,26 @@ _abbr (){ add) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION _arguments \ + '(-S --session -U --user)'{-S,--session}'[available in this session]' \ + '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ + '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ + '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-f)-f[ignore warnings]' \ - '(--force)--force[ignore warnings]' \ - '(-g)-g[expand everywhere]' \ - '(--global)--global[expand everywhere]' \ - '(-q)-q[silence success output]' \ - '(--qq)--qq[silence success output and warnings]' \ - '(--quiet)--quiet[silence success output]' \ - '(--quieter)--quieter[silence success output and warnings]' \ - '(-r)-r[expand at the start of the line]' \ - '(--regular)--regular[expand at the start of the line]' \ - '(-S)-S[available in this session]' \ - '(--session)--session[available in this session]' \ - '(-U)-U[available in all sessions]' \ - '(--user)--user[available in all sessions]' + '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ + '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ + '(-f --force)'{-f,--force}'[ignore warnings]' ret=0 ;; e|\ erase) # [] [] [--dry-run] [--quiet] ABBREVIATION _arguments \ + '(-S --session -U --user)'{-S,--session}'[available in this session]' \ + '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ + '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ + '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-g)-g[expand everywhere]' \ - '(--global)--global[expand everywhere]' \ - '(-q)-q[silence success output]' \ - '(--quiet)--quiet[silence success output]' \ - '(-r)-r[expand at the start of the line]' \ - '(--regular)--regular[expand at the start of the line]' \ - '(-S)-S[available in this session]' \ - '(--session)--session[available in this session]' \ - '(-U)-U[available in all sessions]' \ - '(--user)--user[available in all sessions]' \ + '(-q --quiet)'{-q,--quiet}'[silence success output]' \ '1: :__abbr_abbreviations' ret=0 ;; @@ -102,103 +90,72 @@ _abbr (){ list-commands) # [] [] _arguments \ - '(--global)--global[expand everywhere]' \ - '(-g)-g[expand everywhere]' \ - '(-r)-r[expand at the start of the line]' \ - '(--regular)--regular[expand at the start of the line]' \ - '(-S)-S[available in this session]' \ - '(--session)--session[available in all sessions]' \ - '(--user)--user[available in all sessions]' \ - '(-U)-U[available in all sessions]' + '(-S --session -U --user)'{-S,--session}'[available in this session]' \ + '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ + '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ + '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' + ret=0 ;; git) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION _arguments \ + '(-S --session -U --user)'{-S,--session}'[available in this session]' \ + '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-f)-f[ignore warnings]' \ - '(--force)--force[ignore warnings]' \ - '(-q)-q[silence success output]' \ - '(--qq)--qq[silence success output and warnings]' \ - '(--quiet)--quiet[silence success output]' \ - '(--quieter)--quieter[silence success output and warnings]' \ - '(-S)-S[available in this session]' \ - '(--session)--session[available in all sessions]' \ - '(-U)-U[available in all sessions]' \ - '(--user)--user[available in all sessions]' + '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ + '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ + '(-f --force)'{-f,--force}'[ignore warnings]' ret=0 ;; import-aliases) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] _arguments \ + '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ + '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-f)-f[ignore warnings]' \ - '(--force)--force[ignore warnings]' \ - '(-g)-g[expand everywhere]' \ - '(--global)--global[expand everywhere]' \ - '(-q)-q[silence success output]' \ - '(--qq)--qq[silence success output and warnings]' \ - '(--quiet)--quiet[silence success output]' \ - '(--quieter)--quieter[silence success output and warnings]' \ - '(-r)-r[expand at the start of the line]' \ - '(--regular)--regular[expand at the start of the line]' + '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ + '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ + '(-f --force)'{-f,--force}'[ignore warnings]' + ret=0 ;; import-fish) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] FILE _arguments \ + '(-S --session -U --user)'{-S,--session}'[available in this session]' \ + '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-f)-f[ignore warnings]' \ - '(--force)--force[ignore warnings]' \ - '(-q)-q[silence success output]' \ - '(--qq)--qq[silence success output and warnings]' \ - '(--quiet)--quiet[silence success output]' \ - '(--quieter)--quieter[silence success output and warnings]' \ - '(-S)-S[available in this session]' \ - '(--session)--session[available in this session]' \ - '(-U)-U[available in all sessions]' \ - '(--user)--user[available in all sessions]' + '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ + '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ + '(-f --force)'{-f,--force}'[ignore warnings]' ret=0 ;; import-git-aliases) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] [--file ] [--prefix ] _arguments \ + '(-S --session -U --user)'{-S,--session}'[available in this session]' \ + '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ + '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ + '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(--file)--file[path to a Git config file]:file:_files -/' \ - '(-f)-f[ignore warnings]' \ - '(--force)--force[ignore warnings]' \ - '(-g)-g[expand everywhere]' \ - '(--global)--global[expand everywhere]' \ - '(-q)-q[silence success output]' \ - '(--prefix)--prefix[prefix added to the ABBREVIATIONs]' \ - '(--qq)--qq[silence success output and warnings]' \ - '(--quiet)--quiet[silence success output]' \ - '(--quieter)--quieter[silence success output and warnings]' \ - '(-r)-r[expand at the start of the line]' \ - '(--regular)--regular[expand at the start of the line]' \ - '(-S)-S[available in this session]' \ - '(--session)--session[available in all sessions]' \ - '(-U)-U[available in all sessions]' \ - '(--user)--user[available in all sessions]' + '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ + '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ + '(-f --force)'{-f,--force}'[ignore warnings]' \ + '(--file)--file[path to a Git config file]:filename:_files -/' \ + '(--prefix)--prefix[prefix added to the ABBREVIATIONs]' ret=0 ;; R|\ rename) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] OLD NEW _arguments \ + '(-S --session -U --user)'{-S,--session}'[available in this session]' \ + '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ + '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ + '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-f)-f[ignore warnings]' \ - '(--force)--force[ignore warnings]' \ - '(-g)-g[expand everywhere]' \ - '(--global)--global[expand everywhere]' \ - '(-q)-q[silence success output]' \ - '(--qq)--qq[silence success output and warnings]' \ - '(--quiet)--quiet[silence success output]' \ - '(--quieter)--quieter[silence success output and warnings]' \ - '(-r)-r[expand at the start of the line]' \ - '(--regular)--regular[expand at the start of the line]' \ - '(-S)-S[available in this session]' \ - '(--session)--session[available in this session]' \ - '(-U)-U[available in all sessions]' \ - '(--user)--user[available in all sessions]' \ + '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ + '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ + '(-f --force)'{-f,--force}'[ignore warnings]' \ '1: :__abbr_abbreviations' ret=0 ;; From 5d23c24e06959fd85ff604a7eb980e6c0fcc64f4 Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Mon, 20 May 2024 14:04:51 -0600 Subject: [PATCH 07/24] fix(completions): double was required to invoke completions --- completions/_abbr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/completions/_abbr b/completions/_abbr index db2ba02..640acd5 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -190,3 +190,5 @@ __abbr_abbreviations() { _describe -t abbreviations 'abbr abbreviations' abbreviations } + +_abbr From 110adac74f319a654015a5738ec625fdf58f00f1 Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Mon, 20 May 2024 14:38:40 -0600 Subject: [PATCH 08/24] feat(completions): list abbreviations given scope and type options if any --- completions/_abbr | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 640acd5..6e027b5 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -169,9 +169,20 @@ _abbr (){ (( $+functions[__abbr_extract_abbreviations] )) || __abbr_extract_abbreviations() { local -a tmp_abbr tmp_expd + local scope type - tmp_abbr=(${${(f)"$(_call_program abbreviations abbr list-abbreviations 2>/dev/null)"}//\"/}) - tmp_expd=(${${${${(f)"$(_call_program abbreviations abbr list 2>/dev/null)"}#*=}#\"}%\"}) + if (( $words[(Ie)-U] || $words[(Ie)--user] )); then + scope='-U' + elif (( $words[(Ie)-S] || $words[(I)--session] )); then + scope='-S' + elif (( $words[(Ie)-r] || $words[(Ie)--regular] )); then + type='-r' + elif (( $words[(Ie)-g] || $words[(Ie)--global] )); then + type='-g' + fi + + tmp_abbr=(${${(f)"$(_call_program abbreviations abbr list-abbreviations $scope $type 2>/dev/null)"}//\"/}) + tmp_expd=(${${${${(f)"$(_call_program abbreviations abbr list $scope $type 2>/dev/null)"}#*=}#\"}%\"}) if (( ${#ABBR_REGULAR_USER_ABBREVIATIONS} )); then local len=${#tmp_abbr} From 090ebc362c694b98ceae25db02dfa541e07cdded Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Tue, 21 May 2024 07:44:50 -0600 Subject: [PATCH 09/24] style(completions): use double quotes throughout the file --- completions/_abbr | 174 +++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 6e027b5..335031d 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -18,39 +18,39 @@ _abbr (){ ret=1 _arguments -C \ - '--help[Show the manpage.]' \ - '(-v --version)'{-v,--version}'[Show the current version.]' \ - '1: :->cmds' \ - '*:: :->args' && ret=0 + "--help[Show the manpage.]" \ + "(-v --version)"{-v,--version}"[Show the current version.]" \ + "1: :->cmds" \ + "*:: :->args" && ret=0 case $state in cmds) local commands; commands=( - 'a:Add a new abbreviation.' - 'add:Add a new abbreviation.' - 'c:Erase all session abbreviations.' - 'clear-session:Erase all session abbreviations.' - 'e:Erase an abbreviation.' - 'erase:Erase an abbreviation.' + "a:Add a new abbreviation." + "add:Add a new abbreviation." + "c:Erase all session abbreviations." + "clear-session:Erase all session abbreviations." + "e:Erase an abbreviation." + "erase:Erase an abbreviation." "x:Output the ABBREVIATION's EXPANSION." "expand:Output the ABBREVIATION's EXPANSION." - 'export-aliases:Export abbreviations as alias commands.' - 'g:Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.' - 'git:Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.' - 'help:Show the manpage.' - 'import-aliases:Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session.' - 'import-fish:Import fish abbr-syntax abbreviations.' - 'import-git-aliases:Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git[Space].' - 'list:List the abbreviations with their expansions.' - 'l:List the abbreviations only.' - 'list-abbreviations:List the abbreviations only.' - 'list-commands:List as commands suitable for export.' - 'profile:Log profile information for debugging.' - 'R:Rename an abbreviation.' - 'rename:Rename an abbreviation.' - 'version:Show the current version.' + "export-aliases:Export abbreviations as alias commands." + "g:Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git." + "git:Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git." + "help:Show the manpage." + "import-aliases:Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session." + "import-fish:Import fish abbr-syntax abbreviations." + "import-git-aliases:Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git[Space]." + "list:List the abbreviations with their expansions." + "l:List the abbreviations only." + "list-abbreviations:List the abbreviations only." + "list-commands:List as commands suitable for export." + "profile:Log profile information for debugging." + "R:Rename an abbreviation." + "rename:Rename an abbreviation." + "version:Show the current version." ) - _describe 'abbr commands' commands + _describe "abbr commands" commands ret=0 ;; args) @@ -59,27 +59,27 @@ _abbr (){ add) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION _arguments \ - '(-S --session -U --user)'{-S,--session}'[available in this session]' \ - '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ - '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ - '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ - '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ - '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ - '(-f --force)'{-f,--force}'[ignore warnings]' + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ + "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" ret=0 ;; e|\ erase) # [] [] [--dry-run] [--quiet] ABBREVIATION _arguments \ - '(-S --session -U --user)'{-S,--session}'[available in this session]' \ - '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ - '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ - '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ - '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-q --quiet)'{-q,--quiet}'[silence success output]' \ - '1: :__abbr_abbreviations' + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-q --quiet)"{-q,--quiet}"[silence success output]" \ + "1: :__abbr_abbreviations" ret=0 ;; export-aliases|\ @@ -90,73 +90,73 @@ _abbr (){ list-commands) # [] [] _arguments \ - '(-S --session -U --user)'{-S,--session}'[available in this session]' \ - '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ - '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ - '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" ret=0 ;; git) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION _arguments \ - '(-S --session -U --user)'{-S,--session}'[available in this session]' \ - '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ - '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ - '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ - '(-f --force)'{-f,--force}'[ignore warnings]' + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ + "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" ret=0 ;; import-aliases) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] _arguments \ - '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ - '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ - '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ - '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ - '(-f --force)'{-f,--force}'[ignore warnings]' + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ + "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" ret=0 ;; import-fish) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] FILE _arguments \ - '(-S --session -U --user)'{-S,--session}'[available in this session]' \ - '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ - '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ - '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ - '(-f --force)'{-f,--force}'[ignore warnings]' + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ + "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" ret=0 ;; import-git-aliases) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] [--file ] [--prefix ] _arguments \ - '(-S --session -U --user)'{-S,--session}'[available in this session]' \ - '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ - '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ - '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ - '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ - '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ - '(-f --force)'{-f,--force}'[ignore warnings]' \ - '(--file)--file[path to a Git config file]:filename:_files -/' \ - '(--prefix)--prefix[prefix added to the ABBREVIATIONs]' + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ + "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" \ + "(--file)--file[path to a Git config file]:filename:_files -/" \ + "(--prefix)--prefix[prefix added to the ABBREVIATIONs]" ret=0 ;; R|\ rename) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] OLD NEW _arguments \ - '(-S --session -U --user)'{-S,--session}'[available in this session]' \ - '(-U --user -S --session)'{-U,--user}'[available in all sessions]' \ - '(-r --regular -g --global)'{-r,--regular}'[expand at the start of the line]' \ - '(-g --global -r --regular)'{-g,--global}'[expand everywhere]' \ - '(--dry-run)--dry-run[see what would result, without making any actual changes]' \ - '(-q --quiet -qq --quieter)'{-q,--quiet}'[silence success output]' \ - '(-qq --quieter -q --quiet)'{-qq,--quieter}'[silence success output and warnings]' \ - '(-f --force)'{-f,--force}'[ignore warnings]' \ - '1: :__abbr_abbreviations' + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ + "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ + "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" \ + "1: :__abbr_abbreviations" ret=0 ;; esac @@ -172,13 +172,13 @@ __abbr_extract_abbreviations() { local scope type if (( $words[(Ie)-U] || $words[(Ie)--user] )); then - scope='-U' + scope="-U" elif (( $words[(Ie)-S] || $words[(I)--session] )); then - scope='-S' + scope="-S" elif (( $words[(Ie)-r] || $words[(Ie)--regular] )); then - type='-r' + type="-r" elif (( $words[(Ie)-g] || $words[(Ie)--global] )); then - type='-g' + type="-g" fi tmp_abbr=(${${(f)"$(_call_program abbreviations abbr list-abbreviations $scope $type 2>/dev/null)"}//\"/}) @@ -199,7 +199,7 @@ __abbr_abbreviations() { local -a abbreviations __abbr_extract_abbreviations - _describe -t abbreviations 'abbr abbreviations' abbreviations + _describe -t abbreviations "abbr abbreviations" abbreviations } _abbr From c6c4b015645f228517956daadd429ad40ae32819 Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Tue, 21 May 2024 08:18:08 -0600 Subject: [PATCH 10/24] style(completions): alphabetize options --- completions/_abbr | 66 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 335031d..06b3d80 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -59,26 +59,26 @@ _abbr (){ add) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION _arguments \ - "(-S --session -U --user)"{-S,--session}"[available in this session]" \ - "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ - "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ - "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ - "(-f --force)"{-f,--force}"[ignore warnings]" + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" ret=0 ;; e|\ erase) # [] [] [--dry-run] [--quiet] ABBREVIATION _arguments \ - "(-S --session -U --user)"{-S,--session}"[available in this session]" \ - "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ - "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ - "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(-q --quiet)"{-q,--quiet}"[silence success output]" \ + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ "1: :__abbr_abbreviations" ret=0 ;; @@ -90,72 +90,72 @@ _abbr (){ list-commands) # [] [] _arguments \ - "(-S --session -U --user)"{-S,--session}"[available in this session]" \ - "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ - "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" ret=0 ;; git) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION _arguments \ - "(-S --session -U --user)"{-S,--session}"[available in this session]" \ - "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" \ "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ - "(-f --force)"{-f,--force}"[ignore warnings]" + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" ret=0 ;; import-aliases) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] _arguments \ - "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ - "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ - "(-f --force)"{-f,--force}"[ignore warnings]" + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" ret=0 ;; import-fish) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] FILE _arguments \ - "(-S --session -U --user)"{-S,--session}"[available in this session]" \ - "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" \ "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ - "(-f --force)"{-f,--force}"[ignore warnings]" + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" ret=0 ;; import-git-aliases) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] [--file ] [--prefix ] _arguments \ - "(-S --session -U --user)"{-S,--session}"[available in this session]" \ - "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ - "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ - "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(--file)--file[path to a Git config file]:filename:_files -/" \ + "(-f --force)"{-f,--force}"[ignore warnings]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ + "(--prefix)--prefix[prefix added to the ABBREVIATIONs]" \ "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ - "(-f --force)"{-f,--force}"[ignore warnings]" \ - "(--file)--file[path to a Git config file]:filename:_files -/" \ - "(--prefix)--prefix[prefix added to the ABBREVIATIONs]" + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" ret=0 ;; R|\ rename) # [] [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] OLD NEW _arguments \ - "(-S --session -U --user)"{-S,--session}"[available in this session]" \ - "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ - "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ - "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(--dry-run)--dry-run[see what would result, without making any actual changes]" \ + "(-f --force)"{-f,--force}"[ignore warnings]" \ + "(-g --global -r --regular)"{-g,--global}"[expand everywhere]" \ "(-q --quiet -qq --quieter)"{-q,--quiet}"[silence success output]" \ "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ - "(-f --force)"{-f,--force}"[ignore warnings]" \ + "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ + "(-S --session -U --user)"{-S,--session}"[available in this session]" \ + "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ "1: :__abbr_abbreviations" ret=0 ;; From 77cd21aad851763f0869a8c28831ab7fa7f32e0a Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Tue, 21 May 2024 09:02:57 -0600 Subject: [PATCH 11/24] style(completions): fix indentation --- completions/_abbr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 06b3d80..3718561 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -95,7 +95,7 @@ _abbr (){ "(-S --session -U --user)"{-S,--session}"[available in this session]" \ "(-U --user -S --session)"{-U,--user}"[available in all sessions]" ret=0 - ;; + ;; git) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] ABBREVIATION=EXPANSION _arguments \ @@ -117,7 +117,7 @@ _abbr (){ "(-qq --quieter -q --quiet)"{-qq,--quieter}"[silence success output and warnings]" \ "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" ret=0 - ;; + ;; import-fish) # [] [--dry-run] [(--quiet | --quieter)] [(-f | --force)] FILE _arguments \ From 1164090f08393ef8d04cd735c163ef64ed8e1542 Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Tue, 21 May 2024 14:51:16 -0600 Subject: [PATCH 12/24] revert(completions): use _values intead of _describe for main cmds --- completions/_abbr | 55 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 3718561..c50f7e9 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -18,39 +18,38 @@ _abbr (){ ret=1 _arguments -C \ - "--help[Show the manpage.]" \ - "(-v --version)"{-v,--version}"[Show the current version.]" \ "1: :->cmds" \ "*:: :->args" && ret=0 case $state in cmds) - local commands; commands=( - "a:Add a new abbreviation." - "add:Add a new abbreviation." - "c:Erase all session abbreviations." - "clear-session:Erase all session abbreviations." - "e:Erase an abbreviation." - "erase:Erase an abbreviation." - "x:Output the ABBREVIATION's EXPANSION." - "expand:Output the ABBREVIATION's EXPANSION." - "export-aliases:Export abbreviations as alias commands." - "g:Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git." - "git:Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git." - "help:Show the manpage." - "import-aliases:Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session." - "import-fish:Import fish abbr-syntax abbreviations." - "import-git-aliases:Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git[Space]." - "list:List the abbreviations with their expansions." - "l:List the abbreviations only." - "list-abbreviations:List the abbreviations only." - "list-commands:List as commands suitable for export." - "profile:Log profile information for debugging." - "R:Rename an abbreviation." - "rename:Rename an abbreviation." - "version:Show the current version." - ) - _describe "abbr commands" commands + _values "abbr command" \ + "a[Add a new abbreviation.]" \ + "add[Add a new abbreviation.]" \ + "c[Erase all session abbreviations.]" \ + "clear-session[Erase all session abbreviations.]" \ + "e[Erase an abbreviation.]" \ + "erase[Erase an abbreviation.]" \ + "x[Output the ABBREVIATION's EXPANSION.]" \ + "expand[Output the ABBREVIATION's EXPANSION.]" \ + "export-aliases[Export abbreviations as alias commands.]" \ + "g[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]" \ + "git[Add a regular abbreviation, the expansion of which is prefixed with git; and add a global abbreviation, the abbreviation and expansion of which are prefixed with git.]" \ + "help[Show the manpage.]" \ + "--help[Show the manpage.]" \ + "import-aliases[Add regular abbreviations for every regular alias in the session, and global abbreviations for every global alias in the session.]" \ + "import-fish[Import fish abbr-syntax abbreviations.]" \ + "import-git-aliases[Add regular abbreviations for every Git alias in the current session. The EXPANSION is prefixed with git\[Space\].]" \ + "list[List the abbreviations with their expansions.]" \ + "l[List the abbreviations only.]" \ + "list-abbreviations[List the abbreviations only.]" \ + "list-commands[List as commands suitable for export.]" \ + "profile[Log profile information for debugging.]" \ + "R[Rename an abbreviation.]" \ + "rename[Rename an abbreviation.]" \ + "version[Show the current version.]" \ + "-v[Show the current version.]" \ + "--version[Show the current version.]" ret=0 ;; args) From f7b49a1a37d8eb0f5b4feb8a16ff89e2b317d30b Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Tue, 21 May 2024 15:04:22 -0600 Subject: [PATCH 13/24] refactor(completions): use a single function for completing abbreviations --- completions/_abbr | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index c50f7e9..20def27 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -165,9 +165,9 @@ _abbr (){ return ret } -(( $+functions[__abbr_extract_abbreviations] )) || -__abbr_extract_abbreviations() { - local -a tmp_abbr tmp_expd +(( $+functions[__abbr_abbreviations] )) || # <- This could be removed, it doesn't seems to affect anything, reducing boilerplate +__abbr_abbreviations() { + local -a abbreviations tmp_abbr tmp_expd local scope type if (( $words[(Ie)-U] || $words[(Ie)--user] )); then @@ -191,14 +191,9 @@ __abbr_extract_abbreviations() { else abbreviations=() fi -} - -(( $+functions[__abbr_abbreviations] )) || -__abbr_abbreviations() { - local -a abbreviations - __abbr_extract_abbreviations - _describe -t abbreviations "abbr abbreviations" abbreviations + # I don't think the `-t` option for tags is necessary, and completions works just fine. + _describe "abbr abbreviations" abbreviations } _abbr From 2643344e7f8fa053fe71db623360e117b44fc4c3 Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Mon, 10 Jun 2024 15:05:09 -0600 Subject: [PATCH 14/24] fix(completions): escape colons --- completions/_abbr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/completions/_abbr b/completions/_abbr index 20def27..9c8965e 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -181,7 +181,9 @@ __abbr_abbreviations() { fi tmp_abbr=(${${(f)"$(_call_program abbreviations abbr list-abbreviations $scope $type 2>/dev/null)"}//\"/}) + tmp_abbr=(${tmp_abbr//:/\\:}) tmp_expd=(${${${${(f)"$(_call_program abbreviations abbr list $scope $type 2>/dev/null)"}#*=}#\"}%\"}) + tmp_expd=(${tmp_expd//:/\\:}) if (( ${#ABBR_REGULAR_USER_ABBREVIATIONS} )); then local len=${#tmp_abbr} From 408204c4208757db7ced7cebc772aa8c9742e666 Mon Sep 17 00:00:00 2001 From: Farid NL <34426099+Farid-NL@users.noreply.github.com> Date: Tue, 11 Jun 2024 11:10:01 -0600 Subject: [PATCH 15/24] fix(completions): remove only the initial and final double quotation marks --- completions/_abbr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 9c8965e..4a209f4 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -172,7 +172,7 @@ __abbr_abbreviations() { if (( $words[(Ie)-U] || $words[(Ie)--user] )); then scope="-U" - elif (( $words[(Ie)-S] || $words[(I)--session] )); then + elif (( $words[(Ie)-S] || $words[(Ie)--session] )); then scope="-S" elif (( $words[(Ie)-r] || $words[(Ie)--regular] )); then type="-r" @@ -180,7 +180,7 @@ __abbr_abbreviations() { type="-g" fi - tmp_abbr=(${${(f)"$(_call_program abbreviations abbr list-abbreviations $scope $type 2>/dev/null)"}//\"/}) + tmp_abbr=(${${${(f)"$(_call_program abbreviations abbr list-abbreviations $scope $type 2>/dev/null)"}#\"}%\"}) tmp_abbr=(${tmp_abbr//:/\\:}) tmp_expd=(${${${${(f)"$(_call_program abbreviations abbr list $scope $type 2>/dev/null)"}#*=}#\"}%\"}) tmp_expd=(${tmp_expd//:/\\:}) From 7eab3221f2b2415cfd0fba3d29d7fc056645147b Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Wed, 31 Jul 2024 16:44:09 -1000 Subject: [PATCH 16/24] fix(completions): survives user sourcing zshrc --- completions/_abbr | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 4a209f4..fab456f 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -165,8 +165,7 @@ _abbr (){ return ret } -(( $+functions[__abbr_abbreviations] )) || # <- This could be removed, it doesn't seems to affect anything, reducing boilerplate -__abbr_abbreviations() { +(( $+functions[__abbr_abbreviations] )) || __abbr_abbreviations() { local -a abbreviations tmp_abbr tmp_expd local scope type From d6b89dea369b7087155e03ce5f406a841dec141e Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Wed, 31 Jul 2024 22:16:57 -1000 Subject: [PATCH 17/24] refactor(completions): __abbr_abbreviations dupes _abbr:util_list --- completions/_abbr | 56 ++++++++++++++++++++++++++++++++--------------- zsh-abbr.zsh | 2 ++ 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index fab456f..3336e7a 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -166,35 +166,55 @@ _abbr (){ } (( $+functions[__abbr_abbreviations] )) || __abbr_abbreviations() { - local -a abbreviations tmp_abbr tmp_expd - local scope type + local -a pairs + local abbreviation expansion scope type if (( $words[(Ie)-U] || $words[(Ie)--user] )); then - scope="-U" + scope="user" elif (( $words[(Ie)-S] || $words[(Ie)--session] )); then - scope="-S" + scope="session" elif (( $words[(Ie)-r] || $words[(Ie)--regular] )); then - type="-r" + type="regular" elif (( $words[(Ie)-g] || $words[(Ie)--global] )); then - type="-g" + type="global" fi - tmp_abbr=(${${${(f)"$(_call_program abbreviations abbr list-abbreviations $scope $type 2>/dev/null)"}#\"}%\"}) - tmp_abbr=(${tmp_abbr//:/\\:}) - tmp_expd=(${${${${(f)"$(_call_program abbreviations abbr list $scope $type 2>/dev/null)"}#*=}#\"}%\"}) - tmp_expd=(${tmp_expd//:/\\:}) + # DUPE (nearly) completions/_abbr's __abbr_abbreviations, zsh-abbr.zsh's _abbr:util_list - if (( ${#ABBR_REGULAR_USER_ABBREVIATIONS} )); then - local len=${#tmp_abbr} - for (( i = 1; i <= len; i++ )); do - abbreviations+=(${tmp_abbr[$i]}:${tmp_expd[$i]}) - done - else - abbreviations=() + if [[ $scope != 'session' ]]; then + if [[ $type != 'regular' ]]; then + for abbreviation in ${(iko)ABBR_GLOBAL_USER_ABBREVIATIONS}; do + expansion=${ABBR_GLOBAL_USER_ABBREVIATIONS[$abbreviation]} + pairs+=( ${(Q)abbreviation}:${(Q)expansion} ) + done + fi + + if [[ $type != 'global' ]]; then + for abbreviation in ${(iko)ABBR_REGULAR_USER_ABBREVIATIONS}; do + expansion=${ABBR_REGULAR_USER_ABBREVIATIONS[$abbreviation]} + pairs+=( ${(Q)abbreviation}:${(Q)expansion} ) + done + fi + fi + + if [[ $scope != 'user' ]]; then + if [[ $type != 'regular' ]]; then + for abbreviation in ${(iko)ABBR_GLOBAL_SESSION_ABBREVIATIONS}; do + expansion=${ABBR_GLOBAL_SESSION_ABBREVIATIONS[$abbreviation]} + pairs+=( ${(Q)abbreviation}:${(Q)expansion} ) + done + fi + + if [[ $type != 'global' ]]; then + for abbreviation in ${(iko)ABBR_REGULAR_SESSION_ABBREVIATIONS}; do + expansion=${ABBR_REGULAR_SESSION_ABBREVIATIONS[$abbreviation]} + pairs+=( ${(Q)abbreviation}:${(Q)expansion} ) + done + fi fi # I don't think the `-t` option for tags is necessary, and completions works just fine. - _describe "abbr abbreviations" abbreviations + _describe "abbr abbreviations" pairs } _abbr diff --git a/zsh-abbr.zsh b/zsh-abbr.zsh index 2882528..9759d4e 100755 --- a/zsh-abbr.zsh +++ b/zsh-abbr.zsh @@ -728,6 +728,8 @@ abbr() { session_prefix=$2 user_prefix=$3 + # DUPE (nearly) completions/_abbr's __abbr_abbreviations, zsh-abbr.zsh's _abbr:util_list + if [[ $scope != 'session' ]]; then if [[ $type != 'regular' ]]; then for abbreviation in ${(iko)ABBR_GLOBAL_USER_ABBREVIATIONS}; do From ce877ccf62708fd9d2de544937981565aaeaba0c Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Wed, 31 Jul 2024 22:24:21 -1000 Subject: [PATCH 18/24] refactor(_abbr:util_list, completions' __abbr_abbreviations): tighten --- completions/_abbr | 34 +++++++++++++++------------------- zsh-abbr.zsh | 29 +++++++++++++---------------- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 3336e7a..991a3b4 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -166,9 +166,9 @@ _abbr (){ } (( $+functions[__abbr_abbreviations] )) || __abbr_abbreviations() { - local -a pairs - local abbreviation expansion scope type - + local -a abbreviations_sets pairs + local abbreviations_set abbreviation expansion pair scope type + if (( $words[(Ie)-U] || $words[(Ie)--user] )); then scope="user" elif (( $words[(Ie)-S] || $words[(Ie)--session] )); then @@ -183,36 +183,32 @@ _abbr (){ if [[ $scope != 'session' ]]; then if [[ $type != 'regular' ]]; then - for abbreviation in ${(iko)ABBR_GLOBAL_USER_ABBREVIATIONS}; do - expansion=${ABBR_GLOBAL_USER_ABBREVIATIONS[$abbreviation]} - pairs+=( ${(Q)abbreviation}:${(Q)expansion} ) - done + abbreviations_sets+=( ABBR_GLOBAL_USER_ABBREVIATIONS ) fi if [[ $type != 'global' ]]; then - for abbreviation in ${(iko)ABBR_REGULAR_USER_ABBREVIATIONS}; do - expansion=${ABBR_REGULAR_USER_ABBREVIATIONS[$abbreviation]} - pairs+=( ${(Q)abbreviation}:${(Q)expansion} ) - done + abbreviations_sets+=( ABBR_REGULAR_USER_ABBREVIATIONS ) fi fi if [[ $scope != 'user' ]]; then if [[ $type != 'regular' ]]; then - for abbreviation in ${(iko)ABBR_GLOBAL_SESSION_ABBREVIATIONS}; do - expansion=${ABBR_GLOBAL_SESSION_ABBREVIATIONS[$abbreviation]} - pairs+=( ${(Q)abbreviation}:${(Q)expansion} ) - done + abbreviations_sets+=( ABBR_GLOBAL_SESSION_ABBREVIATIONS ) fi if [[ $type != 'global' ]]; then - for abbreviation in ${(iko)ABBR_REGULAR_SESSION_ABBREVIATIONS}; do - expansion=${ABBR_REGULAR_SESSION_ABBREVIATIONS[$abbreviation]} - pairs+=( ${(Q)abbreviation}:${(Q)expansion} ) - done + abbreviations_sets+=( ABBR_REGULAR_SESSION_ABBREVIATIONS ) fi fi + for abbreviations_set in $abbreviations_sets; do + for abbreviation in ${(iko)${(P)abbreviations_set}}; do + expansion=${${(P)abbreviations_set}[$abbreviation]} + pair=${(Q)abbreviation}:${(Q)expansion} + pairs+=( $pair ) + done + done + # I don't think the `-t` option for tags is necessary, and completions works just fine. _describe "abbr abbreviations" pairs } diff --git a/zsh-abbr.zsh b/zsh-abbr.zsh index 9759d4e..4fb94df 100755 --- a/zsh-abbr.zsh +++ b/zsh-abbr.zsh @@ -719,6 +719,8 @@ abbr() { _abbr_debugger local abbreviation + local abbreviation_set + local -a abbreviations_sets local expansion local -i include_expansion local session_prefix @@ -732,35 +734,30 @@ abbr() { if [[ $scope != 'session' ]]; then if [[ $type != 'regular' ]]; then - for abbreviation in ${(iko)ABBR_GLOBAL_USER_ABBREVIATIONS}; do - (( include_expansion )) && expansion=${ABBR_GLOBAL_USER_ABBREVIATIONS[$abbreviation]} - _abbr:util_list_item $abbreviation $expansion ${user_prefix:+$user_prefix -g} - done + abbreviations_sets+=( ABBR_GLOBAL_USER_ABBREVIATIONS ) fi if [[ $type != 'global' ]]; then - for abbreviation in ${(iko)ABBR_REGULAR_USER_ABBREVIATIONS}; do - (( include_expansion )) && expansion=${ABBR_REGULAR_USER_ABBREVIATIONS[$abbreviation]} - _abbr:util_list_item $abbreviation $expansion $user_prefix - done + abbreviations_sets+=( ABBR_REGULAR_USER_ABBREVIATIONS ) fi fi if [[ $scope != 'user' ]]; then if [[ $type != 'regular' ]]; then - for abbreviation in ${(iko)ABBR_GLOBAL_SESSION_ABBREVIATIONS}; do - (( include_expansion )) && expansion=${ABBR_GLOBAL_SESSION_ABBREVIATIONS[$abbreviation]} - _abbr:util_list_item $abbreviation $expansion ${session_prefix:+$session_prefix -g} - done + abbreviations_sets+=( ABBR_GLOBAL_SESSION_ABBREVIATIONS ) fi if [[ $type != 'global' ]]; then - for abbreviation in ${(iko)ABBR_REGULAR_SESSION_ABBREVIATIONS}; do - (( include_expansion )) && expansion=${ABBR_REGULAR_SESSION_ABBREVIATIONS[$abbreviation]} - _abbr:util_list_item $abbreviation $expansion $session_prefix - done + abbreviations_sets+=( ABBR_REGULAR_SESSION_ABBREVIATIONS ) fi fi + + for abbreviation_set in $abbreviations_sets; do + for abbreviation in ${(iko)${(P)abbreviation_set}}; do + (( include_expansion )) && expansion=${${(P)abbreviation_set}[$abbreviation]} + _abbr:util_list_item $abbreviation $expansion ${user_prefix:+$user_prefix -g} + done + done } _abbr:util_list_item() { From 67459eb349bd086b9f509a403316ceba7c6a9136 Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Wed, 31 Jul 2024 22:29:45 -1000 Subject: [PATCH 19/24] style: one local var per local call --- completions/_abbr | 13 ++++++++++--- zsh-abbr.zsh | 26 ++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 991a3b4..09334d5 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -11,7 +11,8 @@ # ------------------------------------------------------------------------------ _abbr (){ - local state line + local line + local state local -i ret @@ -166,8 +167,14 @@ _abbr (){ } (( $+functions[__abbr_abbreviations] )) || __abbr_abbreviations() { - local -a abbreviations_sets pairs - local abbreviations_set abbreviation expansion pair scope type + local abbreviations_set + local -a abbreviations_sets + local abbreviation + local expansion + local pair + local -a pairs + local scope + local type if (( $words[(Ie)-U] || $words[(Ie)--user] )); then scope="user" diff --git a/zsh-abbr.zsh b/zsh-abbr.zsh index 4fb94df..a762f8a 100755 --- a/zsh-abbr.zsh +++ b/zsh-abbr.zsh @@ -73,9 +73,26 @@ abbr() { _abbr_debugger { - local action error_color job_name logs_silent_when_quiet logs_silent_when_quieter \ - opt output release_date scope success_color type version warn_color - local -i dry_run force has_error number_opts quiet quieter should_exit + local action + local -i dry_run + local error_color + local -i force + local -i has_error + local job_name + local logs_silent_when_quiet + local logs_silent_when_quieter + local -i number_opts + local opt + local output + local release_date + local -i quiet + local -i quieter + local scope + local -i should_exit + local success_color + local type + local version + local warn_color dry_run=$ABBR_DRY_RUN force=$ABBR_FORCE @@ -805,7 +822,8 @@ abbr() { _abbr:util_set_once() { _abbr_debugger - local option value + local option + local value option=$1 value=$2 From f4844956351f4a358ad7f353c6417faed01c078e Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Thu, 1 Aug 2024 09:17:43 -1000 Subject: [PATCH 20/24] refactor(completions): rename fns, vars to match docs + add docs comment --- completions/_abbr | 23 +++++++++++++---------- zsh-abbr.zsh | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/completions/_abbr b/completions/_abbr index 09334d5..165acae 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -79,7 +79,7 @@ _abbr (){ "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ "(-S --session -U --user)"{-S,--session}"[available in this session]" \ "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ - "1: :__abbr_abbreviations" + "1: :__abbr_describe_abbreviations" ret=0 ;; export-aliases|\ @@ -156,7 +156,7 @@ _abbr (){ "(-r --regular -g --global)"{-r,--regular}"[expand at the start of the line]" \ "(-S --session -U --user)"{-S,--session}"[available in this session]" \ "(-U --user -S --session)"{-U,--user}"[available in all sessions]" \ - "1: :__abbr_abbreviations" + "1: :__abbr_describe_abbreviations" ret=0 ;; esac @@ -166,13 +166,13 @@ _abbr (){ return ret } -(( $+functions[__abbr_abbreviations] )) || __abbr_abbreviations() { +(( $+functions[__abbr_describe_abbreviations] )) || __abbr_describe_abbreviations() { local abbreviations_set local -a abbreviations_sets local abbreviation local expansion - local pair - local -a pairs + local completion_and_description + local -a completions_and_descriptions local scope local type @@ -186,7 +186,7 @@ _abbr (){ type="global" fi - # DUPE (nearly) completions/_abbr's __abbr_abbreviations, zsh-abbr.zsh's _abbr:util_list + # DUPE (nearly) completions/_abbr's __abbr_describe_abbreviations, zsh-abbr.zsh's _abbr:util_list if [[ $scope != 'session' ]]; then if [[ $type != 'regular' ]]; then @@ -211,13 +211,16 @@ _abbr (){ for abbreviations_set in $abbreviations_sets; do for abbreviation in ${(iko)${(P)abbreviations_set}}; do expansion=${${(P)abbreviations_set}[$abbreviation]} - pair=${(Q)abbreviation}:${(Q)expansion} - pairs+=( $pair ) + completion_and_description=${(Q)abbreviation}:${(Q)expansion} + completions_and_descriptions+=( $completion_and_description ) done done - # I don't think the `-t` option for tags is necessary, and completions works just fine. - _describe "abbr abbreviations" pairs + # "_describe [-12JVx] [ -oO | -t tag ] descr name1 [ name2 ] [ opt ... ] + # The descr is taken as a string to display above the matches if the format style for the descriptions tag is set. This is followed by one or two names of arrays followed by options to pass to compadd. The array name1 contains the possible completions with their descriptions in the form ‘completion:description’. Any literal colons in completion must be quoted with a backslash. If a name2 is given, it should have the same number of elements as name1; in this case the corresponding elements are added as possible completions instead of the completion strings from name1. The completion list will retain the descriptions from name1. Finally, a set of completion options can appear. + # https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Completion-Functions + # Here, `_describe descr name1` + _describe "abbr completions and descriptions" completions_and_descriptions } _abbr diff --git a/zsh-abbr.zsh b/zsh-abbr.zsh index a762f8a..a6684e6 100755 --- a/zsh-abbr.zsh +++ b/zsh-abbr.zsh @@ -747,7 +747,7 @@ abbr() { session_prefix=$2 user_prefix=$3 - # DUPE (nearly) completions/_abbr's __abbr_abbreviations, zsh-abbr.zsh's _abbr:util_list + # DUPE (nearly) completions/_abbr's __abbr_describe_abbreviations, zsh-abbr.zsh's _abbr:util_list if [[ $scope != 'session' ]]; then if [[ $type != 'regular' ]]; then From afacb69c17b67b8c11ea65af9d9a46fffc6e930e Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Thu, 1 Aug 2024 09:19:37 -1000 Subject: [PATCH 21/24] fix(completions): escape colons in _describe --- completions/_abbr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/_abbr b/completions/_abbr index 165acae..0d86590 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -211,7 +211,7 @@ _abbr (){ for abbreviations_set in $abbreviations_sets; do for abbreviation in ${(iko)${(P)abbreviations_set}}; do expansion=${${(P)abbreviations_set}[$abbreviation]} - completion_and_description=${(Q)abbreviation}:${(Q)expansion} + completion_and_description=${(Q)abbreviation//:/\\:}:${(Q)expansion} completions_and_descriptions+=( $completion_and_description ) done done From c6322a2cb9004e110d2f862d3789936d26b9d36b Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Thu, 1 Aug 2024 09:21:13 -1000 Subject: [PATCH 22/24] fix(completions): scope and type are independent of each other --- completions/_abbr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/completions/_abbr b/completions/_abbr index 0d86590..7bb0183 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -180,7 +180,9 @@ _abbr (){ scope="user" elif (( $words[(Ie)-S] || $words[(Ie)--session] )); then scope="session" - elif (( $words[(Ie)-r] || $words[(Ie)--regular] )); then + fi + + if (( $words[(Ie)-r] || $words[(Ie)--regular] )); then type="regular" elif (( $words[(Ie)-g] || $words[(Ie)--global] )); then type="global" From 7fe7d1d001ff6fe8bdccb47da22f4201bc333aa7 Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Thu, 1 Aug 2024 09:28:54 -1000 Subject: [PATCH 23/24] fix(completions): more reliable handling of colons in abbreviations --- completions/_abbr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/_abbr b/completions/_abbr index 7bb0183..309c1b2 100644 --- a/completions/_abbr +++ b/completions/_abbr @@ -213,7 +213,7 @@ _abbr (){ for abbreviations_set in $abbreviations_sets; do for abbreviation in ${(iko)${(P)abbreviations_set}}; do expansion=${${(P)abbreviations_set}[$abbreviation]} - completion_and_description=${(Q)abbreviation//:/\\:}:${(Q)expansion} + completion_and_description=${${(Q)abbreviation}//:/\\:}:${(Q)expansion} completions_and_descriptions+=( $completion_and_description ) done done From a2624d6a3c35067e8060223b71ca23f9e5ab0425 Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Sat, 26 Oct 2024 11:49:53 -1000 Subject: [PATCH 24/24] docs(roadmap): check off command completion --- ROADMAP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ROADMAP.md b/ROADMAP.md index 510d6ce..cbe2eed 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -27,5 +27,5 @@ _Currently considered feature complete._ ## Maybe maybe? -- [ ] command completion +- [x] command completion - [ ] command highlighting