├── .gitignore ├── LICENSE ├── README.md ├── demo.gif ├── gh-user-stars └── libs.sh /.gitignore: -------------------------------------------------------------------------------- 1 | pid 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Futa HIRAKOBA 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gh-user-stars 2 | This is an extension for the [GitHub CLI](https://github.com/cli/cli) extension 3 | that displays an interactive list of [your github stars](https://github.com/stars), 4 | and allows you to filter it with fuzzy search, 5 | powered by [fzf](https://github.com/junegunn/fzf#readme). 6 | The URL of the selected repository is printed as the output of the command. 7 | 8 | ![Demo animation](./demo.gif) 9 | 10 | ## Installation 11 | Besides [gh](https://github.com/cli/cli), 12 | the following commands are required for this extension to work: 13 | - [fzf](https://github.com/junegunn/fzf) 14 | - [jq](https://github.com/stedolan/jq) 15 | 16 | Please follow their installation instructions if you don't have them yet. 17 | 18 | Then, install this extension by running: 19 | ``` 20 | gh extension install korosuke613/gh-user-stars 21 | ``` 22 | 23 | ## Usage 24 | ``` 25 | ❯ gh user-stars -h 26 | 27 | Displays an interactive list of your starred repositories. 28 | The URL of the selected repository is printed as the output of the command. 29 | 30 | Dependencies: fzf, jq 31 | 32 | Usage 33 | gh user-stars [NUMBER] 34 | 35 | NUMBER: Number of stars to fetch at a time. (default: 50, max: 100) 36 | ``` 37 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/korosuke613/gh-user-stars/1829ccdb28159e4924a22e533a5d8b81698dc218/demo.gif -------------------------------------------------------------------------------- /gh-user-stars: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | extensionPath="$(dirname "${0}")" 4 | source "${extensionPath}/libs.sh" 5 | 6 | number=50 7 | 8 | help() { 9 | message=" 10 | Displays an interactive list of your starred repositories. 11 | The URL of the selected repository is printed as the output of the command. 12 | 13 | Dependencies: fzf, jq 14 | 15 | Usage 16 | gh user-stars [NUMBER] 17 | 18 | NUMBER: Number of stars to fetch at a time. (default: ${number}, max: 100) 19 | " 20 | echo "${message}" 21 | } 22 | 23 | choose() { 24 | number=$1 25 | (loop_list_stars "${1}" & echo $! >&3) 3>"${extensionPath}/pid" | fzf --height 90% --layout=reverse 26 | kill $(<"${extensionPath}/pid") 2>/dev/null 27 | } 28 | 29 | while [ $# -gt 0 ]; do 30 | case "$1" in 31 | -h|--help) 32 | help 33 | exit 0 34 | ;; 35 | *) 36 | number=$1 37 | esac 38 | shift 39 | done 40 | 41 | if [[ $number -gt 100 ]]; then 42 | # detail: https://github.com/korosuke613/gh-user-stars/issues/8#issuecomment-910379829 43 | echo "Error: The maximum value of NUMBER is 100." >&2 44 | exit 1 45 | fi 46 | 47 | if ! type -p fzf >/dev/null; then 48 | echo "Error: Install \`fzf\` to use this command." >&2 49 | exit 1 50 | fi 51 | 52 | if ! type -p jq >/dev/null; then 53 | echo "Error: Install \`jq\` to use this command." >&2 54 | exit 1 55 | fi 56 | 57 | selected="$(choose "${number}")" 58 | [ -n "$selected" ] || exit 1 59 | echo "https://github.com/${selected%% *}" 60 | -------------------------------------------------------------------------------- /libs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | list="" 4 | endCursor="" 5 | is_end="true" 6 | 7 | call_star_api(){ 8 | # shellcheck disable=SC2016 9 | gh api graphql -F first="$1" -F endCursor="$2" -f query=' 10 | query($first: Int, $endCursor: String!){ 11 | viewer { 12 | starredRepositories(first: $first, after: $endCursor, orderBy: {field: STARRED_AT, direction: DESC}) { 13 | edges { 14 | node { 15 | nameWithOwner 16 | url 17 | } 18 | starredAt 19 | } 20 | pageInfo { 21 | hasNextPage 22 | endCursor 23 | } 24 | } 25 | } 26 | } 27 | ' 28 | } 29 | 30 | list_stars() { 31 | result=$(call_star_api "$1" "${endCursor}") 32 | list="$(echo $result | jq -r '.data.viewer.starredRepositories.edges[] | [.node.nameWithOwner, (.starredAt|fromdateiso8601|localtime|strflocaltime("%Y-%m-%d %H:%M:%S"))] | @tsv')" 33 | echo "${list}" | column -t -s$'\t' 34 | endCursor=$(echo $result | jq -r '.data.viewer.starredRepositories.pageInfo.endCursor') 35 | is_end=$(echo $result | jq -r '.data.viewer.starredRepositories.pageInfo.hasNextPage') 36 | } 37 | 38 | loop_list_stars(){ 39 | number=$1 40 | while [ "${is_end}" = "true" ] 41 | do 42 | list_stars $number 43 | done 44 | } 45 | --------------------------------------------------------------------------------