cli / oauth

A library for performing OAuth Device flow and Web application flow in Go client apps.
https://pkg.go.dev/github.com/cli/oauth
MIT License
460 stars 63 forks source link

@fingolfin Thats seems like a good idea. Will you make the PR ? #34

Closed danger2520 closed 1 year ago

danger2520 commented 2 years ago

@fingolfin Thats seems like a good idea. Will you make the PR ?


Once you have selected your values for your --json flag and made them pretty with --template, you can then pass your command through fzf for an interactive experience.

Take advantage of the environment variable GH_FORCE_TTY, to enable terminal-style output even when the output is redirected (see gh environment for more details about it).

Example:

Code

# .zshrc gh pr list command extended with fzf, see the man page (man fzf) for an explanation of the arguments.
function ghpr {
    [[ ! "$(git rev-parse --is-inside-work-tree)" ]] && return 1
    GH_COMMAND='gh pr list --state open --json number,author,additions,deletions,updatedAt,title --template "
    {{- tablerow (\"PR\" | color \"blue+b\") (\"LAST UPDATE\" | color \"blue+b\") (\"AUTHOR\" | color \"blue+b\") \"\" \"\" (\"TITLE\" | color \"blue+b\") -}}
    {{- range . -}}
        {{- tablerow (printf \"#%v\" .number | color \"green+h\") (timeago .updatedAt | color \"gray+h\") (.author.login | color \"cyan+h\") (printf \"+%v\" .additions | color \"green\") (printf \"-%v\" .deletions | color \"red\") .title -}}
    {{- end -}}" --search'
    FZF_DEFAULT_COMMAND="$GH_COMMAND ${1:-\"\"}" \
        GH_FORCE_TTY=100% fzf --ansi --disabled --no-multi --header-lines=1 \
        --header $'CTRL+B - Browser | CTRL+D - Toggle Diff  | CTRL+X - Checkout\nCTRL+E - Edit    | CTRL+I - Toggle Info  | CTRL+Y - Comment' \
        --prompt 'Search Open PRs >' --preview-window hidden:wrap \
        --layout=reverse --info=inline --no-multi \
        --bind "change:reload:sleep 0.25; $GH_COMMAND {q} || true" \
        --bind 'ctrl-b:execute-silent(gh pr view {1} --web)' \
        --bind 'ctrl-d:toggle-preview+change-preview(gh pr diff {1} --color always)' \
        --bind 'ctrl-i:toggle-preview+change-preview(gh pr view {1} --comments)' \
        --bind 'ctrl-e:accept+execute(gh pr edit {1})' \
        --bind 'ctrl-x:accept+execute(gh pr checkout {1})' \
        --bind 'ctrl-y:accept+execute(gh pr comment {1})'
}

GIF

In the example I used nano as editor to write the comment, but you can set your own with gh config set editor ....

Originally posted by @LangLangBart in https://github.com/cli/cli/issues/6089#issuecomment-1220250908