├── LICENSE ├── README.md └── gh-q /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-q 2 | 3 | [![LICENSE](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE) 4 | 5 | A `gh` extension to clone GitHub repositories using `fzf` and `ghq`. 6 | 7 | ## Requirements 8 | 9 | - [junegunn/fzf](https://github.com/junegunn/fzf) 10 | - [x-motemen/ghq](https://github.com/x-motemen/ghq) 11 | 12 | ## Installation 13 | 14 | ``` 15 | gh extension install kawarimidoll/gh-q 16 | ``` 17 | 18 | ### Upgrading 19 | 20 | ``` 21 | gh extension list 22 | gh extension upgrade kawarimidoll/gh-q 23 | ``` 24 | 25 | ## Usage 26 | 27 | Fuzzy find your repo by `fzf` and clone it by `ghq`: 28 | 29 | ``` 30 | gh q 31 | ``` 32 | 33 | To clone other user's repo, pass username: 34 | 35 | ``` 36 | gh q kawarimidoll 37 | ``` 38 | 39 | ## Prior art 40 | 41 | This extension is strongly inspired by [hashue/gh-fuzzyclone](https://github.com/hashue/gh-fuzzyclone). 42 | -------------------------------------------------------------------------------- /gh-q: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if ! type -p fzf >/dev/null; then 5 | echo "error: install \`fzf\`(https://github.com/junegunn/fzf) to use this command" >&2 6 | exit 1 7 | fi 8 | if ! type -p ghq >/dev/null; then 9 | echo "error: install \`ghq\`(https://github.com/x-motemen/ghq) to use this command" >&2 10 | exit 1 11 | fi 12 | 13 | DEFAULT_USER=$(gh api user -q .login) 14 | 15 | REPO=$(gh api graphql --paginate -F owner="${1:-$DEFAULT_USER}" -f query=' 16 | query ($owner: String!, $endCursor: String) { 17 | repositoryOwner(login: $owner) { 18 | repositories( 19 | first: 30 20 | after: $endCursor 21 | ){ 22 | pageInfo { 23 | hasNextPage 24 | endCursor 25 | } 26 | nodes { 27 | nameWithOwner 28 | } 29 | } 30 | } 31 | } 32 | ' -q '.data.repositoryOwner.repositories.nodes[].nameWithOwner' | fzf) 33 | 34 | if [ $? -ne 0 ];then 35 | exit 1 36 | fi 37 | 38 | ghq get "${REPO}" "${@:2}" 39 | --------------------------------------------------------------------------------