From 5e77b7ddd776cfb2c7b8d1c62d5218dd2f6b2fa6 Mon Sep 17 00:00:00 2001 From: "Ruben S. Garcia" Date: Wed, 28 Sep 2022 17:48:32 +0300 Subject: [PATCH 1/2] feat: Add ZSH completions --- src/zsh-completions/_lr | 179 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 src/zsh-completions/_lr diff --git a/src/zsh-completions/_lr b/src/zsh-completions/_lr new file mode 100644 index 0000000..a73786b --- /dev/null +++ b/src/zsh-completions/_lr @@ -0,0 +1,179 @@ +#compdef lr + +_basic=( + 'help: Display Linear CLI help' + 'init: Setup Linear CLI' +) + +_issues=( + 'issue\:create:Create a new issue' + 'issue\:list:List issues' + 'issue\:search:Search issues' + 'issue\:start:Change status of issue to "In Progress" and assign to yourself.' + 'issue\:stop:Return issue to preview state' + 'issue\:update:Update and issue' +) + +_cache=( + 'cache\:refresh:Refresh the cache' + 'cache\:show:Print the cache file' +) + +_config=( + 'config\:delete:Delete configuration' + 'config\:show:Print the config file' +) + +_teams=( + 'teams\:show:Show teams in this workspace' +) + +_workspace=( + 'workspace\:add:Add a new workspace' + 'workspace\:current:Display current workspace' + 'workspace\:switch:Switch to another workspace' +) + +_basic_commands() { + _describe -t _basic 'Generic commands' _basic && ret=0 + _describe -t _issues 'Issues commands' _issues && ret=0 + _describe -t _cache 'Cache commands' _cache && ret=0 + _describe -t _config 'Config commands' _config && ret=0 + _describe -t _teams 'Teams commands' _teams && ret=0 + _describe -t _workspace 'Workspace commands' _workspace && ret=0 +} + +_statuses() { + local status_list=( + "Backlog" + "Groomed" + "Selected for development" + "In Progress" + "In Review" + "Ready for QA" + "Done" + "Canceled" + "Triage" + ) + _describe -t status_list 'list of status' status_list && ret=0 +} + + +_issue_list_commands() { + local -a context line state state_descr args tmp suf + local -A opt_args + + local _cmp=( + {-a,--all}'[Show issues from all teams]' + {-m,--mine}'[Show issues assigned to me]' + {-s,--status=}'[Show issues with the provided status]:status:_statuses' + {-t,--team=}'[Show issues from a specific team]:team' + {-u,--uncompleted}'[Show only incompleted issues]' + {-x,--extended}'[Show extra columns]' + '--columns=[Show only provided columns (comma separatted)]:columns' + '--csv[Output in CSV format (equivalent to --output=csv)]' + '--filter=[Filter property by partial string matching, ex: name=foo]' + '--no-truncate[Do not truncate output to fit screen]' + '--output=[Ouput in a machine friendly format]:format:(( + json + csv + yaml + ))' + '--sort=[Sort issues (default: -status)]:column' + ) + _arguments -C -s -S $_cmp && ret=0 +} + +_issue_start_commands() { + local _cmp=( + '-c:Copy git branch to clipboard' + '--copy-branch:Copy git branch to clipboard' + ) + _describe -t _cmp 'start options' _cmp && ret=0 +} + +_issue_stop_commands() { + local _cmp=( + '-u:Unassign issue from yourself' + '--unassign:Unassign issue from yourself' + ) + _describe -t _cmp 'stop options' _cmp && ret=0 +} + +_issue_create_commands() { + local _cmp=( + '-c:Copy issue URL to clipboard after creation' + '--copy:Copy issue URL to clipboard after creation' + ) + _describe -t _cmp 'create options' _cmp && ret=0 +} + +_issue_update_commands() { + local _cmp=( + '-p:Property to modify' + '--property:Property to modify:(( + title + description + status + ))' + ) + _describe -t _cmp 'update options' _cmp && ret=0 +} + + +_lr() { + local curcontext=$curcontext ret=1 + local -a context line state state_descr args tmp suf + local -A opt_args + + _arguments \ + '1: :_basic_commands' \ + '*:: :->command_args' + + case $state in + command_args) + case $words[1] in + issue\:list) + _arguments \ + '1: :_issue_list_commands' \ + '*: :_issue_list_commands' + ;; + issue\:start) + _arguments \ + '1:issue id:' \ + '*: :_issue_start_commands' \ + ;; + issue\:stop) + _arguments \ + '1:issue id:' \ + '*: :_issue_stop_commands' \ + ;; + issue\:create) + _arguments \ + '1: :_issue_create_commands' \ + ;; + issue\:update) # Improve this completion + _arguments \ + '1:issue id:' \ + '*: :_issue_update_commands' \ + ;; + help) + _arguments \ + '1:command:_lr' + ;; + *) + _default + ;; + esac + esac +} + +_lr "$@" + +# Consulted links +# https://wikimatze.de/writing-zsh-completion-for-padrino/ +# https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#writing-completion-functions-using-_arguments +# https://web.archive.org/web/20190411104837/http://www.linux-mag.com/id/1106/ +# https://github.com/wikimatze/padrino-zsh-completion +# https://zsh.sourceforge.io/Doc/Release/Completion-Widgets.html#Completion-Widgets +# https://github.com/zsh-users/zsh/blob/master/Etc/completion-style-guide From bc4b26b427fa7a5aec8d0e337781359f12fd8c7e Mon Sep 17 00:00:00 2001 From: "Ruben S. Garcia" Date: Wed, 28 Sep 2022 18:00:07 +0300 Subject: [PATCH 2/2] chore(docs): Add instructions for autocompletions --- README.md | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c902b27..7423b22 100644 --- a/README.md +++ b/README.md @@ -32,22 +32,23 @@ A CLI for [Linear](https://linear.app/) that allows you to quickly view, create # Commands -* [`lr cache:refresh`](#lr-cacherefresh) -* [`lr cache:show`](#lr-cacheshow) -* [`lr config:delete`](#lr-configdelete) -* [`lr config:show`](#lr-configshow) -* [`lr init`](#lr-init) -* [`lr issue ISSUEID`](#lr-issue-issueid) -* [`lr issue:create`](#lr-issuecreate) -* [`lr issue:list`](#lr-issuelist) -* [`lr issue:search [QUERY]`](#lr-issuesearch-query) -* [`lr issue:start ISSUEID`](#lr-issuestart-issueid) -* [`lr issue:stop ISSUEID`](#lr-issuestop-issueid) -* [`lr issue:update ISSUEID`](#lr-issueupdate-issueid) -* [`lr teams:show`](#lr-teamsshow) -* [`lr workspace:add`](#lr-workspaceadd) -* [`lr workspace:current`](#lr-workspacecurrent) -* [`lr workspace:switch`](#lr-workspaceswitch) + +- [`lr cache:refresh`](#lr-cacherefresh) +- [`lr cache:show`](#lr-cacheshow) +- [`lr config:delete`](#lr-configdelete) +- [`lr config:show`](#lr-configshow) +- [`lr init`](#lr-init) +- [`lr issue ISSUEID`](#lr-issue-issueid) +- [`lr issue:create`](#lr-issuecreate) +- [`lr issue:list`](#lr-issuelist) +- [`lr issue:search [QUERY]`](#lr-issuesearch-query) +- [`lr issue:start ISSUEID`](#lr-issuestart-issueid) +- [`lr issue:stop ISSUEID`](#lr-issuestop-issueid) +- [`lr issue:update ISSUEID`](#lr-issueupdate-issueid) +- [`lr teams:show`](#lr-teamsshow) +- [`lr workspace:add`](#lr-workspaceadd) +- [`lr workspace:current`](#lr-workspacecurrent) +- [`lr workspace:switch`](#lr-workspaceswitch) ## `lr cache:refresh` @@ -290,4 +291,20 @@ USAGE ``` _See code: [src/commands/workspace/switch.ts](https://github.com/evangodon/linear-cli/blob/v0.17.0/src/commands/workspace/switch.ts)_ + + +# ZSH completions + +If you want to add completions for the `lr` command and you're using ZSH you can do the following: + +```sh +# 1. Clone this repository +> git clone https://github.com/evangodon/linear-cli +> cd linear-cli + +# 2. On Arch Linux you can do +sudo cp zsh-completions/_lr /usr/share/zsh/site-functions/ + +# 3. Open a new terminal an enjoy the completions :) +```