From 6d68e6f91c55414c857414d8cdd5f47fd480ec28 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Fri, 28 Apr 2023 21:11:47 -0700 Subject: [PATCH] shell command helper tool Signed-off-by: Ava Hahn --- snippets/genbind.rls | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 snippets/genbind.rls diff --git a/snippets/genbind.rls b/snippets/genbind.rls new file mode 100644 index 0000000..f7cf74a --- /dev/null +++ b/snippets/genbind.rls @@ -0,0 +1,42 @@ +#!/bin/relish + +;; relish: versatile lisp shell +;; Copyright (C) 2021 Aidan Hahn +;; +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;; GENBIND + +(def gen-binding +"Takes two arguments: a symbol (use quote) and a string token + The symbol should coorespond to a binary on the path (else command will fail) + The string token is taken to be an argument to that command + A lambda is then made which accepts a list of additional arguments. + When called, the resulting function will construct and execute a call to load + +The point is to be able to autogenerate bindings for shell commands. +Example: (eval ((gen-binding (q ls) '-l') ('-a'))) + Or: (def gcommit 'shortcut for git commit -s -m + (lambda (arg) (eval ((gen-binding (q git) 'commit') ('-s' '-m' arg)))))" + (sym subcommand) + (let ((lam ((q lambda) + (cons (q args)) + (cons let (((q func-call) (cons cons (q l) (cons q sym) subcommand)) + ((q arg-iter) (cons pop (q args)))) + (cons while (cons gt? (cons len (q arg-iter)) 1) + (cons set (cons q (q func-call)) (cons cons (q func-call) (cons car (q arg-iter)))) + (cons set (cons q (q arg-iter)) (cons pop (cons cdr (q arg-iter))))) + (cons echo '+ ' (cons cdr (cons pop (q func-call)))) + (cons eval (q func-call)))))) + (eval lam))) \ No newline at end of file