Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Feb 13, 2021
1 parent f290bbf commit a342d5f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ npm install -g @jarred/git-peek

But there are also [precompiled binaries](https://github.com/Jarred-Sumner/git-peek/releases):

- [Windows x64 – 1.1.37](https://github.com/Jarred-Sumner/git-peek/releases/download/1.1.37/git-peek.exe)
- [macOS x64 – 1.1.37](https://github.com/Jarred-Sumner/git-peek/releases/download/1.1.37/git-peek-macOS)
- [Windows x64 – 1.2.0](https://github.com/Jarred-Sumner/git-peek/releases/download/1.1.37/git-peek.exe)
- [macOS x64 – 1.2.0](https://github.com/Jarred-Sumner/git-peek/releases/download/1.1.37/git-peek-macOS)

**NEW**: [Try the chrome extension](https://github.com/Jarred-Sumner/1-click-from-github-to-editor). 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:

Expand Down Expand Up @@ -169,6 +171,8 @@ This was inspired by [github1s.com](https://github.com/conwnet/github1s).
### Changelog
- `1.2.0`: Create a `git-peek://` URL handler, so that you can click a link to open a repository in your local editor. Register the URL handler with `git 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 either `main` or `master`.
Expand Down
21 changes: 13 additions & 8 deletions bin/git-peek
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#isr
require("${await ex.default("git-peek")}");
`;if(console.log(`// --- BEGIN SHIM FILE ---
`+em.default.gray(E)+`
// --- END SHIM FILE ---`),console.log(`Wrote shim file (${em.default.gray(n)})`),Uh.default.writeFileSync(n,E,"utf8"),OE("chmod +x "+n),console.log("Registering URL handler..."),OE(`duti -s com.apple.ScriptEditor.id.git-peek ${tx}`),Uh.default.rmSync(u),Uh.default.existsSync("/Applications/Google Chrome.app")){console.log(`Adding ${tx}:// to Google Chrome`);try{OE(`defaults write com.google.Chrome URLWhitelist -array '${tx}://*'`)}catch(v){console.warn("Failed to add protocol to Google Chrome. Its okay.")}}console.log(em.default.green("\u2705 Registered git-peek:// protocol successfully.")),console.log('To unregister, just delete "/Applications/git-peek.app".'),console.log("To test it, run this:"),console.log(" "+em.default.blue("open git-peek://Jarred-Sumner/git-peek")),r.includes("vi")&&console.warn("vim/vi not supported (no terminal window will be open), but if you know a way to run a terminal window from the AppleScript feel free to submit a PR!")}async function _J(r,n){return`
// --- END SHIM FILE ---`),console.log(`Wrote shim file (${em.default.gray(n)})`),Uh.default.writeFileSync(n,E,"utf8"),OE("chmod +x "+n),console.log("Registering URL handler..."),OE(`duti -s com.apple.ScriptEditor.id.git-peek ${tx}`),Uh.default.rmSync(u),Uh.default.existsSync("/Applications/Google Chrome.app")){console.log(`Adding ${tx}:// to Google Chrome`);try{OE(`defaults write com.google.Chrome URLWhitelist -array '${tx}://*'`)}catch(v){console.warn("Failed to add protocol to Google Chrome. Its okay.")}}console.log(em.default.green("\u2705 Registered git-peek:// protocol successfully.")),console.log('To unregister, just delete "/Applications/git-peek.app".'),console.log("To test it, run this:"),console.log(" "+em.default.blue("open git-peek://Jarred-Sumner/git-peek")),r.includes("vi")&&console.warn("vim/vi not supported (no terminal window will be open), but if you know a way to run a terminal window from the AppleScript please do submit a PR!")}async function _J(r,n){return`
on open location this_URL
try
set innerCmd to "${r} --fromscript --out=${n} " & quoted form of this_URL
Expand Down Expand Up @@ -510,10 +510,13 @@ OPTIONS
By default, it will search $EDITOR. If not found, it
will try code, then subl, then vim.

-o, --out= [default: system temp directory] output directory to
store repository files in. If you're cloning a large
repo and your tempdir is an in-memory storage (/tmp),
maybe change this.
-d [default: false] Ask the GitHub API
for the default_branch to clone.

-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).

-w, --wait [default: false] wait to open the editor until the
repository finishes downloading. always on for vi.
Expand All @@ -525,8 +528,10 @@ OPTIONS
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.
-o, --out= [default: system temp directory] output directory to
store repository files in. If you're cloning a large
repo and your tempdir is an in-memory storage (/tmp),
maybe change this.

-h, --help show CLI help

Expand All @@ -539,7 +544,7 @@ For use with private GitHub repositories, set $GITHUB_TOKEN to a personal
access token. To persist it, store it in your shell or the .env shown above.
`.trim(),{flags:{fromscript:{type:"boolean",default:!1},register:{type:"boolean",default:!1,alias:"r",description:"Register protocol handler"},confirm:{type:"boolean",default:!1,alias:"c",description:"Confirm before deleting"},out:{type:"string",default:"",alias:"o",description:"Parent directory to store the repository in. Defaults to system temp folder."},branch:{type:"string",default:"",alias:"b",description:"branch/ref to use when fetching"},defaultBranch:{type:"boolean",default:!1,alias:"d",description:"Check default branch"},keep:{type:"boolean",default:!1,alias:"k",description:"Don't delete the repository on exit."},wait:{type:"boolean",default:!1,alias:"w",description:"Wait for the repository to completely download before opening. Defaults to false, unless its vim. Then its always true."},help:{type:"boolean",default:!1,alias:"h",isRequired:!1},version:{type:"boolean",default:!1,alias:"v",isRequired:!1},editor:{type:"string",isMultiple:!1,isRequired:!1,default:"auto",alias:"e",description:"editor to open with, possible values: auto, code, vim, subl. By default, it will search $EDITOR. If not found, it will try code, then subl, then vim."}}})}async getArchive(n,o){let u;try{u=await this._unzip(n)}catch(a){try{this.didUseFallback=!0,u=await this._unzip(o)}catch(e){console.error(`Invalid repository link. Tried:
- ${n}
- ${o}`),AE(),process.exit()}}return this.archive=u,u}async run(){var K,ce;let n=this.parse(),{help:o,version:u,out:a,branch:e,defaultBranch:d,register:E}=n.flags;Rg=n.flags.keep,o&&(n.showHelp(0),process.exit(0)),u&&(n.showVersion(),process.exit(0));let{flags:{editor:v="auto"}}=n;if(E){await EJ().register(await AJ(v,!1));return}let y=(ce=(K=n.input[0])==null?void 0:K.trim())!=null?ce:"",C=n.flags.confirm;y.includes("git-peek://")&&(y=y.replace("git-peek://",""),n.flags.fromscript&&(process.exit=()=>{}));let A,I=!1;if(!y.includes("://")&&y.split("/").length===2){let[W,oe]=y.split("/");oe.trim().length?y=`https://github.com/${W}/${oe}`:I=!0}for(I||(I=!y||!y.includes("/")||y.includes(" "));!A;){I&&(y=await this.search(y),I=!y||!y.includes("/")||y.includes(" "));try{A=DJ.default(y)}catch(W){try{y=await this.search(y),I=!y||!y.includes("/")||y.includes(" ")}catch(oe){console.log(oe)}}}let q=A.ref;if(A.resource==="github.com"&&(e==="default"||d)?q=await A3e(A.owner,A.name):e!==""?q=e:q||(q="master"),y&&y.length&&R3e(y)){let[W,oe,_e]=await O3e(y);A.name=oe,A.owner=W,q=_e}let _=new Date().getTime();ef=bJ.default.dirSync((a==null?void 0:a.length)?{unsafeCleanup:!0,keep:Rg,tmpdir:l1.default.resolve(process.cwd(),a)}:{unsafeCleanup:!0,keep:Rg}),this.destination=ef.name,Og=!1,process.once("beforeExit",AE),process.once("SIGABRT",AE),process.once("SIGQUIT",AE);let P=A.filepath,Y=!P;Y&&(P="README.md");let $=l1.default.join(ef.name,P);if(A.resource==="github.com"){let W=q==="main"?"master":"main";await Promise.any([this.prefetchGithub(A.name,A.owner,P,q,W,$).catch(console.error),this.unzip(A.owner,A.name,q,W,ef.name)])}else await this.clone(A.href,ef.name);let B=await AJ(v,!1),Q=[];if(this.editorMode=0,B.includes("code")?(B.includes("wait")||(B+=" --wait"),this.editorMode=1,Q.push("--new-window"),P&&Q.push(`-g "${l1.default.resolve($)}":0:0`)):B.includes("subl")?(B.includes("wait")||(B+=" --wait"),this.editorMode=2,Q.push("--new-window"),P&&Q.push(`"${l1.default.resolve($)}":0:0`)):B.includes("vi")&&(this.editorMode=3),(this.editorMode===3&&Y||n.flags.wait)&&this.unzipPromise&&await this.unzipPromise,await new Promise((W,oe)=>{if(this.editorMode===3){let he=function(){_e||(process.stdin.setRawMode(!1),process.stdin.resume(),W(),_e=!0)};process.stdin.setRawMode(!0),process.stdin.pause(),this.slowTask=rx.default.spawn(B,[Y?ef.name:P,...Q],{env:process.env,stdio:"inherit",detached:!1,cwd:ef.name});let _e=!1;this.slowTask.once("close",he),this.slowTask.once("exit",he),this.slowTask.once("error",he)}else{this.log(`\u{1F4BB} Launched editor in ${((new Date().getTime()-_)/1e3).toFixed(2)}s`);let _e=`${B} "${l1.default.join(ef.name)}" ${Q.join(" ")}`.trim();this.slowTask=rx.default.exec(_e,{env:process.env,stdio:"inherit",cwd:ef.name},(he,me)=>he?oe(he):W(me))}}),Rg)Og=!0;else if(this.editorMode===0||C){let W=process.emitWarning;process.emitWarning=()=>{};let{renderConfirm:oe}=SJ();process.emitWarning=W,Rg=Og=!await oe()}AE(),process.exit()}};$D.description="Quickly open a remote Git repository with your local text editor into a temporary folder.",$D.usage="[git link or github link]",$D.args=[{name:"url"}];process.on("unhandledRejection",r=>console.error(r));process.on("unhandledException",r=>console.error(r));LJ&&RJ.default.config({path:vN});qu=new $D;qu.run();
- ${o}`),AE(),process.exit()}}return this.archive=u,u}async run(){var K,ce;let n=this.parse(),{help:o,version:u,out:a,branch:e,defaultBranch:d,register:E}=n.flags;Rg=n.flags.keep,o&&(n.showHelp(0),process.exit(0)),u&&(n.showVersion(),process.exit(0));let{flags:{editor:v="auto"}}=n;if(E){await EJ().register(await AJ(v,!1));return}let y=(ce=(K=n.input[0])==null?void 0:K.trim())!=null?ce:"",C=n.flags.confirm;y.includes("git-peek://")&&(y=y.replace("git-peek://","").trim(),n.flags.fromscript&&(process.exit=()=>{}));let A,I=!1;if(!y.includes("://")&&y.split("/").length===2){let[W,oe]=y.split("/");oe.trim().length?y=`https://github.com/${W}/${oe}`:I=!0}for(I||(I=!y||!y.includes("/")||y.includes(" "));!A;){I&&(y=await this.search(y),I=!y||!y.includes("/")||y.includes(" "));try{A=DJ.default(y)}catch(W){try{y=await this.search(y),I=!y||!y.includes("/")||y.includes(" ")}catch(oe){console.log(oe)}}}let q=A.ref;if(A.resource==="github.com"&&(e==="default"||d)?q=await A3e(A.owner,A.name):e!==""?q=e:q||(q="master"),y&&y.length&&R3e(y)){let[W,oe,_e]=await O3e(y);A.name=oe,A.owner=W,q=_e}let _=new Date().getTime();ef=bJ.default.dirSync((a==null?void 0:a.length)?{unsafeCleanup:!0,keep:Rg,tmpdir:l1.default.resolve(process.cwd(),a)}:{unsafeCleanup:!0,keep:Rg}),this.destination=ef.name,Og=!1,process.once("beforeExit",AE),process.once("SIGABRT",AE),process.once("SIGQUIT",AE);let P=A.filepath,Y=!P;Y&&(P="README.md");let $=l1.default.join(ef.name,P);if(A.resource==="github.com"){let W=q==="main"?"master":"main";await Promise.any([this.prefetchGithub(A.name,A.owner,P,q,W,$).catch(console.error),this.unzip(A.owner,A.name,q,W,ef.name)])}else await this.clone(A.href,ef.name);let B=await AJ(v,!1),Q=[];if(this.editorMode=0,B.includes("code")?(B.includes("wait")||(B+=" --wait"),this.editorMode=1,Q.push("--new-window"),P&&Q.push(`-g "${l1.default.resolve($)}":0:0`)):B.includes("subl")?(B.includes("wait")||(B+=" --wait"),this.editorMode=2,Q.push("--new-window"),P&&Q.push(`"${l1.default.resolve($)}":0:0`)):B.includes("vi")&&(this.editorMode=3),(this.editorMode===3&&Y||n.flags.wait)&&this.unzipPromise&&await this.unzipPromise,await new Promise((W,oe)=>{if(this.editorMode===3){let he=function(){_e||(process.stdin.setRawMode(!1),process.stdin.resume(),W(),_e=!0)};process.stdin.setRawMode(!0),process.stdin.pause(),this.slowTask=rx.default.spawn(B,[Y?ef.name:P,...Q],{env:process.env,stdio:"inherit",detached:!1,cwd:ef.name});let _e=!1;this.slowTask.once("close",he),this.slowTask.once("exit",he),this.slowTask.once("error",he)}else{this.log(`\u{1F4BB} Launched editor in ${((new Date().getTime()-_)/1e3).toFixed(2)}s`);let _e=`${B} "${l1.default.join(ef.name)}" ${Q.join(" ")}`.trim();this.slowTask=rx.default.exec(_e,{env:process.env,stdio:"inherit",cwd:ef.name},(he,me)=>he?oe(he):W(me))}}),Rg)Og=!0;else if(this.editorMode===0||C){let W=process.emitWarning;process.emitWarning=()=>{};let{renderConfirm:oe}=SJ();process.emitWarning=W,Rg=Og=!await oe()}AE(),process.exit()}};$D.description="Quickly open a remote Git repository with your local text editor into a temporary folder.",$D.usage="[git link or github link]",$D.args=[{name:"url"}];process.on("unhandledRejection",r=>console.error(r));process.on("unhandledException",r=>console.error(r));LJ&&RJ.default.config({path:vN});qu=new $D;qu.run();
/*
object-assign
(c) Sindre Sorhus
Expand Down

0 comments on commit a342d5f

Please sign in to comment.