From d9fdf1ee6d7ca1c1544f89ed7bc73e3f3ec4c450 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Thu, 10 Apr 2025 15:00:57 +0200 Subject: [PATCH] [Launcher] Add helper for fzf --- config/ags/launcher/helpers/fzf/dist/fzf.js | 32 +++++++++++++++++++ config/ags/launcher/helpers/fzf/package.json | 18 +++++++++++ config/ags/launcher/helpers/fzf/src/fzf.ts | 27 ++++++++++++++++ config/ags/launcher/helpers/fzf/tsconfig.json | 13 ++++++++ config/ags/launcher/util/fzf.ts | 4 ++- 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 config/ags/launcher/helpers/fzf/dist/fzf.js create mode 100644 config/ags/launcher/helpers/fzf/package.json create mode 100644 config/ags/launcher/helpers/fzf/src/fzf.ts create mode 100644 config/ags/launcher/helpers/fzf/tsconfig.json diff --git a/config/ags/launcher/helpers/fzf/dist/fzf.js b/config/ags/launcher/helpers/fzf/dist/fzf.js new file mode 100644 index 0000000..c240cf7 --- /dev/null +++ b/config/ags/launcher/helpers/fzf/dist/fzf.js @@ -0,0 +1,32 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const fast_fuzzy_1 = require("fast-fuzzy"); +const fs_1 = __importDefault(require("fs")); +// Get list source from args +// ARGS: type source +// Then we read query from stdin to not restart indexing & the like for each keystroke +let data = []; +if (process.argv[2] === 'fs') { + if (process.argv[3].includes('.json')) { + data = JSON.parse('' + fs_1.default.readFileSync(process.argv[3])); + } + else if (process.argv[3].includes('.txt')) { + data = ('' + fs_1.default.readFileSync(process.argv[3])).split(','); + } + else if (fs_1.default.statSync(process.argv[3]).isDirectory()) { + data = fs_1.default.readdirSync(process.argv[3]); + } +} +else if (process.argv[2] === 'arg') { + data = process.argv[3].split(','); +} +else { + throw new Error('Invalid argument at position 1. Can be either fs or arg, not ' + process.argv[2]); +} +process.stdin.on("data", (query) => { + // On stdin submit (which the other client will have to support) process data + console.log((0, fast_fuzzy_1.search)(query.toString(), data)); +}); diff --git a/config/ags/launcher/helpers/fzf/package.json b/config/ags/launcher/helpers/fzf/package.json new file mode 100644 index 0000000..44e0339 --- /dev/null +++ b/config/ags/launcher/helpers/fzf/package.json @@ -0,0 +1,18 @@ +{ + "name": "fzf", + "version": "1.0.0", + "description": "", + "license": "ISC", + "author": "", + "type": "commonjs", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "devDependencies": { + "@types/node": "^22.14.0" + }, + "dependencies": { + "fast-fuzzy": "^1.12.0" + } +} diff --git a/config/ags/launcher/helpers/fzf/src/fzf.ts b/config/ags/launcher/helpers/fzf/src/fzf.ts new file mode 100644 index 0000000..09e5173 --- /dev/null +++ b/config/ags/launcher/helpers/fzf/src/fzf.ts @@ -0,0 +1,27 @@ +import { search } from 'fast-fuzzy'; +import fs from 'fs'; + +// Get list source from args +// ARGS: type source +// Then we read query from stdin to not restart indexing & the like for each keystroke + +let data: string[] = []; +if ( process.argv[ 2 ] === 'fs' ) { + if ( process.argv[ 3 ].includes( '.json' ) ) { + data = JSON.parse( '' + fs.readFileSync( process.argv[ 3 ] ) ); + } else if ( process.argv[ 3 ].includes( '.txt' ) ) { + data = ( '' + fs.readFileSync( process.argv[ 3 ] ) ).split( ',' ); + } else if ( fs.statSync( process.argv[ 3 ] ).isDirectory() ) { + data = fs.readdirSync( process.argv[ 3 ] ); + } +} else if ( process.argv[ 2 ] === 'arg' ) { + data = process.argv[ 3 ].split( ',' ); +} else { + throw new Error( 'Invalid argument at position 1. Can be either fs or arg, not ' + process.argv[ 2 ] ); +} + +process.stdin.on( "data", ( query ) => { + // On stdin submit (which the other client will have to support) process data + + console.log( search( query.toString(), data ) ); +} ); diff --git a/config/ags/launcher/helpers/fzf/tsconfig.json b/config/ags/launcher/helpers/fzf/tsconfig.json new file mode 100644 index 0000000..a0fcf4c --- /dev/null +++ b/config/ags/launcher/helpers/fzf/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "outDir": "./dist", + "allowJs": true, + "target": "ES6", + "skipLibCheck": true, + "allowSyntheticDefaultImports": true, + "types": ["node"], + "module": "NodeNext", + "moduleResolution": "NodeNext" + }, + "include": [ "./src/**/*" ], +} \ No newline at end of file diff --git a/config/ags/launcher/util/fzf.ts b/config/ags/launcher/util/fzf.ts index 380daf9..5951070 100644 --- a/config/ags/launcher/util/fzf.ts +++ b/config/ags/launcher/util/fzf.ts @@ -15,7 +15,9 @@ const fzfApplication = ( query: string ) => { return apps.fuzzy_query( query ); } -const fzfCmd = ( query: string ) => {} +const fzfCmd = ( query: string ) => { + +} export default { fzfApplication