|
1 | 1 | #!/usr/bin/env node |
2 | | - |
3 | 2 | import { Command } from 'commander'; |
4 | 3 | import readline from 'readline'; |
5 | 4 | import fs, { read } from 'fs'; |
6 | 5 | import path, { resolve } from 'path'; |
7 | 6 | import clipboardy from 'clipboardy'; |
8 | 7 | import { json } from 'stream/consumers'; |
| 8 | +import Fuse from 'fuse.js'; |
9 | 9 | // const {PrismaClient}=require(`@prisma/client`); |
10 | 10 | const DATA_FILE=path.resolve('./snippet.json'); |
11 | 11 |
|
@@ -223,7 +223,33 @@ program |
223 | 223 | }) |
224 | 224 | }); |
225 | 225 |
|
226 | | -// search snippet |
| 226 | +// search snippet (OLDER) |
| 227 | +// program |
| 228 | +// .command('search-snippet') |
| 229 | +// .description('search for the snippet you are looking for on the basis of language,keywords and tags') |
| 230 | +// .option('-l,--lang<language>','Filter on the basis of programming language') |
| 231 | +// .option('-k,--key<keyword>','Filter on the basis of keywords used') |
| 232 | +// .option(`--tags <tags>`, `New comma-separated tags`, val => val.split(`,`)) |
| 233 | + |
| 234 | +// .action((options)=>{ |
| 235 | +// const snippets=loadSnippets(); |
| 236 | +// const matches=snippets.filter(snippet=>{ |
| 237 | +// const matchlang =options.lang? options.lang===snippet.lang:true; |
| 238 | +// const matchtag =options.tag?snippet.tag?.includes(options.tag):true; |
| 239 | +// const matchkey=options.keywords?fs.readFileSync(path.resolve(filePath),'utf-8').includes(options.keywords):true; |
| 240 | + |
| 241 | +// return matchlang && matchtag && matchkey; |
| 242 | +// }); |
| 243 | +// if(!matches.length) return console.log("Snippet not found"); |
| 244 | +// matches.forEach((s,i)=>{ |
| 245 | +// console.log(`\n ${i+1}. ${s.name}[${s.lang}]`); |
| 246 | +// console.log(`Tags: ${snippets.tags?.join(', ')}`); |
| 247 | +// console.log(`File: ${s.file}`); |
| 248 | +// console.log('-----------------------------'); |
| 249 | +// }) |
| 250 | +// }) |
| 251 | + |
| 252 | +//Search snippet FUZZY |
227 | 253 | program |
228 | 254 | .command('search-snippet') |
229 | 255 | .description('search for the snippet you are looking for on the basis of language,keywords and tags') |
|
0 commit comments