├── .gitignore ├── LICENSE ├── README.md └── gh-repo-fzf /.gitignore: -------------------------------------------------------------------------------- 1 | .repos.txt 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Kavin Valli 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-repo-fzf 2 | 3 | A `gh` cli to fuzzy search your repositories and do an action with them 4 | ![gh-repo-fzf](https://user-images.githubusercontent.com/41034356/144628703-caaf0921-8d1a-4913-b5a0-24b5f7269549.gif) 5 | 6 | ## Requirements 7 | 8 | 1. `gh cli` - minimum version (2.0.0) 9 | 10 | 2. `fzf` 11 | 12 | ## Installation 13 | 14 | ```sh 15 | gh extension install kavinvalli/gh-repo-fzf 16 | ``` 17 | 18 | ### Installing Manually 19 | 20 | > To install this extension **manually**, follow these steps: 21 | 22 | 1. Clone repo 23 | 24 | ```bash 25 | # git 26 | git clone https://github.com/kavinvalli/gh-repo-fzf 27 | 28 | # github cli 29 | gh repo clone kavinvalli/gh-fzf 30 | ``` 31 | 32 | 2. cd into it 33 | 34 | ```bash 35 | cd gh-repo-fzf 36 | ``` 37 | 38 | 3. Install it locally 39 | ```bash 40 | gh extension install . 41 | ``` 42 | 43 | ## Available actions 44 | - Clone 45 | - View 46 | - Fork 47 | - Archive 48 | 49 | ## Usage 50 | 51 | - To list all directories you have access to, run: 52 | 53 | ```sh 54 | gh repo-fzf 55 | ``` 56 | 57 | - To list directories of a particular user / organisation: 58 | 59 | ```sh 60 | gh repo-fzf 61 | ``` 62 | -------------------------------------------------------------------------------- /gh-repo-fzf: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | spin[0]="-" 5 | spin[1]="\\" 6 | spin[2]="|" 7 | spin[3]="/" 8 | 9 | user=$(gh api user -q .login) 10 | 11 | QUERY=' 12 | query($owner: String!, $endCursor: String) { 13 | repositoryOwner(login: $owner) { 14 | repositories(first: 100, after: $endCursor) { 15 | nodes { nameWithOwner } 16 | pageInfo { 17 | hasNextPage 18 | endCursor 19 | } 20 | } 21 | } 22 | } 23 | ' 24 | 25 | gh api graphql --paginate -F owner="${1:-$user}" -f query="${QUERY}" --jq '.data.repositoryOwner.repositories.nodes.[].nameWithOwner' > .repos.txt & PID=$! 26 | 27 | echo "This may take a while. Please be patient while it runs" 28 | printf "[" 29 | while kill -0 $PID 2>/dev/null; do 30 | # for i in "${spin[@]}"; do 31 | # echo -ne "\b$i" 32 | printf "▓" 33 | sleep 0.5 34 | # done 35 | done 36 | printf "] done!\n" 37 | 38 | repo=$(cat .repos.txt | fzf) 39 | if [ -z $repo ]; then 40 | echo "Please choose a repository" 41 | exit 1 42 | fi 43 | 44 | option=$(echo "clone view fork archive" | tr " " "\n" | fzf) 45 | if [ -z $option ]; then 46 | echo "Please choose an option" 47 | exit 1 48 | fi 49 | 50 | if [ $option = "clone" ]; then 51 | gh repo clone $repo 52 | elif [ $option = "view" ]; then 53 | gh repo view $repo --web 54 | elif [ $option = "fork" ]; then 55 | gh repo fork $repo 56 | elif [ $option = "archive" ]; then 57 | gh repo archive $repo 58 | fi 59 | --------------------------------------------------------------------------------