├── README.md ├── config.yml └── scripts └── generate-aliases.sh /README.md: -------------------------------------------------------------------------------- 1 | 2 | # awesome-gh-aliases 3 | 4 | A curated aliases and api scripts for GitHub's official command line tool [gh](https://github.com/cli/cli). Essentially, a collection of useful combinations of [gh api](https://cli.github.com/manual/gh_api) and [gh alias](https://cli.github.com/manual/gh_alias)! 5 | 6 | **To get started quickly**, you can either [copy the config provided here](#starter-config) or use the script provided [here to generate aliases in your own config](#script-to-generate-the-aliases). 7 | 8 | 9 | ## Table of Contents 10 | 11 | - [Script to generate the aliases](#script-to-generate-the-aliases) 12 | - [Starter config](#starter-config) 13 | - [Usage](#usage) 14 | - [Similar projects](#similar-projects) 15 | 16 | ## Script to generate the aliases 17 | 18 | ```bash 19 | ./scripts/generate-aliases.sh 20 | ``` 21 | 22 | ## Starter config 23 | 24 | ```bash 25 | # backup your existing config 26 | cp $HOME/.config/gh/config.yml{,.bak} 27 | # copy the config from this repo to your gh folder 28 | cp config.yml $HOME/.config/gh/config.yml 29 | ``` 30 | 31 | ## Usage 32 | 33 | - `gh user`: fetch information about the currently authenticated user as JSON 34 | - `gh list-milestones`: list the open milestones for the current repository 35 | - `PR_NUM=1 && gh pr-files-changed $PR_NUM`: lists files changed in pull request `$PR_NUM` for the current repository 36 | - `USER=yashbhutwala && gh list-repos $USER`: list repositories of `$USER` 37 | - `N=10 QUERY=kubernetes && gh search-repos $N $QUERY` : List `$N` repositories and their stars count that match `$QUERY` 38 | 39 | ## Similar projects 40 | 41 | [mislav/hub-api-utils](https://github.com/mislav/hub-api-utils) is an inspiration for this project. 42 | -------------------------------------------------------------------------------- /config.yml: -------------------------------------------------------------------------------- 1 | git_protocol: ssh 2 | aliases: 3 | pv: pr view 4 | bugs: issue list --label="bugs" 5 | epicsBy: issue list --author="$1" --label="epic" 6 | igrep: '!gh issue list --label="$1" | grep -i $2' 7 | user: api user 8 | list-milestones: |- 9 | !gh api --paginate graphql -F owner=':owner' -F name=':repo' -f query=' 10 | query($per_page: Int = 100, $endCursor: String, $owner: String!, $name: String!) { 11 | repository(owner: $owner, name: $name) { 12 | milestones(first: $per_page, after: $endCursor, states: OPEN, orderBy: {field:CREATED_AT, direction:DESC}) { 13 | nodes { 14 | title 15 | number 16 | } 17 | pageInfo { 18 | hasNextPage 19 | endCursor 20 | } 21 | } 22 | } 23 | } 24 | ' | jq -r ".data.repository.milestones.nodes[] | [.number,.title] | @tsv" 25 | pr-files-changed: |- 26 | !gh api --paginate graphql -F owner=':owner' -F name=':repo' -F "pr=$1" -f query=' 27 | query($per_page: Int = 100, $endCursor: String, $pr: Int!, $owner: String!, $name: String!) { 28 | repository(owner: $owner, name: $name) { 29 | pullRequest(number: $pr) { 30 | files(first: $per_page, after: $endCursor) { 31 | edges { 32 | node { 33 | path 34 | } 35 | } 36 | pageInfo { 37 | endCursor 38 | hasNextPage 39 | } 40 | } 41 | } 42 | } 43 | } 44 | ' | jq -r ".data.repository.pullRequest.files.edges[] | [.node.path] | @tsv" 45 | list-repos: |- 46 | !gh api --paginate graphql -F owner="$1" -f query=' 47 | query($owner: String!, $per_page: Int = 100, $endCursor: String) { 48 | repositoryOwner(login: $owner) { 49 | repositories(first: $per_page, after: $endCursor, ownerAffiliations: OWNER) { 50 | nodes { 51 | nameWithOwner 52 | } 53 | pageInfo { 54 | hasNextPage 55 | endCursor 56 | } 57 | } 58 | } 59 | } 60 | ' | jq -r ".data.repositoryOwner.repositories.nodes[] | [.nameWithOwner] | @tsv" 61 | search-repos: |- 62 | !gh api graphql -F per_page="$1" -F q="$2" -f query=' 63 | query($q: String!, $per_page: Int = 10, $endCursor: String) { 64 | search(query: $q, type: REPOSITORY, first: $per_page, after: $endCursor) { 65 | nodes { 66 | ...on Repository { 67 | nameWithOwner 68 | stargazers { 69 | totalCount 70 | } 71 | } 72 | } 73 | pageInfo { 74 | hasNextPage 75 | endCursor 76 | } 77 | } 78 | } 79 | ' | jq -r ".data.search.nodes[] | [.nameWithOwner,.stargazers.totalCount] | @tsv" 80 | -------------------------------------------------------------------------------- /scripts/generate-aliases.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # https://news.ycombinator.com/item?id=10736584 4 | set -o errexit -o nounset -o pipefail 5 | # this line enables debugging 6 | set -xv 7 | 8 | ################################################################################ 9 | # examples from https://cli.github.com/manual/gh_alias_set 10 | gh alias set pv 'pr view' 11 | gh alias set bugs 'issue list --label="bugs"' 12 | gh alias set epicsBy 'issue list --author="$1" --label="epic"' 13 | gh alias set --shell igrep 'gh issue list --label="$1" | grep -i $2' 14 | ################################################################################ 15 | # 16 | ################################################################################ 17 | # custom API 18 | # 19 | # `gh user`: fetch information about the currently authenticated user as JSON 20 | gh alias set 'user' 'api user' 21 | # 22 | # `gh list-milestones`: list the open milestones for the current repository 23 | # NOTE: '"'"' means a single single quote, see: https://stackoverflow.com/a/1250279 24 | gh alias set --shell 'list-milestones' \ 25 | 'gh api --paginate graphql -F owner='"'"':owner'"'"' -F name='"'"':repo'"'"' -f query='"'"' 26 | query($per_page: Int = 100, $endCursor: String, $owner: String!, $name: String!) { 27 | repository(owner: $owner, name: $name) { 28 | milestones(first: $per_page, after: $endCursor, states: OPEN, orderBy: {field:CREATED_AT, direction:DESC}) { 29 | nodes { 30 | title 31 | number 32 | } 33 | pageInfo { 34 | hasNextPage 35 | endCursor 36 | } 37 | } 38 | } 39 | } 40 | '"'"' | jq -r ".data.repository.milestones.nodes[] | [.number,.title] | @tsv"' 41 | # 42 | # `PR_NUM=1 && gh pr-files-changed $PR_NUM`: lists files changed in pull request `$PR_NUM` for the current repository 43 | gh alias set --shell 'pr-files-changed' \ 44 | 'gh api --paginate graphql -F owner='"'"':owner'"'"' -F name='"'"':repo'"'"' -F "pr=$1" -f query='"'"' 45 | query($per_page: Int = 100, $endCursor: String, $pr: Int!, $owner: String!, $name: String!) { 46 | repository(owner: $owner, name: $name) { 47 | pullRequest(number: $pr) { 48 | files(first: $per_page, after: $endCursor) { 49 | edges { 50 | node { 51 | path 52 | } 53 | } 54 | pageInfo { 55 | endCursor 56 | hasNextPage 57 | } 58 | } 59 | } 60 | } 61 | } 62 | '"'"' | jq -r ".data.repository.pullRequest.files.edges[] | [.node.path] | @tsv"' 63 | # 64 | # `USER=yashbhutwala && gh list-repos $USER`: list repositories of `$USER` 65 | gh alias set --shell 'list-repos' \ 66 | 'gh api --paginate graphql -F owner="$1" -f query='"'"' 67 | query($owner: String!, $per_page: Int = 100, $endCursor: String) { 68 | repositoryOwner(login: $owner) { 69 | repositories(first: $per_page, after: $endCursor, ownerAffiliations: OWNER) { 70 | nodes { 71 | nameWithOwner 72 | } 73 | pageInfo { 74 | hasNextPage 75 | endCursor 76 | } 77 | } 78 | } 79 | } 80 | '"'"' | jq -r ".data.repositoryOwner.repositories.nodes[] | [.nameWithOwner] | @tsv"' 81 | ################################################################################ 82 | # 83 | # `N=10 QUERY=kubernetes && gh search-repos $N $QUERY` : List `$N` repositories and their stars count that match `$QUERY` 84 | gh alias set --shell 'search-repos' \ 85 | 'gh api graphql -F per_page="$1" -F q="$2" -f query='"'"' 86 | query($q: String!, $per_page: Int = 10, $endCursor: String) { 87 | search(query: $q, type: REPOSITORY, first: $per_page, after: $endCursor) { 88 | nodes { 89 | ...on Repository { 90 | nameWithOwner 91 | stargazers { 92 | totalCount 93 | } 94 | } 95 | } 96 | pageInfo { 97 | hasNextPage 98 | endCursor 99 | } 100 | } 101 | } 102 | '"'"' | jq -r ".data.search.nodes[] | [.nameWithOwner,.stargazers.totalCount] | @tsv"' 103 | --------------------------------------------------------------------------------