├── LICENSE ├── README.md └── gh-graph /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 カワリミ人形 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-graph 2 | 3 | GitHub contribution graph in your terminal. 4 | 5 | ![screenshot](https://user-images.githubusercontent.com/8146876/131276560-9b97596f-2f21-48ed-a946-498c47d9faf1.png) 6 | 7 | This command calls [kawarimidoll/deno-github-contributions-api](https://github.com/kawarimidoll/deno-github-contributions-api). 8 | 9 | ## Requirements 10 | 11 | - [GitHub cli (gh)](https://github.com/cli/cli) 12 | - [curl](https://github.com/curl/curl) 13 | 14 | ## Installation 15 | 16 | ``` 17 | gh extension install kawarimidoll/gh-graph 18 | ``` 19 | 20 | ### Upgrading 21 | 22 | ``` 23 | gh extension list 24 | gh extension upgrade kawarimidoll/gh-graph 25 | ``` 26 | 27 | ## Usage 28 | 29 | Simply run: 30 | 31 | ``` 32 | gh graph 33 | ``` 34 | 35 | View the help: 36 | 37 | ``` 38 | gh graph --help 39 | ``` 40 | 41 | Have fun: 42 | 43 | ``` 44 | gh graph --pixel %EF%90%88%20 --scheme unicorn 45 | ``` 46 | 47 | ![options-example](https://user-images.githubusercontent.com/8146876/131276566-ea113885-9760-4f75-9b4d-396ac728264c.png) 48 | 49 | 50 | -------------------------------------------------------------------------------- /gh-graph: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | usage() { 4 | cat << EOS >&2 5 | gh graph 6 | GitHub contribution graph in your terminal. 7 | 8 | USAGE: 9 | gh graph [options] [user] 10 | 11 | ARGS: 12 | user GitHub user name. 13 | If this is blank, the current user (login by 'gh auth login') will be used. 14 | 15 | OPTIONS: 16 | -i, --invert Change the background colors instead of the foreground colors. 17 | --no-total Remove the total contributions count. 18 | --no-legend Remove the legend. 19 | -s, --scheme Use the specific color scheme. 20 | The default is 'github'. 21 | -p, --pixel Use the character as pixels (URL encoding is required). 22 | The default is '■' (encoded to '%E2%96%A0'). 23 | -h, --help Show this help message. 24 | 25 | AUTHOR: 26 | kawarimidoll (https://github.com/kawarimidoll) 27 | EOS 28 | } 29 | 30 | invalid() { 31 | usage 32 | echo 33 | echo "$@" 1>&2 34 | exit 1 35 | } 36 | 37 | while (( $# > 0 )) 38 | do 39 | case $1 in 40 | -h | --help) 41 | usage 42 | exit 0 43 | ;; 44 | --no-total) 45 | if [[ -n "$NO_TOTAL" ]]; then 46 | invalid "Duplicated 'no-total' option." 47 | exit 1 48 | fi 49 | NO_TOTAL=1 50 | shift 51 | ;; 52 | --no-legend) 53 | if [[ -n "$NO_LEGEND" ]]; then 54 | invalid "Duplicated 'no-legend' option." 55 | exit 1 56 | fi 57 | NO_LEGEND=1 58 | shift 59 | ;; 60 | -i | --invert) 61 | if [[ -n "$INVERT" ]]; then 62 | invalid "Duplicated 'invert' option." 63 | exit 1 64 | fi 65 | INVERT=1 66 | shift 67 | ;; 68 | -s | --scheme | --scheme=*) 69 | if [[ -n "$SCHEME" ]]; then 70 | invalid "Duplicated 'scheme' option." 71 | exit 1 72 | elif [[ "$1" =~ ^--scheme= ]]; then 73 | SCHEME=$(echo $1 | sed -e 's/^--scheme=//') 74 | shift 75 | elif [[ -z "$2" ]] || [[ "$2" =~ ^-+ ]]; then 76 | invalid "'scheme' option requires an argument." 77 | exit 1 78 | else 79 | SCHEME="$2" 80 | shift 2 81 | fi 82 | ;; 83 | -p | --pixel | --pixel=*) 84 | if [[ -n "$PIXEL" ]]; then 85 | invalid "Duplicated 'pixel' option." 86 | exit 1 87 | elif [[ "$1" =~ ^--pixel= ]]; then 88 | PIXEL=$(echo $1 | sed -e 's/^--pixel=//') 89 | shift 90 | elif [[ -z "$2" ]] || [[ "$2" =~ ^-+ ]]; then 91 | invalid "'pixel' option requires an argument." 92 | exit 1 93 | else 94 | PIXEL="$2" 95 | shift 2 96 | fi 97 | ;; 98 | -*) 99 | invalid "Illegal option -- '$(echo $1 | sed 's/^-*//')'." 100 | exit 1 101 | ;; 102 | *) 103 | if [[ -n "$GH_USER" ]]; then 104 | invalid "Too many arguments." 105 | exit 1 106 | fi 107 | GH_USER="$1" 108 | shift 109 | ;; 110 | esac 111 | done 112 | 113 | OPTS="?gh-graph=true" 114 | if [[ -n "$NO_TOTAL" ]]; then 115 | OPTS="$OPTS&no-total=true" 116 | fi 117 | if [[ -n "$NO_LEGEND" ]]; then 118 | OPTS="$OPTS&no-legend=true" 119 | fi 120 | if [[ -n "$INVERT" ]]; then 121 | OPTS="$OPTS&invert=true" 122 | fi 123 | if [[ -n "$SCHEME" ]]; then 124 | OPTS="$OPTS&scheme=$SCHEME" 125 | fi 126 | if [[ -n "$PIXEL" ]]; then 127 | OPTS="$OPTS&pixel=$PIXEL" 128 | fi 129 | 130 | if [[ -z "$GH_USER" ]]; then 131 | GH_USER=$(gh api user --jq .login) 132 | if [[ $? -ne 0 ]]; then 133 | echo "${GH_USER}" 134 | exit 1 135 | fi 136 | fi 137 | 138 | curl "https://github-contributions-api.deno.dev/${GH_USER}.term${OPTS}" 139 | --------------------------------------------------------------------------------