|
| 1 | +#compdef lr |
| 2 | + |
| 3 | +_basic=( |
| 4 | + 'help: Display Linear CLI help' |
| 5 | + 'init: Setup Linear CLI' |
| 6 | +) |
| 7 | + |
| 8 | +_issues=( |
| 9 | + 'issue\:create:Create a new issue' |
| 10 | + 'issue\:list:List issues' |
| 11 | + 'issue\:search:Search issues' |
| 12 | + 'issue\:start:Change status of issue to "In Progress" and assign to yourself.' |
| 13 | + 'issue\:stop:Return issue to preview state' |
| 14 | + 'issue\:update:Update and issue' |
| 15 | +) |
| 16 | + |
| 17 | +_cache=( |
| 18 | + 'cache\:refresh:Refresh the cache' |
| 19 | + 'cache\:show:Print the cache file' |
| 20 | +) |
| 21 | + |
| 22 | +_config=( |
| 23 | + 'config\:delete:Delete configuration' |
| 24 | + 'config\:show:Print the config file' |
| 25 | +) |
| 26 | + |
| 27 | +_teams=( |
| 28 | + 'teams\:show:Show teams in this workspace' |
| 29 | +) |
| 30 | + |
| 31 | +_workspace=( |
| 32 | + 'workspace\:add:Add a new workspace' |
| 33 | + 'workspace\:current:Display current workspace' |
| 34 | + 'workspace\:switch:Switch to another workspace' |
| 35 | +) |
| 36 | + |
| 37 | +_basic_commands() { |
| 38 | + _describe -t _basic 'Generic commands' _basic && ret=0 |
| 39 | + _describe -t _issues 'Issues commands' _issues && ret=0 |
| 40 | + _describe -t _cache 'Cache commands' _cache && ret=0 |
| 41 | + _describe -t _config 'Config commands' _config && ret=0 |
| 42 | + _describe -t _teams 'Teams commands' _teams && ret=0 |
| 43 | + _describe -t _workspace 'Workspace commands' _workspace && ret=0 |
| 44 | +} |
| 45 | + |
| 46 | +_statuses() { |
| 47 | + local status_list=( |
| 48 | + "Backlog" |
| 49 | + "Groomed" |
| 50 | + "Selected for development" |
| 51 | + "In Progress" |
| 52 | + "In Review" |
| 53 | + "Ready for QA" |
| 54 | + "Done" |
| 55 | + "Canceled" |
| 56 | + "Triage" |
| 57 | + ) |
| 58 | + _describe -t status_list 'list of status' status_list && ret=0 |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +_issue_list_commands() { |
| 63 | + local -a context line state state_descr args tmp suf |
| 64 | + local -A opt_args |
| 65 | + |
| 66 | + local _cmp=( |
| 67 | + {-a,--all}'[Show issues from all teams]' |
| 68 | + {-m,--mine}'[Show issues assigned to me]' |
| 69 | + {-s,--status=}'[Show issues with the provided status]:status:_statuses' |
| 70 | + {-t,--team=}'[Show issues from a specific team]:team' |
| 71 | + {-u,--uncompleted}'[Show only incompleted issues]' |
| 72 | + {-x,--extended}'[Show extra columns]' |
| 73 | + '--columns=[Show only provided columns (comma separatted)]:columns' |
| 74 | + '--csv[Output in CSV format (equivalent to --output=csv)]' |
| 75 | + '--filter=[Filter property by partial string matching, ex: name=foo]' |
| 76 | + '--no-truncate[Do not truncate output to fit screen]' |
| 77 | + '--output=[Ouput in a machine friendly format]:format:(( |
| 78 | + json |
| 79 | + csv |
| 80 | + yaml |
| 81 | + ))' |
| 82 | + '--sort=[Sort issues (default: -status)]:column' |
| 83 | + ) |
| 84 | + _arguments -C -s -S $_cmp && ret=0 |
| 85 | +} |
| 86 | + |
| 87 | +_issue_start_commands() { |
| 88 | + local _cmp=( |
| 89 | + '-c:Copy git branch to clipboard' |
| 90 | + '--copy-branch:Copy git branch to clipboard' |
| 91 | + ) |
| 92 | + _describe -t _cmp 'start options' _cmp && ret=0 |
| 93 | +} |
| 94 | + |
| 95 | +_issue_stop_commands() { |
| 96 | + local _cmp=( |
| 97 | + '-u:Unassign issue from yourself' |
| 98 | + '--unassign:Unassign issue from yourself' |
| 99 | + ) |
| 100 | + _describe -t _cmp 'stop options' _cmp && ret=0 |
| 101 | +} |
| 102 | + |
| 103 | +_issue_create_commands() { |
| 104 | + local _cmp=( |
| 105 | + '-c:Copy issue URL to clipboard after creation' |
| 106 | + '--copy:Copy issue URL to clipboard after creation' |
| 107 | + ) |
| 108 | + _describe -t _cmp 'create options' _cmp && ret=0 |
| 109 | +} |
| 110 | + |
| 111 | +_issue_update_commands() { |
| 112 | + local _cmp=( |
| 113 | + '-p:Property to modify' |
| 114 | + '--property:Property to modify:(( |
| 115 | + title |
| 116 | + description |
| 117 | + status |
| 118 | + ))' |
| 119 | + ) |
| 120 | + _describe -t _cmp 'update options' _cmp && ret=0 |
| 121 | +} |
| 122 | + |
| 123 | + |
| 124 | +_lr() { |
| 125 | + local curcontext=$curcontext ret=1 |
| 126 | + local -a context line state state_descr args tmp suf |
| 127 | + local -A opt_args |
| 128 | + |
| 129 | + _arguments \ |
| 130 | + '1: :_basic_commands' \ |
| 131 | + '*:: :->command_args' |
| 132 | + |
| 133 | + case $state in |
| 134 | + command_args) |
| 135 | + case $words[1] in |
| 136 | + issue\:list) |
| 137 | + _arguments \ |
| 138 | + '1: :_issue_list_commands' \ |
| 139 | + '*: :_issue_list_commands' |
| 140 | + ;; |
| 141 | + issue\:start) |
| 142 | + _arguments \ |
| 143 | + '1:issue id:' \ |
| 144 | + '*: :_issue_start_commands' \ |
| 145 | + ;; |
| 146 | + issue\:stop) |
| 147 | + _arguments \ |
| 148 | + '1:issue id:' \ |
| 149 | + '*: :_issue_stop_commands' \ |
| 150 | + ;; |
| 151 | + issue\:create) |
| 152 | + _arguments \ |
| 153 | + '1: :_issue_create_commands' \ |
| 154 | + ;; |
| 155 | + issue\:update) # Improve this completion |
| 156 | + _arguments \ |
| 157 | + '1:issue id:' \ |
| 158 | + '*: :_issue_update_commands' \ |
| 159 | + ;; |
| 160 | + help) |
| 161 | + _arguments \ |
| 162 | + '1:command:_lr' |
| 163 | + ;; |
| 164 | + *) |
| 165 | + _default |
| 166 | + ;; |
| 167 | + esac |
| 168 | + esac |
| 169 | +} |
| 170 | + |
| 171 | +_lr "$@" |
| 172 | + |
| 173 | +# Consulted links |
| 174 | +# https://wikimatze.de/writing-zsh-completion-for-padrino/ |
| 175 | +# https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#writing-completion-functions-using-_arguments |
| 176 | +# https://web.archive.org/web/20190411104837/http://www.linux-mag.com/id/1106/ |
| 177 | +# https://github.com/wikimatze/padrino-zsh-completion |
| 178 | +# https://zsh.sourceforge.io/Doc/Release/Completion-Widgets.html#Completion-Widgets |
| 179 | +# https://github.com/zsh-users/zsh/blob/master/Etc/completion-style-guide |
0 commit comments