just-bash 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/chunks/chunk-CTLU5QUH.js +17 -0
- package/dist/bin/chunks/{grep-WDHYDUUD.js → grep-QCXXYC54.js} +1 -1
- package/dist/bin/chunks/rg-GVIT6FTE.js +33 -0
- package/dist/bin/just-bash.js +1 -1
- package/dist/bin/shell/chunks/chunk-CTLU5QUH.js +17 -0
- package/dist/bin/shell/chunks/{grep-WDHYDUUD.js → grep-QCXXYC54.js} +1 -1
- package/dist/bin/shell/chunks/rg-GVIT6FTE.js +33 -0
- package/dist/bin/shell/shell.js +1 -1
- package/dist/bundle/browser.js +379 -375
- package/dist/bundle/chunks/chunk-OHJS5H37.js +16 -0
- package/dist/bundle/chunks/{grep-QVR5G7SC.js → grep-TUWLGQC2.js} +1 -1
- package/dist/bundle/chunks/rg-KTCMPGU6.js +32 -0
- package/dist/bundle/index.js +1 -1
- package/dist/commands/rg/file-types.d.ts +33 -7
- package/dist/commands/rg/gitignore.d.ts +32 -3
- package/dist/commands/rg/rg-options.d.ts +14 -0
- package/dist/commands/search-engine/index.d.ts +1 -1
- package/dist/commands/search-engine/regex.d.ts +10 -0
- package/dist/fs/in-memory-fs/in-memory-fs.d.ts +51 -0
- package/dist/fs/in-memory-fs/index.d.ts +1 -0
- package/dist/fs/init.d.ts +12 -0
- package/dist/fs/interface.d.ts +203 -0
- package/dist/fs/mountable-fs/index.d.ts +1 -0
- package/dist/fs/mountable-fs/mountable-fs.d.ts +108 -0
- package/dist/fs/overlay-fs/index.d.ts +1 -0
- package/dist/fs/overlay-fs/overlay-fs.d.ts +107 -0
- package/dist/fs/read-write-fs/index.d.ts +1 -0
- package/dist/fs/read-write-fs/read-write-fs.d.ts +47 -0
- package/dist/fs/utils.d.ts +17 -0
- package/package.json +2 -3
- package/dist/bin/chunks/chunk-X4WRNADE.js +0 -17
- package/dist/bin/chunks/rg-ALK3CYAN.js +0 -29
- package/dist/bin/shell/chunks/chunk-X4WRNADE.js +0 -17
- package/dist/bin/shell/chunks/rg-ALK3CYAN.js +0 -29
- package/dist/bundle/chunks/chunk-7VH6U2UX.js +0 -16
- package/dist/bundle/chunks/rg-43HLKW4V.js +0 -28
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as O,b as R}from"./chunk-X4WRNADE.js";import{a as E,b as _,c as k}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var j={js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}};function P(e,t){let r=e.toLowerCase();for(let s of t){let n=j[s];if(n){for(let i of n.extensions)if(r.endsWith(i))return!0;for(let i of n.globs)if(i.includes("*")){let l=i.replace(/\./g,"\\.").replace(/\*/g,".*");if(new RegExp(`^${l}$`,"i").test(e))return!0}else if(r===i.toLowerCase())return!0}}return!1}function B(){let e=[];for(let[t,r]of Object.entries(j).sort()){let s=[];for(let n of r.extensions)s.push(`*${n}`);for(let n of r.globs)s.push(n);e.push(`${t}: ${s.join(", ")}`)}return`${e.join(`
|
|
3
|
-
`)}
|
|
4
|
-
`}function A(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,filesWithMatches:!1,filesWithoutMatch:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],types:[],typesNot:[],hidden:!1,noIgnore:!1,maxDepth:1/0,followSymlinks:!1,searchZip:!1,searchBinary:!1}}function U(e){return j[e]?null:{stdout:"",stderr:`rg: unknown type: ${e}
|
|
5
|
-
Use --type-list to see available types.
|
|
6
|
-
`,exitCode:1}}var J=[{short:"g",long:"glob",target:"globs",multi:!0},{short:"t",long:"type",target:"types",multi:!0,validate:U},{short:"T",long:"type-not",target:"typesNot",multi:!0,validate:U},{short:"m",long:"max-count",target:"maxCount",parse:parseInt},{short:"e",long:"regexp",target:"patterns",multi:!0},{short:"f",long:"file",target:"patternFiles",multi:!0},{short:"r",long:"replace",target:"replace"},{long:"max-depth",target:"maxDepth",parse:parseInt},{long:"context-separator",target:"contextSeparator"}],H={i:e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1},"--ignore-case":e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1},s:e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1},"--case-sensitive":e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1},S:e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1},"--smart-case":e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1},F:e=>{e.fixedStrings=!0},"--fixed-strings":e=>{e.fixedStrings=!0},w:e=>{e.wordRegexp=!0},"--word-regexp":e=>{e.wordRegexp=!0},x:e=>{e.lineRegexp=!0},"--line-regexp":e=>{e.lineRegexp=!0},v:e=>{e.invertMatch=!0},"--invert-match":e=>{e.invertMatch=!0},U:e=>{e.multiline=!0},"--multiline":e=>{e.multiline=!0},c:e=>{e.count=!0},"--count":e=>{e.count=!0},"--count-matches":e=>{e.countMatches=!0},l:e=>{e.filesWithMatches=!0},"--files-with-matches":e=>{e.filesWithMatches=!0},"--files-without-match":e=>{e.filesWithoutMatch=!0},o:e=>{e.onlyMatching=!0},"--only-matching":e=>{e.onlyMatching=!0},q:e=>{e.quiet=!0},"--quiet":e=>{e.quiet=!0},N:e=>{e.lineNumber=!1},"--no-line-number":e=>{e.lineNumber=!1},I:e=>{e.noFilename=!0},"--no-filename":e=>{e.noFilename=!0},0:e=>{e.nullSeparator=!0},"--null":e=>{e.nullSeparator=!0},b:e=>{e.byteOffset=!0},"--byte-offset":e=>{e.byteOffset=!0},"--column":e=>{e.column=!0,e.lineNumber=!0},"--vimgrep":e=>{e.vimgrep=!0,e.column=!0,e.lineNumber=!0},"--json":e=>{e.json=!0},"--hidden":e=>{e.hidden=!0},"--no-ignore":e=>{e.noIgnore=!0},L:e=>{e.followSymlinks=!0},"--follow":e=>{e.followSymlinks=!0},z:e=>{e.searchZip=!0},"--search-zip":e=>{e.searchZip=!0},a:e=>{e.searchBinary=!0},"--text":e=>{e.searchBinary=!0},"--heading":e=>{e.heading=!0},"--passthru":e=>{e.passthru=!0},"--include-zero":e=>{e.includeZero=!0}},V=new Set(["n","--line-number"]);function X(e){e.hidden?e.searchBinary=!0:e.noIgnore?e.hidden=!0:e.noIgnore=!0}function K(e,t,r){let s=e[t];for(let n of J){if(s.startsWith(`--${n.long}=`)){let i=s.slice(`--${n.long}=`.length),l=D(r,n,i);return l?{newIndex:t,error:l}:{newIndex:t}}if(n.short&&s===`-${n.short}`||s===`--${n.long}`){if(t+1>=e.length)return null;let i=e[t+1],l=D(r,n,i);return l?{newIndex:t+1,error:l}:{newIndex:t+1}}}return null}function D(e,t,r){if(t.validate){let n=t.validate(r);if(n)return n}let s=t.parse?t.parse(r):r;t.multi?e[t.target].push(s):e[t.target]=s}function Q(e,t){let r=e[t];if(r==="--sort"&&t+1<e.length){let s=e[t+1];if(s==="path"||s==="none")return{value:s,newIndex:t+1}}if(r.startsWith("--sort=")){let s=r.slice(7);if(s==="path"||s==="none")return{value:s,newIndex:t}}return null}function ee(e,t){let r=e[t],s=r.match(/^-([ABC])(\d+)$/);return s?{flag:s[1],value:parseInt(s[2],10),newIndex:t}:(r==="-A"||r==="-B"||r==="-C")&&t+1<e.length?{flag:r[1],value:parseInt(e[t+1],10),newIndex:t+1}:null}function te(e){let t=e.match(/^-m(\d+)$/);return t?parseInt(t[1],10):null}function q(e){let t=A(),r=null,s=[],n=-1,i=-1,l=-1,o=!1;for(let a=0;a<e.length;a++){let c=e[a];if(c.startsWith("-")&&c!=="-"){let u=ee(e,a);if(u){let{flag:f,value:m,newIndex:x}=u;f==="A"?n=Math.max(n,m):f==="B"?i=Math.max(i,m):l=m,a=x;continue}let h=te(c);if(h!==null){t.maxCount=h;continue}let d=K(e,a,t);if(d){if(d.error)return{success:!1,error:d.error};a=d.newIndex;continue}let g=Q(e,a);if(g){t.sort=g.value,a=g.newIndex;continue}let p=c.startsWith("--")?[c]:c.slice(1).split("");for(let f of p){if(V.has(f)){t.lineNumber=!0,o=!0;continue}if(f==="u"||f==="--unrestricted"){X(t);continue}let m=H[f];if(m){m(t);continue}if(f.startsWith("--"))return{success:!1,error:k("rg",f)};if(f.length===1)return{success:!1,error:k("rg",`-${f}`)}}}else r===null?r=c:s.push(c)}return(n>=0||l>=0)&&(t.afterContext=Math.max(n>=0?n:0,l>=0?l:0)),(i>=0||l>=0)&&(t.beforeContext=Math.max(i>=0?i:0,l>=0?l:0)),r!==null&&t.patterns.push(r),(t.column||t.vimgrep)&&(o=!0),{success:!0,options:t,paths:s,explicitLineNumbers:o}}import{gunzipSync as se}from"node:zlib";var W=class{patterns=[];basePath;constructor(t="/"){this.basePath=t}parse(t){let r=t.split(`
|
|
7
|
-
`);for(let s of r){let n=s.replace(/\s+$/,"");if(!n||n.startsWith("#"))continue;let i=!1;n.startsWith("!")&&(i=!0,n=n.slice(1));let l=!1;n.endsWith("/")&&(l=!0,n=n.slice(0,-1));let o=!1;n.startsWith("/")?(o=!0,n=n.slice(1)):n.includes("/")&&!n.startsWith("**/")&&(o=!0);let a=this.patternToRegex(n,o);this.patterns.push({pattern:s,regex:a,negated:i,directoryOnly:l,rooted:o})}}patternToRegex(t,r){let s="";r?s="^":s="(?:^|/)";let n=0;for(;n<t.length;){let i=t[n];if(i==="*")t[n+1]==="*"?t[n+2]==="/"?(s+="(?:.*/)?",n+=3):(n+2>=t.length,s+=".*",n+=2):(s+="[^/]*",n++);else if(i==="?")s+="[^/]",n++;else if(i==="["){let l=n+1;for(l<t.length&&t[l]==="!"&&l++,l<t.length&&t[l]==="]"&&l++;l<t.length&&t[l]!=="]";)l++;if(l<t.length){let o=t.slice(n,l+1);o.startsWith("[!")&&(o=`[^${o.slice(2)}`),s+=o,n=l+1}else s+="\\[",n++}else i==="/"?(s+="/",n++):(s+=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n++)}return s+="(?:/.*)?$",new RegExp(s)}matches(t,r){let s=t.replace(/^\.\//,"");s=s.replace(/^\//,"");let n=!1;for(let i of this.patterns)i.directoryOnly&&!r||i.regex.test(s)&&(n=!i.negated);return n}getBasePath(){return this.basePath}},M=class{parsers=[];fs;rootPath;constructor(t,r){this.fs=t,this.rootPath=r}async load(t){let r=[],s=t;for(;s.startsWith(this.rootPath)||s===this.rootPath;){r.unshift(s);let n=this.fs.resolvePath(s,"..");if(n===s)break;s=n}for(let n of r)for(let i of[".gitignore",".ignore"]){let l=this.fs.resolvePath(n,i);try{let o=await this.fs.readFile(l),a=new W(n);a.parse(o),this.parsers.push(a)}catch{}}}matches(t,r){for(let s of this.parsers){let n=s.getBasePath();if(!t.startsWith(n))continue;let i=t.slice(n.length).replace(/^\//,"");if(s.matches(i,r))return!0}return!1}static isCommonIgnored(t){return new Set(["node_modules",".git",".svn",".hg","__pycache__",".pytest_cache",".mypy_cache","venv",".venv","dist","build",".next",".nuxt","target",".cargo"]).has(t)}};async function z(e,t){let r=new M(e,t);return await r.load(t),r}function ne(e){return e.length>=2&&e[0]===31&&e[1]===139}async function G(e){let{ctx:t,options:r,paths:s,explicitLineNumbers:n}=e,i=[...r.patterns];for(let p of r.patternFiles)try{let f=t.fs.resolvePath(t.cwd,p),x=(await t.fs.readFile(f)).split(`
|
|
8
|
-
`).filter(y=>y.length>0);i.push(...x)}catch{return{stdout:"",stderr:`rg: ${p}: No such file or directory
|
|
9
|
-
`,exitCode:2}}if(i.length===0)return{stdout:"",stderr:`rg: no pattern given
|
|
10
|
-
`,exitCode:2};let l=s.length===0?["."]:s,o=re(r,i),a;try{a=ie(i,r,o)}catch{return{stdout:"",stderr:`rg: invalid regex: ${i.join(", ")}
|
|
11
|
-
`,exitCode:2}}let c=null;r.noIgnore||(c=await z(t.fs,t.cwd));let{files:u,singleExplicitFile:h}=await le(t,l,r,c);if(u.length===0)return{stdout:"",stderr:"",exitCode:1};let d=!r.noFilename&&(!h||u.length>1),g=r.lineNumber;return n||(h&&u.length===1&&(g=!1),r.onlyMatching&&(g=!1)),oe(t,u,a,r,d,g)}function re(e,t){return e.caseSensitive?!1:e.ignoreCase?!0:e.smartCase?!t.some(r=>/[A-Z]/.test(r)):!1}function ie(e,t,r){let s;return e.length===1?s=e[0]:s=e.map(n=>t.fixedStrings?n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):`(?:${n})`).join("|"),R(s,{mode:t.fixedStrings&&e.length===1?"fixed":"perl",ignoreCase:r,wholeWord:t.wordRegexp,lineRegexp:t.lineRegexp,multiline:t.multiline})}async function le(e,t,r,s){let n=[],i=0,l=0;for(let a of t){let c=e.fs.resolvePath(e.cwd,a);try{let u=await e.fs.stat(c);u.isFile?(i++,Y(a,r,s,c)&&n.push(a)):u.isDirectory&&(l++,await Z(e,a,c,0,r,s,n))}catch{}}return{files:r.sort==="path"?n.sort():n,singleExplicitFile:i===1&&l===0}}async function Z(e,t,r,s,n,i,l){if(!(s>=n.maxDepth))try{let o=e.fs.readdirWithFileTypes?await e.fs.readdirWithFileTypes(r):(await e.fs.readdir(r)).map(a=>({name:a,isFile:void 0}));for(let a of o){let c=a.name;if(!n.hidden&&c.startsWith(".")||!n.noIgnore&&M.isCommonIgnored(c))continue;let u=t==="."?c:`${t}/${c}`,h=e.fs.resolvePath(r,c),d,g,p=!1;if(a.isFile!==void 0&&"isDirectory"in a){let m=a;if(p=m.isSymbolicLink===!0,p&&!n.followSymlinks)continue;if(p&&n.followSymlinks)try{let x=await e.fs.stat(h);d=x.isFile,g=x.isDirectory}catch{continue}else d=m.isFile,g=m.isDirectory}else try{let m=e.fs.lstat?await e.fs.lstat(h):await e.fs.stat(h);if(p=m.isSymbolicLink===!0,p&&!n.followSymlinks)continue;let x=p&&n.followSymlinks?await e.fs.stat(h):m;d=x.isFile,g=x.isDirectory}catch{continue}i?.matches(h,g)||(g?await Z(e,u,h,s+1,n,i,l):d&&Y(u,n,i,h)&&l.push(u))}}catch{}}function Y(e,t,r,s){let n=e.split("/").pop()||e;if(r?.matches(s,!1)||t.types.length>0&&!P(n,t.types)||t.typesNot.length>0&&P(n,t.typesNot))return!1;if(t.globs.length>0){let i=t.globs.filter(o=>!o.startsWith("!")),l=t.globs.filter(o=>o.startsWith("!")).map(o=>o.slice(1));if(i.length>0){let o=!1;for(let a of i)if(I(n,a)||I(e,a)){o=!0;break}if(!o)return!1}for(let o of l)if(o.startsWith("/")){let a=o.slice(1);if(I(e,a))return!1}else if(I(n,o)||I(e,o))return!1}return!0}function I(e,t){let r="^";for(let s=0;s<t.length;s++){let n=t[s];if(n==="*")t[s+1]==="*"?(r+=".*",s++):r+="[^/]*";else if(n==="?")r+="[^/]";else if(n==="["){let i=s+1;for(i<t.length&&t[i]==="!"&&i++,i<t.length&&t[i]==="]"&&i++;i<t.length&&t[i]!=="]";)i++;if(i<t.length){let l=t.slice(s,i+1);l.startsWith("[!")&&(l=`[^${l.slice(2)}`),r+=l,s=i}else r+="\\["}else r+=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}return r+="$",new RegExp(r).test(e)}async function ae(e,t,r,s){try{if(s.searchZip&&r.endsWith(".gz")){let l=await e.fs.readFileBuffer(t);if(ne(l))try{let o=se(l),a=new TextDecoder().decode(o),c=a.slice(0,8192);return{content:a,isBinary:c.includes("\0")}}catch{return null}}let n=await e.fs.readFile(t),i=n.slice(0,8192);return{content:n,isBinary:i.includes("\0")}}catch{return null}}async function oe(e,t,r,s,n,i){let l="",o=!1,a=[],c=0,u=0,h=0,d=50;e:for(let f=0;f<t.length;f+=d){let m=t.slice(f,f+d),x=await Promise.all(m.map(async y=>{let S=e.fs.resolvePath(e.cwd,y),w=await ae(e,S,y,s);if(!w)return null;let{content:b,isBinary:N}=w;if(h+=b.length,N&&!s.searchBinary)return null;let F=n&&!s.heading?y:"",C=O(b,r,{invertMatch:s.invertMatch,showLineNumbers:i,countOnly:s.count,countMatches:s.countMatches,filename:F,onlyMatching:s.onlyMatching,beforeContext:s.beforeContext,afterContext:s.afterContext,maxCount:s.maxCount,contextSeparator:s.contextSeparator,showColumn:s.column,vimgrep:s.vimgrep,showByteOffset:s.byteOffset,replace:s.replace,passthru:s.passthru,multiline:s.multiline});return s.json&&C.matched?{file:y,result:C,content:b,isBinary:!1}:{file:y,result:C}}));for(let y of x){if(!y)continue;let{file:S,result:w}=y;if(w.matched){if(o=!0,u++,c+=w.matchCount,s.quiet&&!s.json)break e;if(s.json&&!s.quiet){let b=y.content||"";a.push(JSON.stringify({type:"begin",data:{path:{text:S}}}));let N=b.split(`
|
|
12
|
-
`);r.lastIndex=0;let F=0;for(let C=0;C<N.length;C++){let $=N[C];r.lastIndex=0;let T=[];for(let v=r.exec($);v!==null;v=r.exec($)){let L={match:{text:v[0]},start:v.index,end:v.index+v[0].length};s.replace!==null&&(L.replacement={text:s.replace}),T.push(L),v[0].length===0&&r.lastIndex++}if(T.length>0){let v={type:"match",data:{path:{text:S},lines:{text:`${$}
|
|
13
|
-
`},line_number:C+1,absolute_offset:F,submatches:T}};a.push(JSON.stringify(v))}F+=$.length+1}a.push(JSON.stringify({type:"end",data:{path:{text:S},binary_offset:null,stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:1,searches_with_match:1,bytes_searched:b.length,bytes_printed:0,matched_lines:w.matchCount,matches:w.matchCount}}}))}else if(s.filesWithMatches){let b=s.nullSeparator?"\0":`
|
|
14
|
-
`;l+=`${S}${b}`}else s.filesWithoutMatch||(s.heading&&n&&(l+=`${S}
|
|
15
|
-
`),l+=w.output)}else if(s.filesWithoutMatch){let b=s.nullSeparator?"\0":`
|
|
16
|
-
`;l+=`${S}${b}`}else s.includeZero&&(s.count||s.countMatches)&&(l+=w.output)}}s.json&&(a.push(JSON.stringify({type:"summary",data:{elapsed_total:{secs:0,nanos:0,human:"0s"},stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:t.length,searches_with_match:u,bytes_searched:h,bytes_printed:0,matched_lines:c,matches:c}}})),l=`${a.join(`
|
|
17
|
-
`)}
|
|
18
|
-
`);let g=s.quiet&&!s.json?"":l,p;return s.filesWithoutMatch?p=l.length>0?0:1:p=o?0:1,{stdout:g,stderr:"",exitCode:p}}var ce={name:"rg",summary:"recursively search for a pattern",usage:"rg [OPTIONS] PATTERN [PATH ...]",description:`rg (ripgrep) recursively searches directories for a regex pattern.
|
|
19
|
-
Unlike grep, rg is recursive by default and respects .gitignore files.
|
|
20
|
-
|
|
21
|
-
EXAMPLES:
|
|
22
|
-
rg foo Search for 'foo' in current directory
|
|
23
|
-
rg foo src/ Search in src/ directory
|
|
24
|
-
rg -i foo Case-insensitive search
|
|
25
|
-
rg -w foo Match whole words only
|
|
26
|
-
rg -t js foo Search only JavaScript files
|
|
27
|
-
rg -g '*.ts' foo Search files matching glob
|
|
28
|
-
rg --hidden foo Include hidden files
|
|
29
|
-
rg -l foo List files with matches only`,options:["-e, --regexp PATTERN search for PATTERN (can be used multiple times)","-f, --file FILE read patterns from FILE, one per line","-i, --ignore-case case-insensitive search","-s, --case-sensitive case-sensitive search (overrides smart-case)","-S, --smart-case smart case (default: case-insensitive unless pattern has uppercase)","-F, --fixed-strings treat pattern as literal string","-w, --word-regexp match whole words only","-x, --line-regexp match whole lines only","-v, --invert-match select non-matching lines","-r, --replace TEXT replace matches with TEXT","-c, --count print count of matching lines per file"," --count-matches print count of individual matches per file","-l, --files-with-matches print only file names with matches"," --files-without-match print file names without matches","-o, --only-matching print only matching parts","-m, --max-count NUM stop after NUM matches per file","-q, --quiet suppress output, exit 0 on match","-n, --line-number print line numbers (default: on)","-N, --no-line-number do not print line numbers","-I, --no-filename suppress the prefixing of file names","-0, --null use NUL as filename separator","-b, --byte-offset show byte offset of each match"," --column show column number of first match"," --vimgrep show results in vimgrep format"," --json show results in JSON Lines format","-A NUM print NUM lines after each match","-B NUM print NUM lines before each match","-C NUM print NUM lines before and after each match"," --context-separator SEP separator for context groups (default: --)","-U, --multiline match patterns across lines","-z, --search-zip search in compressed files (gzip only)","-g, --glob GLOB include files matching GLOB","-t, --type TYPE only search files of TYPE (e.g., js, py, ts)","-T, --type-not TYPE exclude files of TYPE","-L, --follow follow symbolic links","-u, --unrestricted reduce filtering (-u: no ignore, -uu: +hidden, -uuu: +binary)","-a, --text search binary files as text"," --hidden search hidden files and directories"," --no-ignore don't respect .gitignore/.ignore files"," --max-depth NUM maximum search depth"," --sort TYPE sort files (path, none)"," --heading show file path above matches"," --passthru print all lines (non-matches use - separator)"," --include-zero include files with 0 matches in count output"," --type-list list all available file types"," --help display this help and exit"]},Ne={name:"rg",async execute(e,t){if(_(e))return E(ce);if(e.includes("--type-list"))return{stdout:B(),stderr:"",exitCode:0};let r=q(e);return r.success?G({ctx:t,options:r.options,paths:r.paths,explicitLineNumbers:r.explicitLineNumbers}):r.error}};export{Ne as rgCommand};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
function A(r,l,u={}){let{invertMatch:f=!1,showLineNumbers:c=!1,countOnly:B=!1,countMatches:j=!1,filename:a="",onlyMatching:T=!1,beforeContext:N=0,afterContext:v=0,maxCount:w=0,contextSeparator:P="--",showColumn:M=!1,vimgrep:z=!1,showByteOffset:b=!1,replace:p=null,passthru:g=!1,multiline:R=!1}=u;if(R)return D(r,l,{invertMatch:f,showLineNumbers:c,countOnly:B,countMatches:j,filename:a,onlyMatching:T,beforeContext:N,afterContext:v,maxCount:w,contextSeparator:P,showColumn:M,showByteOffset:b,replace:p});let d=r.split(`
|
|
2
|
-
`),S=d.length,y=S>0&&d[S-1]===""?S-1:S;if(B||j){let i=0;for(let e=0;e<y;e++)if(l.lastIndex=0,j)for(let t=l.exec(d[e]);t!==null;t=l.exec(d[e]))f||i++,t[0].length===0&&l.lastIndex++;else l.test(d[e])!==f&&i++;return{output:`${a?`${a}:${i}`:String(i)}
|
|
3
|
-
`,matched:i>0,matchCount:i}}if(N===0&&v===0&&!g){let i=[],o=!1,e=0,t=0;for(let s=0;s<y&&!(w>0&&e>=w);s++){let L=d[s];if(l.lastIndex=0,l.test(L)!==f)if(o=!0,e++,T){l.lastIndex=0;for(let h=l.exec(L);h!==null;h=l.exec(L)){let I=p!==null?p:h[0],k=a?`${a}:`:"";b&&(k+=`${t+h.index}:`),c&&(k+=`${s+1}:`),M&&(k+=`${h.index+1}:`),i.push(k+I),h[0].length===0&&l.lastIndex++}}else if(z){l.lastIndex=0;for(let h=l.exec(L);h!==null;h=l.exec(L)){let I=a?`${a}:`:"";b&&(I+=`${t+h.index}:`),c&&(I+=`${s+1}:`),M&&(I+=`${h.index+1}:`),i.push(I+L),h[0].length===0&&l.lastIndex++}}else{l.lastIndex=0;let h=l.exec(L),I=h?h.index+1:1,k=L;p!==null&&(l.lastIndex=0,k=L.replace(l,p));let E=a?`${a}:`:"";b&&(E+=`${t+(h?h.index:0)}:`),c&&(E+=`${s+1}:`),M&&(E+=`${I}:`),i.push(E+k)}t+=L.length+1}return{output:i.length>0?`${i.join(`
|
|
4
|
-
`)}
|
|
5
|
-
`:"",matched:o,matchCount:e}}if(g){let i=[],o=!1,e=0;for(let t=0;t<y;t++){let s=d[t];l.lastIndex=0;let O=l.test(s)!==f;O&&(o=!0,e++);let h=O?":":"-",I=a?`${a}${h}`:"";c&&(I+=`${t+1}${h}`),i.push(I+s)}return{output:i.length>0?`${i.join(`
|
|
6
|
-
`)}
|
|
7
|
-
`:"",matched:o,matchCount:e}}let $=[],C=0,m=new Set,x=-1,n=[];for(let i=0;i<y&&!(w>0&&C>=w);i++)l.lastIndex=0,l.test(d[i])!==f&&(n.push(i),C++);for(let i of n){let o=Math.max(0,i-N);x>=0&&o>x+1&&$.push(P);for(let t=o;t<i;t++)if(!m.has(t)){m.add(t),x=t;let s=d[t];c&&(s=`${t+1}-${s}`),a&&(s=`${a}-${s}`),$.push(s)}if(!m.has(i)){m.add(i),x=i;let t=d[i];if(T){l.lastIndex=0;for(let s=l.exec(t);s!==null;s=l.exec(t)){let L=p!==null?p:s[0],O=a?`${a}:`:"";c&&(O+=`${i+1}:`),M&&(O+=`${s.index+1}:`),$.push(O+L),s[0].length===0&&l.lastIndex++}}else{let s=t;c&&(s=`${i+1}:${s}`),a&&(s=`${a}:${s}`),$.push(s)}}let e=Math.min(y-1,i+v);for(let t=i+1;t<=e;t++)if(!m.has(t)){m.add(t),x=t;let s=d[t];c&&(s=`${t+1}-${s}`),a&&(s=`${a}-${s}`),$.push(s)}}return{output:$.length>0?`${$.join(`
|
|
8
|
-
`)}
|
|
9
|
-
`:"",matched:C>0,matchCount:C}}function D(r,l,u){let{invertMatch:f,showLineNumbers:c,countOnly:B,countMatches:j,filename:a,onlyMatching:T,beforeContext:N,afterContext:v,maxCount:w,contextSeparator:P,showColumn:M,showByteOffset:z,replace:b}=u,p=r.split(`
|
|
10
|
-
`),g=p.length,R=g>0&&p[g-1]===""?g-1:g,d=[0];for(let n=0;n<r.length;n++)r[n]===`
|
|
11
|
-
`&&d.push(n+1);let S=n=>{let i=0;for(let o=0;o<d.length&&!(d[o]>n);o++)i=o;return i},y=n=>{let i=S(n);return n-d[i]+1},$=[];l.lastIndex=0;for(let n=l.exec(r);n!==null&&!(w>0&&$.length>=w);n=l.exec(r)){let i=S(n.index),o=S(n.index+Math.max(0,n[0].length-1));$.push({startLine:i,endLine:o,byteOffset:n.index,column:y(n.index),matchText:n[0]}),n[0].length===0&&l.lastIndex++}if(B||j){let n;if(j)n=f?0:$.length;else{let o=new Set;for(let e of $)for(let t=e.startLine;t<=e.endLine;t++)o.add(t);n=f?R-o.size:o.size}return{output:`${a?`${a}:${n}`:String(n)}
|
|
12
|
-
`,matched:n>0,matchCount:n}}if(f){let n=new Set;for(let o of $)for(let e=o.startLine;e<=o.endLine;e++)n.add(e);let i=[];for(let o=0;o<R;o++)if(!n.has(o)){let e=p[o];c&&(e=`${o+1}:${e}`),a&&(e=`${a}:${e}`),i.push(e)}return{output:i.length>0?`${i.join(`
|
|
13
|
-
`)}
|
|
14
|
-
`:"",matched:i.length>0,matchCount:i.length}}if($.length===0)return{output:"",matched:!1,matchCount:0};let C=new Set,m=-1,x=[];for(let n of $){let i=Math.max(0,n.startLine-N),o=Math.min(R-1,n.endLine+v);m>=0&&i>m+1&&x.push(P);for(let e=i;e<n.startLine;e++)if(!C.has(e)){C.add(e),m=e;let t=p[e];c&&(t=`${e+1}-${t}`),a&&(t=`${a}-${t}`),x.push(t)}if(T){let e=b!==null?b:n.matchText,t=a?`${a}:`:"";z&&(t+=`${n.byteOffset}:`),c&&(t+=`${n.startLine+1}:`),M&&(t+=`${n.column}:`),x.push(t+e);for(let s=n.startLine;s<=n.endLine;s++)C.add(s),m=s}else for(let e=n.startLine;e<=n.endLine&&e<R;e++)if(!C.has(e)){C.add(e),m=e;let t=p[e];b!==null&&e===n.startLine&&(l.lastIndex=0,t=t.replace(l,b));let s=a?`${a}:`:"";z&&e===n.startLine&&(s+=`${n.byteOffset}:`),c&&(s+=`${e+1}:`),M&&e===n.startLine&&(s+=`${n.column}:`),x.push(s+t)}for(let e=n.endLine+1;e<=o;e++)if(!C.has(e)){C.add(e),m=e;let t=p[e];c&&(t=`${e+1}-${t}`),a&&(t=`${a}-${t}`),x.push(t)}}return{output:x.length>0?`${x.join(`
|
|
15
|
-
`)}
|
|
16
|
-
`:"",matched:!0,matchCount:$.length}}function F(r,l){let u;switch(l.mode){case"fixed":u=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");break;case"extended":case"perl":u=r;break;default:u=G(r);break}l.wholeWord&&(u=`(?<![\\w])(?:${u})(?![\\w])`),l.lineRegexp&&(u=`^${u}$`);let f=`g${l.ignoreCase?"i":""}${l.multilineDotall?"s":""}`;return new RegExp(u,f)}function G(r){let l="",u=0;for(;u<r.length;){let f=r[u];if(f==="\\"&&u+1<r.length){let c=r[u+1];if(c==="|"||c==="("||c===")"){l+=c,u+=2;continue}else if(c==="{"||c==="}"){l+=`\\${c}`,u+=2;continue}}f==="+"||f==="?"||f==="|"||f==="("||f===")"||f==="{"||f==="}"?l+=`\\${f}`:l+=f,u++}return l}export{A as a,F as b};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import{a as O,b as R}from"./chunk-7VH6U2UX.js";import{a as E,b as _,c as k}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var j={js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}};function P(e,t){let r=e.toLowerCase();for(let s of t){let n=j[s];if(n){for(let i of n.extensions)if(r.endsWith(i))return!0;for(let i of n.globs)if(i.includes("*")){let l=i.replace(/\./g,"\\.").replace(/\*/g,".*");if(new RegExp(`^${l}$`,"i").test(e))return!0}else if(r===i.toLowerCase())return!0}}return!1}function B(){let e=[];for(let[t,r]of Object.entries(j).sort()){let s=[];for(let n of r.extensions)s.push(`*${n}`);for(let n of r.globs)s.push(n);e.push(`${t}: ${s.join(", ")}`)}return`${e.join(`
|
|
2
|
-
`)}
|
|
3
|
-
`}function A(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,filesWithMatches:!1,filesWithoutMatch:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],types:[],typesNot:[],hidden:!1,noIgnore:!1,maxDepth:1/0,followSymlinks:!1,searchZip:!1,searchBinary:!1}}function U(e){return j[e]?null:{stdout:"",stderr:`rg: unknown type: ${e}
|
|
4
|
-
Use --type-list to see available types.
|
|
5
|
-
`,exitCode:1}}var J=[{short:"g",long:"glob",target:"globs",multi:!0},{short:"t",long:"type",target:"types",multi:!0,validate:U},{short:"T",long:"type-not",target:"typesNot",multi:!0,validate:U},{short:"m",long:"max-count",target:"maxCount",parse:parseInt},{short:"e",long:"regexp",target:"patterns",multi:!0},{short:"f",long:"file",target:"patternFiles",multi:!0},{short:"r",long:"replace",target:"replace"},{long:"max-depth",target:"maxDepth",parse:parseInt},{long:"context-separator",target:"contextSeparator"}],H={i:e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1},"--ignore-case":e=>{e.ignoreCase=!0,e.caseSensitive=!1,e.smartCase=!1},s:e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1},"--case-sensitive":e=>{e.caseSensitive=!0,e.ignoreCase=!1,e.smartCase=!1},S:e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1},"--smart-case":e=>{e.smartCase=!0,e.ignoreCase=!1,e.caseSensitive=!1},F:e=>{e.fixedStrings=!0},"--fixed-strings":e=>{e.fixedStrings=!0},w:e=>{e.wordRegexp=!0},"--word-regexp":e=>{e.wordRegexp=!0},x:e=>{e.lineRegexp=!0},"--line-regexp":e=>{e.lineRegexp=!0},v:e=>{e.invertMatch=!0},"--invert-match":e=>{e.invertMatch=!0},U:e=>{e.multiline=!0},"--multiline":e=>{e.multiline=!0},c:e=>{e.count=!0},"--count":e=>{e.count=!0},"--count-matches":e=>{e.countMatches=!0},l:e=>{e.filesWithMatches=!0},"--files-with-matches":e=>{e.filesWithMatches=!0},"--files-without-match":e=>{e.filesWithoutMatch=!0},o:e=>{e.onlyMatching=!0},"--only-matching":e=>{e.onlyMatching=!0},q:e=>{e.quiet=!0},"--quiet":e=>{e.quiet=!0},N:e=>{e.lineNumber=!1},"--no-line-number":e=>{e.lineNumber=!1},I:e=>{e.noFilename=!0},"--no-filename":e=>{e.noFilename=!0},0:e=>{e.nullSeparator=!0},"--null":e=>{e.nullSeparator=!0},b:e=>{e.byteOffset=!0},"--byte-offset":e=>{e.byteOffset=!0},"--column":e=>{e.column=!0,e.lineNumber=!0},"--vimgrep":e=>{e.vimgrep=!0,e.column=!0,e.lineNumber=!0},"--json":e=>{e.json=!0},"--hidden":e=>{e.hidden=!0},"--no-ignore":e=>{e.noIgnore=!0},L:e=>{e.followSymlinks=!0},"--follow":e=>{e.followSymlinks=!0},z:e=>{e.searchZip=!0},"--search-zip":e=>{e.searchZip=!0},a:e=>{e.searchBinary=!0},"--text":e=>{e.searchBinary=!0},"--heading":e=>{e.heading=!0},"--passthru":e=>{e.passthru=!0},"--include-zero":e=>{e.includeZero=!0}},V=new Set(["n","--line-number"]);function X(e){e.hidden?e.searchBinary=!0:e.noIgnore?e.hidden=!0:e.noIgnore=!0}function K(e,t,r){let s=e[t];for(let n of J){if(s.startsWith(`--${n.long}=`)){let i=s.slice(`--${n.long}=`.length),l=D(r,n,i);return l?{newIndex:t,error:l}:{newIndex:t}}if(n.short&&s===`-${n.short}`||s===`--${n.long}`){if(t+1>=e.length)return null;let i=e[t+1],l=D(r,n,i);return l?{newIndex:t+1,error:l}:{newIndex:t+1}}}return null}function D(e,t,r){if(t.validate){let n=t.validate(r);if(n)return n}let s=t.parse?t.parse(r):r;t.multi?e[t.target].push(s):e[t.target]=s}function Q(e,t){let r=e[t];if(r==="--sort"&&t+1<e.length){let s=e[t+1];if(s==="path"||s==="none")return{value:s,newIndex:t+1}}if(r.startsWith("--sort=")){let s=r.slice(7);if(s==="path"||s==="none")return{value:s,newIndex:t}}return null}function ee(e,t){let r=e[t],s=r.match(/^-([ABC])(\d+)$/);return s?{flag:s[1],value:parseInt(s[2],10),newIndex:t}:(r==="-A"||r==="-B"||r==="-C")&&t+1<e.length?{flag:r[1],value:parseInt(e[t+1],10),newIndex:t+1}:null}function te(e){let t=e.match(/^-m(\d+)$/);return t?parseInt(t[1],10):null}function q(e){let t=A(),r=null,s=[],n=-1,i=-1,l=-1,o=!1;for(let a=0;a<e.length;a++){let c=e[a];if(c.startsWith("-")&&c!=="-"){let u=ee(e,a);if(u){let{flag:f,value:m,newIndex:x}=u;f==="A"?n=Math.max(n,m):f==="B"?i=Math.max(i,m):l=m,a=x;continue}let h=te(c);if(h!==null){t.maxCount=h;continue}let d=K(e,a,t);if(d){if(d.error)return{success:!1,error:d.error};a=d.newIndex;continue}let g=Q(e,a);if(g){t.sort=g.value,a=g.newIndex;continue}let p=c.startsWith("--")?[c]:c.slice(1).split("");for(let f of p){if(V.has(f)){t.lineNumber=!0,o=!0;continue}if(f==="u"||f==="--unrestricted"){X(t);continue}let m=H[f];if(m){m(t);continue}if(f.startsWith("--"))return{success:!1,error:k("rg",f)};if(f.length===1)return{success:!1,error:k("rg",`-${f}`)}}}else r===null?r=c:s.push(c)}return(n>=0||l>=0)&&(t.afterContext=Math.max(n>=0?n:0,l>=0?l:0)),(i>=0||l>=0)&&(t.beforeContext=Math.max(i>=0?i:0,l>=0?l:0)),r!==null&&t.patterns.push(r),(t.column||t.vimgrep)&&(o=!0),{success:!0,options:t,paths:s,explicitLineNumbers:o}}import{gunzipSync as se}from"node:zlib";var W=class{patterns=[];basePath;constructor(t="/"){this.basePath=t}parse(t){let r=t.split(`
|
|
6
|
-
`);for(let s of r){let n=s.replace(/\s+$/,"");if(!n||n.startsWith("#"))continue;let i=!1;n.startsWith("!")&&(i=!0,n=n.slice(1));let l=!1;n.endsWith("/")&&(l=!0,n=n.slice(0,-1));let o=!1;n.startsWith("/")?(o=!0,n=n.slice(1)):n.includes("/")&&!n.startsWith("**/")&&(o=!0);let a=this.patternToRegex(n,o);this.patterns.push({pattern:s,regex:a,negated:i,directoryOnly:l,rooted:o})}}patternToRegex(t,r){let s="";r?s="^":s="(?:^|/)";let n=0;for(;n<t.length;){let i=t[n];if(i==="*")t[n+1]==="*"?t[n+2]==="/"?(s+="(?:.*/)?",n+=3):(n+2>=t.length,s+=".*",n+=2):(s+="[^/]*",n++);else if(i==="?")s+="[^/]",n++;else if(i==="["){let l=n+1;for(l<t.length&&t[l]==="!"&&l++,l<t.length&&t[l]==="]"&&l++;l<t.length&&t[l]!=="]";)l++;if(l<t.length){let o=t.slice(n,l+1);o.startsWith("[!")&&(o=`[^${o.slice(2)}`),s+=o,n=l+1}else s+="\\[",n++}else i==="/"?(s+="/",n++):(s+=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n++)}return s+="(?:/.*)?$",new RegExp(s)}matches(t,r){let s=t.replace(/^\.\//,"");s=s.replace(/^\//,"");let n=!1;for(let i of this.patterns)i.directoryOnly&&!r||i.regex.test(s)&&(n=!i.negated);return n}getBasePath(){return this.basePath}},M=class{parsers=[];fs;rootPath;constructor(t,r){this.fs=t,this.rootPath=r}async load(t){let r=[],s=t;for(;s.startsWith(this.rootPath)||s===this.rootPath;){r.unshift(s);let n=this.fs.resolvePath(s,"..");if(n===s)break;s=n}for(let n of r)for(let i of[".gitignore",".ignore"]){let l=this.fs.resolvePath(n,i);try{let o=await this.fs.readFile(l),a=new W(n);a.parse(o),this.parsers.push(a)}catch{}}}matches(t,r){for(let s of this.parsers){let n=s.getBasePath();if(!t.startsWith(n))continue;let i=t.slice(n.length).replace(/^\//,"");if(s.matches(i,r))return!0}return!1}static isCommonIgnored(t){return new Set(["node_modules",".git",".svn",".hg","__pycache__",".pytest_cache",".mypy_cache","venv",".venv","dist","build",".next",".nuxt","target",".cargo"]).has(t)}};async function z(e,t){let r=new M(e,t);return await r.load(t),r}function ne(e){return e.length>=2&&e[0]===31&&e[1]===139}async function G(e){let{ctx:t,options:r,paths:s,explicitLineNumbers:n}=e,i=[...r.patterns];for(let p of r.patternFiles)try{let f=t.fs.resolvePath(t.cwd,p),x=(await t.fs.readFile(f)).split(`
|
|
7
|
-
`).filter(y=>y.length>0);i.push(...x)}catch{return{stdout:"",stderr:`rg: ${p}: No such file or directory
|
|
8
|
-
`,exitCode:2}}if(i.length===0)return{stdout:"",stderr:`rg: no pattern given
|
|
9
|
-
`,exitCode:2};let l=s.length===0?["."]:s,o=re(r,i),a;try{a=ie(i,r,o)}catch{return{stdout:"",stderr:`rg: invalid regex: ${i.join(", ")}
|
|
10
|
-
`,exitCode:2}}let c=null;r.noIgnore||(c=await z(t.fs,t.cwd));let{files:u,singleExplicitFile:h}=await le(t,l,r,c);if(u.length===0)return{stdout:"",stderr:"",exitCode:1};let d=!r.noFilename&&(!h||u.length>1),g=r.lineNumber;return n||(h&&u.length===1&&(g=!1),r.onlyMatching&&(g=!1)),oe(t,u,a,r,d,g)}function re(e,t){return e.caseSensitive?!1:e.ignoreCase?!0:e.smartCase?!t.some(r=>/[A-Z]/.test(r)):!1}function ie(e,t,r){let s;return e.length===1?s=e[0]:s=e.map(n=>t.fixedStrings?n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):`(?:${n})`).join("|"),R(s,{mode:t.fixedStrings&&e.length===1?"fixed":"perl",ignoreCase:r,wholeWord:t.wordRegexp,lineRegexp:t.lineRegexp,multiline:t.multiline})}async function le(e,t,r,s){let n=[],i=0,l=0;for(let a of t){let c=e.fs.resolvePath(e.cwd,a);try{let u=await e.fs.stat(c);u.isFile?(i++,Y(a,r,s,c)&&n.push(a)):u.isDirectory&&(l++,await Z(e,a,c,0,r,s,n))}catch{}}return{files:r.sort==="path"?n.sort():n,singleExplicitFile:i===1&&l===0}}async function Z(e,t,r,s,n,i,l){if(!(s>=n.maxDepth))try{let o=e.fs.readdirWithFileTypes?await e.fs.readdirWithFileTypes(r):(await e.fs.readdir(r)).map(a=>({name:a,isFile:void 0}));for(let a of o){let c=a.name;if(!n.hidden&&c.startsWith(".")||!n.noIgnore&&M.isCommonIgnored(c))continue;let u=t==="."?c:`${t}/${c}`,h=e.fs.resolvePath(r,c),d,g,p=!1;if(a.isFile!==void 0&&"isDirectory"in a){let m=a;if(p=m.isSymbolicLink===!0,p&&!n.followSymlinks)continue;if(p&&n.followSymlinks)try{let x=await e.fs.stat(h);d=x.isFile,g=x.isDirectory}catch{continue}else d=m.isFile,g=m.isDirectory}else try{let m=e.fs.lstat?await e.fs.lstat(h):await e.fs.stat(h);if(p=m.isSymbolicLink===!0,p&&!n.followSymlinks)continue;let x=p&&n.followSymlinks?await e.fs.stat(h):m;d=x.isFile,g=x.isDirectory}catch{continue}i?.matches(h,g)||(g?await Z(e,u,h,s+1,n,i,l):d&&Y(u,n,i,h)&&l.push(u))}}catch{}}function Y(e,t,r,s){let n=e.split("/").pop()||e;if(r?.matches(s,!1)||t.types.length>0&&!P(n,t.types)||t.typesNot.length>0&&P(n,t.typesNot))return!1;if(t.globs.length>0){let i=t.globs.filter(o=>!o.startsWith("!")),l=t.globs.filter(o=>o.startsWith("!")).map(o=>o.slice(1));if(i.length>0){let o=!1;for(let a of i)if(I(n,a)||I(e,a)){o=!0;break}if(!o)return!1}for(let o of l)if(o.startsWith("/")){let a=o.slice(1);if(I(e,a))return!1}else if(I(n,o)||I(e,o))return!1}return!0}function I(e,t){let r="^";for(let s=0;s<t.length;s++){let n=t[s];if(n==="*")t[s+1]==="*"?(r+=".*",s++):r+="[^/]*";else if(n==="?")r+="[^/]";else if(n==="["){let i=s+1;for(i<t.length&&t[i]==="!"&&i++,i<t.length&&t[i]==="]"&&i++;i<t.length&&t[i]!=="]";)i++;if(i<t.length){let l=t.slice(s,i+1);l.startsWith("[!")&&(l=`[^${l.slice(2)}`),r+=l,s=i}else r+="\\["}else r+=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}return r+="$",new RegExp(r).test(e)}async function ae(e,t,r,s){try{if(s.searchZip&&r.endsWith(".gz")){let l=await e.fs.readFileBuffer(t);if(ne(l))try{let o=se(l),a=new TextDecoder().decode(o),c=a.slice(0,8192);return{content:a,isBinary:c.includes("\0")}}catch{return null}}let n=await e.fs.readFile(t),i=n.slice(0,8192);return{content:n,isBinary:i.includes("\0")}}catch{return null}}async function oe(e,t,r,s,n,i){let l="",o=!1,a=[],c=0,u=0,h=0,d=50;e:for(let f=0;f<t.length;f+=d){let m=t.slice(f,f+d),x=await Promise.all(m.map(async y=>{let S=e.fs.resolvePath(e.cwd,y),w=await ae(e,S,y,s);if(!w)return null;let{content:b,isBinary:N}=w;if(h+=b.length,N&&!s.searchBinary)return null;let F=n&&!s.heading?y:"",C=O(b,r,{invertMatch:s.invertMatch,showLineNumbers:i,countOnly:s.count,countMatches:s.countMatches,filename:F,onlyMatching:s.onlyMatching,beforeContext:s.beforeContext,afterContext:s.afterContext,maxCount:s.maxCount,contextSeparator:s.contextSeparator,showColumn:s.column,vimgrep:s.vimgrep,showByteOffset:s.byteOffset,replace:s.replace,passthru:s.passthru,multiline:s.multiline});return s.json&&C.matched?{file:y,result:C,content:b,isBinary:!1}:{file:y,result:C}}));for(let y of x){if(!y)continue;let{file:S,result:w}=y;if(w.matched){if(o=!0,u++,c+=w.matchCount,s.quiet&&!s.json)break e;if(s.json&&!s.quiet){let b=y.content||"";a.push(JSON.stringify({type:"begin",data:{path:{text:S}}}));let N=b.split(`
|
|
11
|
-
`);r.lastIndex=0;let F=0;for(let C=0;C<N.length;C++){let $=N[C];r.lastIndex=0;let T=[];for(let v=r.exec($);v!==null;v=r.exec($)){let L={match:{text:v[0]},start:v.index,end:v.index+v[0].length};s.replace!==null&&(L.replacement={text:s.replace}),T.push(L),v[0].length===0&&r.lastIndex++}if(T.length>0){let v={type:"match",data:{path:{text:S},lines:{text:`${$}
|
|
12
|
-
`},line_number:C+1,absolute_offset:F,submatches:T}};a.push(JSON.stringify(v))}F+=$.length+1}a.push(JSON.stringify({type:"end",data:{path:{text:S},binary_offset:null,stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:1,searches_with_match:1,bytes_searched:b.length,bytes_printed:0,matched_lines:w.matchCount,matches:w.matchCount}}}))}else if(s.filesWithMatches){let b=s.nullSeparator?"\0":`
|
|
13
|
-
`;l+=`${S}${b}`}else s.filesWithoutMatch||(s.heading&&n&&(l+=`${S}
|
|
14
|
-
`),l+=w.output)}else if(s.filesWithoutMatch){let b=s.nullSeparator?"\0":`
|
|
15
|
-
`;l+=`${S}${b}`}else s.includeZero&&(s.count||s.countMatches)&&(l+=w.output)}}s.json&&(a.push(JSON.stringify({type:"summary",data:{elapsed_total:{secs:0,nanos:0,human:"0s"},stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:t.length,searches_with_match:u,bytes_searched:h,bytes_printed:0,matched_lines:c,matches:c}}})),l=`${a.join(`
|
|
16
|
-
`)}
|
|
17
|
-
`);let g=s.quiet&&!s.json?"":l,p;return s.filesWithoutMatch?p=l.length>0?0:1:p=o?0:1,{stdout:g,stderr:"",exitCode:p}}var ce={name:"rg",summary:"recursively search for a pattern",usage:"rg [OPTIONS] PATTERN [PATH ...]",description:`rg (ripgrep) recursively searches directories for a regex pattern.
|
|
18
|
-
Unlike grep, rg is recursive by default and respects .gitignore files.
|
|
19
|
-
|
|
20
|
-
EXAMPLES:
|
|
21
|
-
rg foo Search for 'foo' in current directory
|
|
22
|
-
rg foo src/ Search in src/ directory
|
|
23
|
-
rg -i foo Case-insensitive search
|
|
24
|
-
rg -w foo Match whole words only
|
|
25
|
-
rg -t js foo Search only JavaScript files
|
|
26
|
-
rg -g '*.ts' foo Search files matching glob
|
|
27
|
-
rg --hidden foo Include hidden files
|
|
28
|
-
rg -l foo List files with matches only`,options:["-e, --regexp PATTERN search for PATTERN (can be used multiple times)","-f, --file FILE read patterns from FILE, one per line","-i, --ignore-case case-insensitive search","-s, --case-sensitive case-sensitive search (overrides smart-case)","-S, --smart-case smart case (default: case-insensitive unless pattern has uppercase)","-F, --fixed-strings treat pattern as literal string","-w, --word-regexp match whole words only","-x, --line-regexp match whole lines only","-v, --invert-match select non-matching lines","-r, --replace TEXT replace matches with TEXT","-c, --count print count of matching lines per file"," --count-matches print count of individual matches per file","-l, --files-with-matches print only file names with matches"," --files-without-match print file names without matches","-o, --only-matching print only matching parts","-m, --max-count NUM stop after NUM matches per file","-q, --quiet suppress output, exit 0 on match","-n, --line-number print line numbers (default: on)","-N, --no-line-number do not print line numbers","-I, --no-filename suppress the prefixing of file names","-0, --null use NUL as filename separator","-b, --byte-offset show byte offset of each match"," --column show column number of first match"," --vimgrep show results in vimgrep format"," --json show results in JSON Lines format","-A NUM print NUM lines after each match","-B NUM print NUM lines before each match","-C NUM print NUM lines before and after each match"," --context-separator SEP separator for context groups (default: --)","-U, --multiline match patterns across lines","-z, --search-zip search in compressed files (gzip only)","-g, --glob GLOB include files matching GLOB","-t, --type TYPE only search files of TYPE (e.g., js, py, ts)","-T, --type-not TYPE exclude files of TYPE","-L, --follow follow symbolic links","-u, --unrestricted reduce filtering (-u: no ignore, -uu: +hidden, -uuu: +binary)","-a, --text search binary files as text"," --hidden search hidden files and directories"," --no-ignore don't respect .gitignore/.ignore files"," --max-depth NUM maximum search depth"," --sort TYPE sort files (path, none)"," --heading show file path above matches"," --passthru print all lines (non-matches use - separator)"," --include-zero include files with 0 matches in count output"," --type-list list all available file types"," --help display this help and exit"]},Ne={name:"rg",async execute(e,t){if(_(e))return E(ce);if(e.includes("--type-list"))return{stdout:B(),stderr:"",exitCode:0};let r=q(e);return r.success?G({ctx:t,options:r.options,paths:r.paths,explicitLineNumbers:r.explicitLineNumbers}):r.error}};export{Ne as rgCommand};
|