refactor start

This commit is contained in:
Spectre 2025-02-18 11:19:45 +01:00
parent bd49791e06
commit e46d25f0b7
16699 changed files with 2 additions and 1484887 deletions

View file

@ -1,48 +0,0 @@
import GLib from "gi://GLib?version=2.0"
import { bash, dependencies } from "lib/utils"
import icons from "lib/icons"
import options from "options"
const MAX = options.launcher.sh.max
const BINS = `${Utils.CACHE_DIR}/binaries`
async function ls(path: string) {
return Utils.execAsync(`ls ${path}`).catch(() => "")
}
async function reload() {
const bins = await Promise.all(GLib.getenv("PATH")!
.split(":")
.map(ls))
Utils.writeFile(bins.join("\n"), BINS)
}
async function query(filter: string) {
if (!dependencies("fzf"))
return [] as string[]
return bash(`cat ${BINS} | fzf -f ${filter} | head -n ${MAX}`)
.then(str => Array.from(new Set(str.split("\n").filter(i => i)).values()))
.catch(err => { print(err); return [] })
}
function run(args: string) {
Utils.execAsync(args)
.then(out => {
print(`:sh ${args.trim()}:`)
print(out)
})
.catch(err => {
Utils.notify("ShRun Error", err, icons.app.terminal)
})
}
class Sh extends Service {
static { Service.register(this) }
constructor() { super(); reload() }
query = query
run = run
}
export default new Sh