Skip to content

Commit

Permalink
Add tests for glab completion (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
chitoku-k authored Oct 3, 2024
1 parent 2a78488 commit 8dde1cd
Show file tree
Hide file tree
Showing 4 changed files with 770 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ git rebase -i **<TAB>
- Commit messaees
- Files
- Remotes
- glab
- Merge Requests
- kubectl
- Annotations/Labels/Field selectors
- Containers/Ports
Expand Down
2 changes: 0 additions & 2 deletions src/completers/gh.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ _fzf_complete_gh() {
return
;;
esac

return
fi

_fzf_path_completion "$prefix" "$@"
Expand Down
38 changes: 26 additions & 12 deletions src/completers/glab.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,51 @@ _fzf_complete_glab() {
return
fi

if [[ $glab_command = mr ]]; then
if [[ $glab_command = co ]]; then
local prefix_option completing_option
local glab_options_argument_required=()
local glab_options_argument_required=(-b --branch -R --repo -u --set-upstream-to)
local glab_options_argument_optional=()

completing_option=$(_fzf_complete_parse_completing_option "$prefix" "$last_argument" "${(F)glab_options_argument_required}" "${(F)glab_options_argument_optional}" || :)

case $completing_option in
-b|--branch|-R|--repo|-u|--set-upstream-to)
return
;;

*)
if [[ $glab_subcommand = (checkout|close|merge|approve|todo|revoke) ]]; then
_fzf_complete_glab-mr '' '' "$@"
return
;;
esac
elif [[ $glab_command = mr ]]; then
local prefix_option completing_option
local glab_options_argument_required=(-R --repo)
local glab_options_argument_optional=()

completing_option=$(_fzf_complete_parse_completing_option "$prefix" "$last_argument" "${(F)glab_options_argument_required}" "${(F)glab_options_argument_optional}" || :)

case $completing_option in
-R|--repo)
return
;;

*)
if [[ $glab_subcommand = (approve|checkout|close|merge|revoke|todo) ]]; then
_fzf_complete_glab-mr '' '' "$@"
fi

if [[ $glab_subcommand = reopen ]]; then
_fzf_complete_glab-mr '' '--closed' "$@"
fi

if [[ $glab_subcommand = (diff|update|view) ]]; then
if [[ $glab_subcommand = (diff|issues|note|update|view) ]]; then
_fzf_complete_glab-mr '' '--all' "$@"
fi

return
;;
esac

return

elif [[ $glab_command = co ]]; then
_fzf_complete_glab-mr '' '' "$@"
return
fi

_fzf_path_completion "$prefix" "$@"
Expand All @@ -62,10 +76,10 @@ _fzf_complete_glab-mr() {

_fzf_complete --ansi --tiebreak=index --header-lines=1 ${(Q)${(Z+n+)fzf_options}} -- "$@" < <({
echo "#\tTITLE\tBRANCH\tSTATE"
glab mr list $mr_state -F json | jq -r '(.[] | [.reference, .title, .source_branch, .state]) | @tsv'
glab mr list $mr_state -F json | jq -r '.[] | [.reference, .title, .source_branch, .state] | @tsv'
} | FS="\t" _fzf_complete_tabularize ${fg[yellow]} $reset_color ${fg[blue]} ${fg[green]})
}

_fzf_complete_glab-mr_post() {
awk '{ print $1 }' | tr -d "!"
awk '{ print $1 }' | tr -d '!'
}
Loading

0 comments on commit 8dde1cd

Please sign in to comment.