git-peak-extended uses the same basic idea as git-peak but takes it a few steps further:
- Supports saving git repos either to temporary storage (like git-peak), but alternatively, to permanent storage for future use.
- Supports the most common public git providers: GitHub, GitLab, sourcehut, and BitBucket.
- Supports HTTPS, Git, and short-hand formatted repo URLs to clone
- Supports checking out a user-specified branch, or the repo's default branch
- 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.
git-peak-extended is inspired by similar repos posted in Hacker News 1 2 3 4 recently:
Specifically it is an extended version of #3 above, git-peak.
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:
- 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. - I wanted to be able to view repos using one $EDITOR VSCode while storing repos permanently and opening them with another $EDITOR vim.
- More practice writing Bash scripts
- More specifically testing Bash scripts with GitHub Actions
-
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
-
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
- Using cURL:
-
Find a repo to you want to "peek", and get the
GIT_REPO_URL
in any one of these supported formats: -
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
- For more explicit usage (like in aliases), you can alternatively use
-
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
- Alternatively, the
-
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>'
- Temporarily set the editor for this one-time usage of git-peak-extended:
- If you want to specify a non-default git branch to checkout, you can use
--branch <branch_name>
or add the optionalGIT_REPO_BRANCH
as a positional argument afterGIT_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 ofgit-peak-extended
, like say for example for self-hosted Git servers, or others that aren't fully supported bygit-peak-extended
, you can do so by passing the--raw
flag (or-r
for short)
- 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)
Below are examples of how I use git-peak-extended:
- 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
- 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
- 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
- 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