Skip to content

toozej/git-peak-extended

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git-peak-extended

Overview

git-peak-extended uses the same basic idea as git-peak but takes it a few steps further:

  1. Supports saving git repos either to temporary storage (like git-peak), but alternatively, to permanent storage for future use.
  2. Supports the most common public git providers: GitHub, GitLab, sourcehut, and BitBucket.
  3. Supports HTTPS, Git, and short-hand formatted repo URLs to clone
  4. Supports checking out a user-specified branch, or the repo's default branch
  5. Supports appending repo to myrepos ("mr") config

Like git-peak, git-peak-extended is written in Bash for portability, ease of use, and extendability.

In essence git-peak-extended chains together common tools like sed, git, ssh, and mktemp to allow users to quickly view git repos or permanently save them to disk in a configurable location for future use.

Inspirations

git-peak-extended is inspired by similar repos posted in Hacker News 1 2 3 4 recently:

  1. github1s by cownet
  2. git-peek by Jarred Sumner
  3. git-peak by Alex David
  4. repo-peek by Rahul Nair

Specifically it is an extended version of #3 above, git-peak.

Why git-peak-extended?

With so many similar repos as noted above in the inspirations section, why did I decide to write git-peak-extended? A few reasons really:

  1. I often find myself wanting to be able to quickly store git repos from a terminal without having to faff around copy/pasting git clone-style links.
  2. I wanted to be able to view repos using one $EDITOR VSCode while storing repos permanently and opening them with another $EDITOR vim.
    • I find the GUI-centric nature of VSCode easier for quick perusing and determining what a repo is and does than my main editing-focused usage of vim
  3. More practice writing Bash scripts
  4. More specifically testing Bash scripts with GitHub Actions

Usage

  1. Install pre-requisites

    • bash
    • git
    • jq
    • curl
    • coreutils (for the mktemp binary)
    • myrepos (if you want to append a repo to your mr config)
    • If you're using an apt-based distribution, you can typically install these with:
      sudo apt-get install -y bash git jq curl coreutils myrepos
    • If you're using a dnf-based distribution, you can typically install these with:
      sudo dnf install -y bash git jq curl coreutils myrepos
    • If you're using MacOS, you can typically install these with homebrew:
      brew install bash git jq curl mr
      
  2. Download git-peak-extended:

    • Using cURL: curl -sLo ./git-peak-extended https://raw.githubusercontent.com/toozej/git-peak-extended/main/git-peak-extended && chmod u+x ./git-peak-extended
    • Using Wget: wget -q -O ./git-peak-extended https://raw.githubusercontent.com/toozej/git-peak-extended/main/git-peak-extended && chmod u+x ./git-peak-extended
    • Using git: git clone [email protected]:toozej/git-peak-extended.git
    • Using git-peak-extended (meta!): git-peak-extended toozej/git-peak-extended
  3. Find a repo to you want to "peek", and get the GIT_REPO_URL in any one of these supported formats:

    • https://$git_provider/$username/$repo.git
    • git@$git_provider:$username/$repo.git
    • $username/$repo
      • git-peak-extended will first search GitHub, then GitLab, then soucehut and finally BitBucket. If repo not found, git-peak-extended will print an error message and exit
  4. Temporarily clone and view a git repo: ./git-peak-extended GIT_REPO_URL

    • For more explicit usage (like in aliases), you can alternatively use ./git-peak-extended --temp GIT_REPO_URL or the -t flag to mean the same thing
  5. Permanently clone and view a git repo: ./git-peak-extended --save GIT_REPO_URL

    • Alternatively, the -s short-hand flag, --permanent or -p short-hand flags do the same thing
  6. Optional arguments affecting both "temporary" and "permanent" modes are as follows:

    • ./git-peak-extended <arguments> GIT_REPO_URL
    • If you want to specify a non-default directory to store, you can use --dir </path/to/dir>
    • If you want to change the default editor used to open the git repo using either of these methods:
      • Temporarily set the editor for this one-time usage of git-peak-extended: EDITOR=<some_different_editor> ./git-peak-extended <arguments> GIT_REPO_URL
      • Permanently set the editor by editing your shell's configuration file, adding or adjusting a line like this: export EDITOR='<some_different_editor>'
    • If you want to specify a non-default git branch to checkout, you can use --branch <branch_name> or add the optional GIT_REPO_BRANCH as a positional argument after GIT_REPO_URL
    • If you want to append the git repo you're working on to your myrepos config, you can add --mr to your git-peak-extended command
    • If you want to clone a GIT_REPO_URL directly, bypassing any additional niceties of git-peak-extended, like say for example for self-hosted Git servers, or others that aren't fully supported by git-peak-extended, you can do so by passing the --raw flag (or -r for short)

Assumptions

  • Already have git and mktemp packages installed
  • Already have $EDITOR environment variable configured for your favourite editor
  • Port 22 not blocked so you can use git over SSH
  • git config is set up for various git providers like GitHub or GitLab
  • SSH config already set up with entry for git providers using IdentityFile with the same SSH key added to your git provider user profiles
  • SSH agent has your key loaded to facilitate fast usage (don't need to enter password each time)

Examples

Below are examples of how I use git-peak-extended:

  1. Download it to ~/bin/git-peak-extended and set as executable:
curl -sLo ~/bin/git-peak-extended https://raw.githubusercontent.com/toozej/git-peak-extended/main/git-peak-extended && chmod u+x ~/bin/git-peak-extended
  1. Alias gp to git-peak-extended's default mode (temporarily grab repo)
echo "gp() { EDITOR='code -n -w -a' $HOME/bin/git-peak-extended --temp $@; }" >> ~/.functions
  1. Alias gps to git-peak-extended's save permanently mode, appending the repo to your mr config
echo "gps() { EDITOR=vim $HOME/bin/git-peak-extended --mr --save $@ && cd $(cat /tmp/git-peak-extended.tmp); }" >> ~/.functions
  1. Alias gpb to git-peak-extended's default mode (temporarily grab repo) with a specific branch
echo "gpb() { EDITOR='code -n -w -a' $HOME/bin/git-peak-extended --temp --branch $@; }" >> ~/.functions

About

Quickly grab git repos temporarily or permanently

Topics

Resources

License

Stars

Watchers

Forks