Github GitHub - Jarred-Sumner/git-peek: git repo to local editor instantly
source link: https://github.com/Jarred-Sumner/git-peek
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
git-peek
git peek
is the fastest way to open a remote git repository in your local text editor.
Use it when you want to browse or search other people's code with your own editor.
Installation:
Installing from npm makes updates easy:
npm install -g @jarred/git-peek
But there are also precompiled binaries:
NEW: Try the chrome/firefox extension. It adds an "Open" button to pull requests, files, and repositories, so you can read code with your editor without needing to copy-paste into the terminal. Only works on macOS for now and doesn't work on vim (terminal editor without a temrinal? how)
Usage:
git peek https://github.com/ylukem/pin-go
git peek https://github.com/jarred-sumner/atbuild
git peek https://github.com/facebook/react/pull/20790
git peek hanford/trends
git peek react
git peek https://github.com/jarred-sumner/fastbench.dev/tree/main/
git peek https://github.com/evanw/esbuild/blob/master/lib/common.ts
Pass git peek
a git repository or a github link, and it will quickly fetch and open it in your local editor. It stores the repository in a temporary directory and deletes it when you close the editor or git peek
.
It's fast.
❯ git peek https://github.com/nodejs/node/blob/master/lib/dgram.js ⏳ Extracting repository to temp folder... 💻 Launched editor in 0.20s
If you paste a link to a pull request on GitHub, it will open it quickly:
❯ git peek https://github.com/facebook/react/pull/20790
💻 Launched editor in 0.13s
⏳ Extracting repository to temp folder...
💿 Finished downloading repository!
Much faster than cloning.
If you don't pass git peek
input, it will let you search Github repositories and show trending repositories:
❯ git peek
Search Github repositories:
> Search
❯ iam-abbas/Reddit-Stock-T | Fetch currently trending stocks on Reddit
codeSTACKr/free-develope | Free Developer Resources
justjavac/1s | 天若有情天亦老,我为网站加一秒
PaddlePaddle/PaddleNLP | NLP Core Library and Model Zoo based on PaddlePa
ModernPwner/cicuta_viros |
jevakallio/vscode-live-f | Run your web app inside VS Code
getActivity/AndroidCodeS | Android 代码规范文档
gigantz/react-xpress | React renderer to build Node.js server
If you type a repository name without the owner (react
instead of facebook/react
), it will search:
❯ git peek react
Search Github repositories:
> react
❯ facebook/react | A declarative, efficient, and flexible JavaScrip
typescript-cheatsheets/r | Cheatsheets for experienced React developers get
duxianwei520/react | React+webpack+redux+ant design+axios+less全家桶后台管
discountry/react | React docs in Chinese | React 中文文档翻译
Cathy0807/react | 京东首页构建
react-redux-antd-es6/rea | 基于react的企业后台管理开发框架
HackYourFuture/React | This repository contains all the material for th
geist-org/react | Modern and minimalist React UI library.
If you paste a link to a file on GitHub, it will quickly open the file in your local editor:
❯ git peek https://github.com/Jarred-Sumner/git-peek/blob/main/src/index.ts
💻 Launched editor in 0.39s
⏳ Extracting repository to temp folder...
💿 Finished downloading repository!
❯ git peek -h Quickly preview remote Git repositories in your local editor USAGE $ git-peek [git link or github link or search query or repository file path] EXAMPLES git peek https://github.com/evanw/esbuild/blob/master/lib/common.ts git peek https://github.com/ylukem/pin-go git peek https://github.com/jarred-sumner/atbuild git peek hanford/trends git peek react OPTIONS -e, --editor=editor [default: auto] editor to open with, possible values: auto, code, subl, vim, vi, code-insiders. By default, it will search $EDITOR. If not found, it will try code, then subl, then vim. -r, --register [default: false] Register the git-peek:// url protocol This allows the "Open" buttons to work on github.com once you\'ve installed the extension. Only supported on macOS (Windows coming soon). -o, --out= [default: system temp directory] output directory to store repository files in. If youre cloning a large repo and your tempdir is an in-memory storage (/tmp), maybe change this. -w, --wait [default: false] wait to open the editor until the repository finishes downloading. always on for vi. --no-keep [default: false] keep the repository, rather than deleting it. -b, --branch [default: "master"] select a branch/ref to use. if the repository doesn't use master/main, you'll want to set this manually. but it will try to infer from the input by default. -d [default: false] Ask the GitHub API for the default_branch to clone. -h, --help show CLI help ENVIRONMENT VARIABLES: $EDITOR: code --wait $GITHUB_TOKEN: ******** .env: ✅ $HOME/.git-peek For use with private GitHub repositories, set $GITHUB_TOKEN to a personal access token. To persist it, store it in your shell config or the .env shown above.
Private repositories & choosing an editor
To use git-peek
with private repositories, set a $GITHUB_TOKEN
to a personal access token. If you don't want a global shell $GITHUB_TOKEN
, you can set in $HOME/.git-peek
.
Its a .env
file, so the syntax looks like this:
EDITOR="code" GITHUB_TOKEN="**********"
You can also save a custom editor this way. So you don't have to add -e vim
everytime if $EDITOR
is not propagating to the process.
How does this work?
If you pass it a GitHub repository, it fetches a tarball instead of using git and decompresses it while downloading it (streaming). From unscientific benchmarks, this is about 2x faster than cloning. While downloading & decompressing the tarball, it also downloads the specific file linked to (or the README.md
) via JSDelivr's CDN. Whichever happens first, it opens in the editor (usually JSDelivr), but it will keep fetching the repo until its complete or the program exits.
If you pass it a git repository rather than a Github url, it does a partial clone instead of doing a full clone.
When your editor closes or you close git peek
, it deletes the repository from your computer.
This was inspired by github1s.com.
Changelog
-
1.2.0
: Create agit-peek://
URL handler, so that you can click a link to open a repository in your local editor. Register the URL handler withgit peek -r
. -
1.1.37
: Add easter egg to search results -
1.1.36
: Add optional-d
flag that automatically asks github what the default branch is before cloning instead of guessing its eithermain
ormaster
. -
1.1.35
: Add optional--branch
flag so you can choose which branch to clone if its not shown in the url. See #17 -
1.1.34
: Fix home directory path resolution on Windows -
1.1.33
: Add precompiled binary for windows in releases script. -
1.1.32
Add--no-keep
flag which skips deleting repositories on exit. Fix support for unknown editors. When the editor is unknown, it asks to confirm deleting the repository. -
1.1.31
: Fix issue where whenvim
is loaded with a specific file (rather than the repository root dir), it would log text on top ofvim
.
1.1.30
git-peek now starts 32% faster (delayed loading ink
until its used for search)
You can now store $EDITOR
and $GITHUB_TOKEN
in $HOME/.git-peek
. Its a .env
file, so the syntax looks like this:
EDITOR="code" GITHUB_TOKEN="**********"
Removed using the $GITHUB_TOKEN
from ~/.hubs/config
.
1.1.28-29
: Fix for Node 12+ #141.1.27
: Added--wait
flag which waits to open the editor until the entire repository is downloaded. Added--out
flag which changes the temp directory to store files in (see #8)1.1.22-26
: Fix windows bug.1.1.21
: Add Pull Request support. Now you can use this to quickly read a pull request. For example:git peek https://github.com/facebook/react/pull/20790
.1.1.20
: Fix bug when using with Fedora1.1.16-1.1.19
: trying to getrelease-it
to work1.1.15
: Movecode-insiders
to end of preference list1.1.14
: Fix code-insiders and fix passing in editor manually when itssubl
orcode
.1.1.13
: UseAuthorization
header instead ofaccess_token
query string.1.1.12
: When available, also use github access token for fetching tarballs (instead of just search)1.1.11
: When available, use github access token for github API requests to enable private repositories to work. To enable this, either set aGITHUB_TOKEN
environment variable or if you've installed hub, it will automatically useoauth_token
from$HOME/.config/hub
. In other words, if you usehub
, this should just work by default.1.1.10
: Fix vim1.1.9
: Fix Windows
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK