├── .gashrc
├── LICENSE
├── README.md
├── conf
├── configure
├── gash-base-lib
├── gash-code.scm
├── history.scm
├── libgash.c
└── reference.org
/.gashrc:
--------------------------------------------------------------------------------
1 | (define-shorthand "ls" "ls --color")
2 |
3 | (define (fmt string . args)
4 | (format #f string args))
5 |
6 | (set! scheme-switch #\§)
7 |
8 | (define-history-rule (lambda (txt) #t))
9 |
10 | (define-builtin "cd.."
11 | (lambda (lst)
12 | (chdir "..")
13 | (cdr lst)))
14 |
15 | (define ($ string)
16 | "splices in the resut of running string and collecting its output. We assume
17 | string is a viable shell command. "
18 | (let* ((port (open-input-pipe string))
19 | (strs (get-string-all port)))
20 | (close-port port)
21 | strs))
22 |
23 | (define (color-fmt color string . newline)
24 | (if (equal? (car newline) #f)
25 | (format #f "\\033[38;5;~Am~A\\033[0m" color string)
26 | (format #f "\\033[38;5;~Am~A\\033[0m\n" color string)))
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GASH
2 |
3 | GASH is in very early development. commands may change - the api shouldnt be considered stable.
4 |
5 | GASH is a shell based on guile scheme. However, its not exactly a shell. Its more of an interpretation layer. The main purpose of GASH is to allow scheme code to be spliced in, via §. for example: `$ echo '§(format #f "welcome, ~a! the pwd is ~a" user-at-host (getcwd))'` This would be parsed, and turned into `echo 'welcome, my-username@my-computer! the pwd is /home/my-username'` before being fed into sh. We send it into sh, but we could just as easily write shell functionalities in c, and use those instead.
6 |
7 | ## Why Should I Care and/or Use GASH?
8 |
9 | Because its FUN! For basic shell usage, it works just fine, same as bash, except for completions following an opening paren complete guile. It lets you use scheme from the command line with a simple switch character to either things for side effects or splicing in text. The only place it really falls flat on its face is in completions on things with spaces in them.
10 |
11 | ## Installation
12 |
13 | Clone this repo, and ensure guile is installed to /usr/bin/guile. CD into the GASH directory. What you do depends on how you want to install GASH; here are the flags and what they do:
14 |
15 | Commands to use/install gash:
16 | * --generate; --generate builds `libgash.so` and assembles gash-code.scm and history.scm into a single file which is then set to be executable. If --local is passed, it must be before --generate.
17 | * --install; --install does the same thing as --generate except it also installs the file made by --generate to `execdir`. if --local is passed, it must be passed before --install. First, we copy `single-file-name` to `/execdir/exececutable-name`. If local is true,thats all we do, otherwise we also copy our libraries to `libsdir`.
18 |
19 | Commands to control how we generate and install gash:
20 | * --local; --local should be passed to control the whether we want things to load from the git directory, or we want to load things from `libsdir`. It should also pass either a `y` or an `n` to determine whether or not to load from `libsdir`. If we dont pass local, it is assumed to be true. This flag controls the `local?` variable.
21 | * --set-libsdir; this sets `libsdir` to the string following the flag. `libsdir` is the path to where our libraries will be put and loaded from if `local?` is false.
22 | * --set-execdir; this sets `execdir`, which is where we will copy our gash executable to when installing.
23 | * --set-single-file-name; this sets the filename to write to for the generation stage - the assembled file is saved under `single-file-name`, and will overwrite any file of the same name. The default is `gash-local`.
24 | * --set-install-name; this sets the name of our executable when we install with the --install flag.
25 |
26 | The first time you run GASH, it will be compiled into guile vm code, which shouldnt take more than a minute (it takes ~ 5 seconds on a dual core celeron from 2009 at 1.6ghz)
27 |
28 | ## Usage
29 |
30 | GASH has several functionalities. Firstly, text is read in via gnu readline. Next, the scheme sections(§) are replaced. Following that, the string is split into tokens. At this point we handle builtins, which you can define. Then user defined shorthand is replaced, and finally, its executed via /bin/sh (which is sometimes symlinked to bash). If the string begins with an opening paren, it is treated as a scheme string, and its tokenized, shorthand replaced, and joined back up before being passed to guile.
31 |
32 | GASH reads from a user directory, ~/.gashrc, where one can define whatever is needed. As GASH uses readline, ~/.inputrc is also read and respected.
33 |
34 | To change the character to switch to scheme to a comma, place `(set! scheme-switch #\,)` in you ~/.gashrc.
35 |
36 | ### §(...)
37 |
38 | Conceptually, this is rather simple. If the toplevel form following § is a string, the § and form is replaced by its evaluation. Otherwise, it is assumed to be run for the side effects, in which case it is replaced by an empty string.
39 |
40 | ### Builtins
41 |
42 | GASH handles builtins a little funkily. This is due to GASH parsing a string and then passing it off to sh, instead of forking and exec-ing on its own. Builtins are only recognized if they're in the first position.
43 |
44 | The builtins are held in an alist, and consist of a name as a string and a lambda, which takes a list, and returns a list.
45 | One can define a builtin like so: `(define-builtin "my-builtin" (lambda (lst) (my-func) '()))`.
46 | Regarding the lambda; The lambda will be called with the full command line, tokenized, and must return anything that they want executed, as a tokenized list. For example, if I defined some builtin that changed the current directory, I might return `'("ls" "--color" "-a")` in order to list the new current directory.
47 |
48 | ### Shorthand
49 |
50 | Shorthand is like the alias of GASH. The last step before un-tokenizing is to replace any shorthand with its longhand. We check every token against the list of shorthand the user has defined, and whenever we encounter one that matches it is replaced with its appropriate longhand. There is one predefined shorthand, which changes any instance of "ls" with "ls --color". If a user wants to rid themselves of this behaviore, they can run `(define-shorthand "ls" "ls")` to reset it.
51 |
52 | ## Completions
53 |
54 | GASH doesnt use the regular guile readline extension, instead building a similar system within libgash.c. This allows us to be more hands on with completions. Currently, we have a set of rules for our default completions in the variable default-gash-completer. The earlier a rule occurs in the cond statement, the higher priority it is. eg if you have two conflicting rules, the first one to match is the one used. So, if a word begins with our switch followed by an opening paren, or just a paren, we use guiles apropos completion function. Otherwise, if were at the start of the line (ie working on the first word) we complete based on commands, and finally we otherwise complete based on the default file completion function.
55 |
56 | ## Wanted Features
57 |
58 | There are a couple features we will be wanting in GASH. The following is an unordered list of wanted features. If you have an idea for implementing any of them, open a pull request.
59 | 1. More meaningful shell interaction. Write better interaction functions between shell and guile. Since the § has augmented pipes so much, it seems only right to have a $, which runs a shell command, collecting its output. This functionality is already implemented in gash-base-lib as collect-shell-command, but could be improved and gussied up. For example, send the string send in through our parser for guile, in a mutually recursive manner, so we can do `§(fun $[echo '§(otherfun $[ls -al])'])` and have everything be expanded propperly. The prior syntax is only a suggestion.
60 |
61 | ## Issues and Quirks
62 |
63 | There are some issues with readline, specifically with reading over a certain length, and skipping back to the beginning of the line with C-a. I'm no C wizard, and theres probably things that could be done I dont know of. I think looking to the Bash usage of readline would be a good start.
64 |
65 | There are a couple quirks. Firstly, as GASH accessorizes the shell, and isnt itself a shell, there end up being some oddities with running it as your default shell. Since its not technically a shell, its not in /etc/shells, so you cant just set it as a default. Another way of launching might be to run `xterm -e /path/to/gash`, but this doesnt work either. The only way of launching, currently, is to open a terminal and run it from there.
66 |
67 | Another quirk is strings. When you switch to scheme mode, and call a shell command (generally via (sh "...")) you need to make sure to escape strings. Take this example call: `$ echo '§(format #f "~a" (sh "ls §(format #f "/home")"))'` This call will error out, due to misquoted strings. Because the inner format contains a string while being contained within a string, the inner string needs to be escaped, like so: `$ echo '§(format #f "~a" (sh "ls §(format #f \"/home\")"))'`.
68 | Of course, this is all moot as sh and § dont play well yet.
--------------------------------------------------------------------------------
/conf:
--------------------------------------------------------------------------------
1 | #!/usr/bin/guile \
2 | -l gash-base-lib -e main -s
3 | !#
4 |
5 | (use-modules (ice-9 format)
6 | (ice-9 popen)
7 | (ice-9 rdelim)
8 | (ice-9 textual-ports)
9 | (ice-9 session)
10 | (ice-9 regex)
11 | (ice-9 buffered-input))
12 |
13 | (define cc "gcc")
14 | (define cflags "`pkg-config --cflags readline guile-2.2`")
15 | (define execdir "/usr/local/bin")
16 | (define libsdir "/usr/local/lib")
17 | (define single-file-name "gash-local")
18 | (define local? #t)
19 | (define executable-name "gash")
20 |
21 | (define (build-libgash.so)
22 | (echo "Compiling libgash.so")
23 | (system-fmt
24 | "~a ~a -shared -o libgash.so -fPIC libgash.c -l readline" cc cflags)
25 | (echo "libgash.so compiled"))
26 |
27 | (let ((extension-path (format #f "~a/libgash.so" (getcwd)))
28 | (init-function "init_gash_c"))
29 | (catch #t
30 | (lambda () (load-extension extension-path init-function))
31 | (lambda (key . args)
32 | (display "key: ") (display key) (newline)
33 | (build-libgash.so)
34 | (load-extension extension-path init-function))))
35 |
36 | ;; (define (build-gash-base-lib))
37 |
38 |
39 | (define (gash-load-dynamic-code-installed)
40 | (let* ((1l "#!/usr/bin/guile \\")
41 | (2l (format #f "-l ~a/gash-base-lib -e main -s" libsdir))
42 | (3l "!#")
43 | (n (list->string '(#\newline)))
44 | (shebang (string-append 1l n 2l n 3l n n)))
45 | (let ((code-to-load-libgash.so
46 | (format #f "(let ((extension-path \"~a/libgash.so\")
47 | (init-function \"init_gash_c\"))
48 | (load-extension extension-path init-function))"
49 | libsdir)))
50 | (string-append shebang code-to-load-libgash.so n n
51 | "(define header-loads-libgash #t)" n n
52 | ";;; the above was generated by configure, please inspect!"
53 | n))))
54 |
55 | (define (gash-load-dynamic-code-local)
56 | (let* ((1st-line "#!/usr/bin/guile \\")
57 | (2nd-line (format #f "-l ~a/gash-base-lib -e main -s" (getcwd)))
58 | (3rd-line "!#")
59 | (n (list->string '(#\newline)))
60 | (shebang (string-append 1st-line n 2nd-line n 3rd-line n n)))
61 | (let ((code-to-load-libgash.so
62 | (format #f "(let ((extension-path \"~a/libgash.so\")
63 | (init-function \"init_gash_c\"))
64 | (load-extension extension-path init-function))"
65 | (getcwd))))
66 | (string-append shebang code-to-load-libgash.so n n
67 | "(define header-loads-libgash #t)" n n
68 | ";;; the above was generated by configure, please inspect!"
69 | n))))
70 |
71 | (define (gash-and-history-as-string)
72 | (define (trash-x-lines-from-port x port)
73 | (for v from 1 to x
74 | (read-line port)))
75 | (let ((gash-port (open-file "gash-code.scm" "r"))
76 | ;; (gash-base-lib-port (open-file "gash-base-lib" "r"))
77 | (history-port (open-file "history.scm" "r")))
78 | (trash-x-lines-from-port 3 gash-port)
79 | (let ((gash-text (get-string-all gash-port))
80 | ;; (gash-base-lib-text (get-string-all gash-base-lib-port))
81 | (history-text (get-string-all history-port)))
82 | (string-append gash-text history-text))))
83 |
84 | (define (assemble-gash)
85 | "put together a single gash file to install, and set it to be executable"
86 | (echo
87 | "Assembling history and gash propper into single file with propper headers")
88 | (let ((header (if local?
89 | (gash-load-dynamic-code-local)
90 | (gash-load-dynamic-code-installed)))
91 | (port (open-file single-file-name "w"))
92 | (code (gash-and-history-as-string)))
93 | (echo "writing to single-file")
94 | (display (string-append header code) port)
95 | (close-port port)
96 | (system-fmt "chmod +x ~a" single-file-name)))
97 |
98 | (define (copy-install-gash-execdir)
99 | (if local? ; if local?, then dont install libraries.
100 | (begin
101 | (system-fmt "sudo cp ~a ~a/~a" single-file-name execdir executable-name)
102 | (echo-fmt "installed ~a to ~a/~a"
103 | single-file-name execdir executable-name))
104 | (begin (system-fmt "sudo cp libgash.so ~a/libgash.so" libsdir)
105 | (system-fmt "sudo cp gash-base-lib ~a/gash-base-lib" libsdir)
106 | (system-fmt "sudo cp ~a ~a/~a"
107 | single-file-name execdir executable-name)
108 | (echo-fmt "installed ~a to ~a/~a" "libgash.so" libsdir "libgash.so")
109 | (echo-fmt "installed ~a to ~a/~a"
110 | "gash-base-lib" libsdir "gash-base-lib")
111 | (echo-fmt "installed ~a to ~a/~a"
112 | single-file-name execdir executable-name)
113 | )))
114 |
115 | (define (copy-install-gash-curdir)
116 | "this function installs gash to the current directory."
117 | (system-fmt "sudo cp ~a ~a/~a" single-file-name (getcwd) executable-name))
118 |
119 | (define (main . args)
120 | (for-cmd-line
121 | ((--set-libsdir)
122 | (set! libsdir (shift)))
123 | ((--set-execdir)
124 | (set! execdir (shift)))
125 | ((--set-single-file-name)
126 | (set! single-file-name (shift)))
127 | ((--set-install-name)
128 | (set! executable-name (shift)))
129 | ((--local)
130 | ;; set local? to #t or #f based on --local flag
131 | (let ((x (shift)))
132 | (cond ((or (string=? x "f") (string=? x "no") (string=? x "n"))
133 | (set! local? #f))
134 | ((or (string=? x "t") (string=? x "yes") (string=? x "y"))
135 | (set! local? #t)))))
136 | ((--generate)
137 | (build-libgash.so)
138 | (assemble-gash))
139 | ((--install)
140 | (build-libgash.so)
141 | (assemble-gash)
142 | (copy-install-gash-execdir)
143 | (system-fmt "rm ~a" single-file-name))
144 | ((-qi))
145 | ;; (())
146 | )
147 | (display "build with local directory as library directory?: ")
148 | (echo (if local? "yes" "no")))
149 |
--------------------------------------------------------------------------------
/configure:
--------------------------------------------------------------------------------
1 | #!/usr/bin/guile \
2 | -l gash-base-lib -e main -s
3 | !#
4 |
5 | (use-modules (ice-9 format)
6 | (ice-9 popen)
7 | (ice-9 rdelim)
8 | (ice-9 textual-ports)
9 | (ice-9 session)
10 | (ice-9 regex)
11 | (ice-9 buffered-input))
12 |
13 | (let ((extension-path (format #f "~a/libgash.so" (getcwd)))
14 | (init-function "init_gash_c"))
15 | (load-extension extension-path init-function))
16 |
17 | (define cc "gcc")
18 | (define cflags "`pkg-config --cflags readline guile-2.2`")
19 | (define execdir "/usr/local/bin")
20 | (define libsdir "/usr/local/lib")
21 | (define single-file-name "gash-single-file")
22 |
23 | (define (build-libgash)
24 | (echo "compiling libgash.so")
25 | (system-fmt
26 | "~a ~a -shared -o libgash.so -fPIC libgash.c -l readline" cc cflags)
27 | (echo "setting gash to be executable")
28 | (system "chmod +x gash"))
29 |
30 | (define (link-gash-libs)
31 | (echo "linking gash libraries")
32 | (system-fmt "sudo cp ~a/gash-base-lib /usr/local/lib/gash-base-lib" (getcwd))
33 | (system-fmt "sudo cp ~a/libgash.so /usr/local/lib/libgash.so" (getcwd))
34 | (system-fmt "sudo cp ~a/history.scm /usr/local/lib/history.scm" (getcwd)))
35 |
36 | (define (link-gash . location)
37 | (if (null? location)
38 | (system-fmt "sudo cp ~a/gash /usr/local/bin/gash" (getcwd))
39 | (system-fmt "sudo cp ~a/gash ~a" (getcwd) (car location))))
40 |
41 | (define (clean-gash)
42 | (let ((path (collect-shell-command "which gash")))
43 | (display "cleaning ") (echo path)
44 | (system-fmt "rm ~a" (car path))))
45 |
46 | ;; (define (reinstall))
47 | (define (smart-reinstall)
48 | (let ((path (collect-shell-command "which gash")))
49 | (cond ((directory? (car path))
50 | (build-libgash)
51 | (link-gash-libs)
52 | (display "cleaning ")
53 | (echo path)
54 | (system-fmt "rm ~a" (car path))
55 | (system-fmt "ln ~a/gash ~a" (getcwd) path))
56 | (else
57 | (echo "GASH not in path, re run with --install")))))
58 |
59 | (define (main . args)
60 | (if (null? (cdr (car args)))
61 | (build-libgash)
62 | (for-cmd-line
63 | ((--local)
64 | (echo "building gash.test.o, should be inspected")
65 | (build-gash-file-local))
66 | ((--echo-stuff)
67 | (echo gash-code-local))
68 | ((-ll) (link-gash-libs))
69 | ((--clean) (clean-gash))
70 | ((--reinstall) (smart-reinstall))
71 | ((--install)
72 | (build-libgash)
73 | (link-gash-libs)
74 | (link-gash))
75 | ((--single)
76 | (generate-gash-as-single-file #t))
77 | ((--install-with-local)
78 | ;; (single-file-gash-install)
79 | (install-gash-single-file "gash-single-file")
80 | ;; (link-gash-locally "gash-single-file")
81 | )
82 | )))
83 |
84 | (define gash-code
85 | (let* ((port (open-file "gash-code.scm" "r"))
86 | (text (get-string-all port)))
87 | (close-port port)
88 | text))
89 |
90 | (define gash-load-dynamic-code-local
91 | (let* ((1st-line "#!/usr/bin/guile \\")
92 | (2nd-line (format #f "-l ~a/gash-base-lib -e main -s" (getcwd)))
93 | (3rd-line "!#")
94 | (n (list->string '(#\newline)))
95 | (shebang (string-append 1st-line n 2nd-line n 3rd-line n n)))
96 | (let ((code-to-load-libgash.so
97 | (format #f "(let ((extension-path \"~a/libgash.so\")
98 | (init-function \"init_gash_c\"))
99 | (load-extension extension-path init-function))"
100 | (getcwd))))
101 | (string-append shebang code-to-load-libgash.so n
102 | ";;; the above was generated by configure, please inspect!"
103 | n n))))
104 |
105 | (define gash-load-dynamic-code-installed
106 | (let* ((1l "#!/usr/bin/guile \\")
107 | (2l (format #f "-l ~a/gash-base-lib -e main -s" libsdir))
108 | (3l "!#")
109 | (n (list->string '(#\newline)))
110 | (shebang (string-append 1l n 2l n 3l n n)))
111 | (let ((code-to-load-libgash.so
112 | (format #f "(let ((extension-path \"~a/libgash.so\")
113 | (init-function \"init_gash_c\"))
114 | (load-extension extension-path init-function))"
115 | libsdir)))
116 | (string-append shebang code-to-load-libgash.so n
117 | ";;; the above was generated by configure, please inspect!"
118 | n n)))
119 | ;; (let* ((port (open-file "configure-gash-load-installed" "r"))
120 | ;; (text (get-string-all port)))
121 | ;; (close-port port)
122 | ;; text)
123 | )
124 |
125 | (define gash-single-file-head
126 | (let* ((port (open-file "conf-gash-libs-and-gash-all-together" "r"))
127 | (text (get-string-all port)))
128 | (close-port port)
129 | text))
130 |
131 | ;; (define gash-single-file
132 | ;; (let* ((history-port (open-file "history.scm" "r"))
133 | ;; (history (get-string-all history-port))
134 | ;; (base-lib-port (open-file "gash-base-lib" "r"))
135 | ;; (base-lib #f))
136 | ;; (read-line base-lib-port)
137 | ;; (read-line base-lib-port)
138 | ;; (read-line base-lib-port)
139 | ;; (set! base-lib (get-string-all base-lib-port))
140 | ;; (string-append base-lib (list->string '(#\newline #\newline))
141 | ;; history (list->string '(#\newline #\newline))
142 | ;; gash-code)))
143 |
144 | ;; (define (print-stuff)
145 | ;; (let* ((base-lib-port (open-file "gash-base-lib" "r"))
146 | ;; (base-lib-line-1 (read-line base-lib-port))
147 | ;; (base-lib-line-2 (read-line base-lib-port))
148 | ;; (base-lib-line-3 (read-line base-lib-port))
149 | ;; (rest (get-string-all base-lib-port)))
150 | ;; (close-port base-lib-port)
151 | ;; (display base-lib-line-1) (newline)
152 | ;; (display base-lib-line-2) (newline)
153 | ;; (display base-lib-line-3) (newline)
154 | ;; (display rest) (newline)))
155 |
156 | (define (build-gash-file-local)
157 | (let ((file-text
158 | (string-append
159 | gash-load-dynamic-code-local
160 | (list->string '(#\newline #\newline))
161 | ";;; above is code to load the necessary libraries for GASH,
162 | "
163 | ";;; libgash.so, history.scm, and gash-base-lib will be loaded
164 | "
165 | (format #f ";;; from the local directory, ~a" (getcwd))
166 | (list->string '(#\newline #\newline))
167 | gash-code)))
168 | (let ((port (open-file "gash.test.o" "w")))
169 | (display file-text port)
170 | (close-port port))))
171 |
172 | ;; (define (link-gash-locally from . to)
173 | ;; (if (null? to)
174 | ;; (system-fmt "sudo ln -s ~a ~a" from "/usr/local/bin/gash-local")
175 | ;; (system-fmt "sudo ln -s ~a ~a" from to)))
176 |
177 | (define (install-gash-single-file from . to)
178 | (if (null? to)
179 | (system-fmt "sudo cp ~a ~a" from "/usr/local/bin/gash-local")
180 | (system-fmt "sudo cp ~a ~a" from to)))
181 |
182 | ;; (define (main . xyz)
183 | ;; (let* ((cmdl (car xyz))
184 | ;; (command (car cmdl))
185 | ;; )
186 | ;; ()))
187 |
188 | ;; (define (single-file-gash-install)
189 | ;; (let ((port (open-file "gash-single-file" "w")))
190 | ;; (display (string-append gash-single-file-head gash-code) port)
191 | ;; (close-port port)))
192 |
193 | (define (generate-load-path . path)
194 | (string-append "#!/usr/bin/guile \\
195 | -l "
196 | (if (null? path)
197 | (getcwd)
198 | (car path))
199 | "/gash-base-lib -e main -s"
200 | "
201 | !#
202 |
203 | (let ((ext-path (format #f \"~a/libgash.so\" "
204 | (if (null? path)
205 | (getcwd)
206 | (car path))
207 | ")))
208 | (load-extension ext-path \"init_gash_c\"))
209 |
210 | "
211 | ))
212 |
213 | (define gash-and-history-as-string
214 | (let ((gash-port (open-file "gash" "r"))
215 | ;; (gash-base-lib-port (open-file "gash-base-lib" "r"))
216 | (history-port (open-file "history.scm" "r")))
217 | (define (trash-x-lines-from-port x port)
218 | (for v from 1 to x
219 | (read-line port)))
220 | (trash-x-lines-from-port 3 gash-port)
221 | (let ((gash-text (get-string-all gash-port))
222 | ;; (gash-base-lib-text (get-string-all gash-base-lib-port))
223 | (history-text (get-string-all history-port)))
224 | (string-append gash-text history-text))))
225 |
226 | (define (generate-gash-as-single-file . local?)
227 | "This function generates a file which contains history and gash propper. This
228 | file name is held in single-file-name. "
229 | (display "about to enter let for gash-single-file") (newline)
230 | (let ((header (if (not (null? local?))
231 | gash-load-dynamic-code-local
232 | gash-load-dynamic-code-installed))
233 | (port (open-file single-file-name "w"))
234 | (code gash-and-history-as-string)
235 | )
236 | (display "about to write to gash-single-file") (newline)
237 | (display (string-append header code
238 | ) port)
239 | (close-port port))
240 | ;; (if (null? local?)
241 | ;; (begin (display (format #f "copying to ~a and ~a" execdir libsdir))
242 | ;; (system-fmt "sudo cp gash-base-lib ~a/gash-base-lib" libsdir)
243 | ;; (system-fmt "sudo cp libgash.so ~a/libgash.so" libsdir)
244 | ;; (system-fmt "sudo cp gash-single-file ~a/gash" execdir))
245 | ;; ())
246 | )
247 |
248 | (define installed-name "gash-local")
249 |
250 | (define (install-single-file-gash local?)
251 | (if local? ;; if we have generated load strings that reference the current dir
252 | (system-fmt "sudo cp gash-single-file ~a/~a" execdir)
253 | ;; otherwise copy over all the libs and whatnot.
254 | (begin (display (format #f "copying to ~a and ~a" execdir libsdir))
255 | (system-fmt "sudo cp gash-base-lib ~a/gash-base-lib" libsdir)
256 | (system-fmt "sudo cp libgash.so ~a/libgash.so" libsdir)
257 | (system-fmt "sudo cp gash-single-file ~a/gash" execdir))))
258 |
--------------------------------------------------------------------------------
/gash-base-lib:
--------------------------------------------------------------------------------
1 | #!/usr/bin/guile \
2 | -s
3 | !#
4 |
5 | (use-modules (ice-9 format)
6 | (ice-9 popen)
7 | (ice-9 rdelim)
8 | (ice-9 textual-ports))
9 |
10 | ;;; general niceties.
11 |
12 | (define-macro (when cond expr . rest)
13 | `(if ,cond
14 | (begin ,expr . ,rest)
15 | nil))
16 |
17 | (define-macro (bset! . to-set)
18 | `(begin (set! ,@to-set) ,(car to-set)))
19 |
20 | (define-macro (display-fmt str . fmt)
21 | `(display (format #f ,str ,@fmt)))
22 |
23 | (define-macro (system-fmt str . fmt)
24 | `(system (format #f ,str ,@fmt)))
25 |
26 | (define (display-color color-number string)
27 | "this is for terminal output, it prints a string in the specified 24bit color."
28 | (system-fmt "printf '\\033[38;5;~Am~A\\033[0m'" color-number string))
29 |
30 | (define-syntax echo-color
31 | (syntax-rules ()
32 | ((echo-color color item)
33 | (begin (display-color color item)
34 | (newline)))
35 | ((echo-color color items ...)
36 | (let loop ((itm-lst '(items ...)))
37 | (unless (null? itm-lst)
38 | (display-color color (car itm-lst))
39 | (newline)
40 | (loop (cdr itm-lst)))))))
41 |
42 | (define-macro (echo-fmt-test . args)
43 | ;; so... args is either:
44 | ;; (color-number control-string formatters ...)
45 | ;; (control-string formatters)
46 | `(cond ((null? ,args)
47 | (newline))
48 | ((number? ,(car args))
49 | (echo-color ,(car args) `(format #f ,(cadr args) ,@(cddr args))))
50 | (else
51 | (echo-standard (format #f ,(car args) ,@(cdr args))))))
52 |
53 | (define-syntax echo-ex
54 | (syntax-rules ()
55 | ((echo-ex)
56 | (newline))
57 | ;; ((echo item)
58 | ;; (begin (display item)
59 | ;; (newline)))
60 | ((echo-ex color str ...)
61 | (let ((is-color? (number? color)))
62 | (if is-color?
63 | (echo-color color str ...)
64 | (let loop ((lst (append '(color) '(str ...))))
65 | (unless (null? lst)
66 | (display (car lst))
67 | (newline)
68 | (loop (cdr lst)))))))))
69 |
70 | (define-syntax echo-fmt
71 | (syntax-rules ()
72 | ((echo-fmt str one-formatter)
73 | (echo (format #f str one-formatter)))
74 | ((echo-fmt color str formatters ...)
75 | (let ((is-color? (number? color)))
76 | (if is-color?
77 | (echo-color color (format #f str formatters ...))
78 | (echo (format #f color str formatters ...)))))))
79 |
80 | (define-macro (echo thing)
81 | `(begin (display ,thing)
82 | (newline)))
83 |
84 | (define (print strings-list)
85 | (map (lamdba (el)
86 | (echo el))
87 | strings-list))
88 |
89 | (define-macro (first thing)
90 | `(car ,thing))
91 | (define-macro (second thing)
92 | `(cadr ,thing))
93 | (define-macro (third thing)
94 | `(caddr ,thing))
95 | (define-macro (fourth thing)
96 | `(cadddr ,thing))
97 | (define-macro (fifth thing)
98 | `(cadr (cdddr ,thing)))
99 | (define-macro (sixth thing)
100 | `(caddr (cdddr ,thing)))
101 | (define-macro (seventh thing)
102 | `(cadddr (cdddr ,thing)))
103 | (define-macro (eighth thing)
104 | `(cadr (cdddr (cdddr ,thing))))
105 | (define-macro (ninth thing)
106 | `(caddr (cdddr (cdddr ,thing))))
107 | (define (last l)
108 | (if (null? (cdr l))
109 | (car l)
110 | (last (cdr l))))
111 |
112 | ;; (define-syntax run-bash-command
113 | ;; (syntax-rules ()
114 | ;; ((run-bash-command command)
115 | ;; (let ((port (open-file-output-port "~/.temp-bash")))
116 | ;; (display command port)
117 | ;; (newline port)
118 | ;; (close-port port)
119 | ;; (chmod "~/.temp-bash" #o100)
120 | ;; (system "~/.temp-bash")
121 | ;; (system "rm ~/.temp-bash")))))
122 |
123 | (define (remove-all x ls)
124 | (if (null? ls)
125 | '()
126 | (if (eq? x (car ls))
127 | (remove-all x (cdr ls))
128 | (cons (car ls)
129 | (remove-all x (cdr ls))))))
130 |
131 | (define-syntax echo-with-color
132 | (syntax-rules ()
133 | ((echo-with-color color-as-number text)
134 | (system* "echo" (string-append "\\xlb[38;5;" text "\\xlb[m\n")))))
135 |
136 | (define-syntax collect-shell-command
137 | (syntax-rules ()
138 | ((collect-shell-command command as-string)
139 | (let* ((port (open-input-pipe command))
140 | (stringer (get-string-all port)))
141 | (close-port port)
142 | stringer))
143 | ((collect-shell-command command as-string trim-last-newline)
144 | (let* ((port (open-input-pipe command))
145 | (stringer (get-string-all port))
146 | (len (string-length stringer)))
147 | (close-port port)
148 | (if (and trim-last-newline
149 | (char=? #\newline (string-ref stringer (- len 1))))
150 | (substring stringer 0 (- len 1))
151 | stringer)))
152 | ((collect-shell-command command)
153 | (let ((port (open-input-pipe command)))
154 | (let loop ((current-read (read-line port)))
155 | (if (eof-object? current-read)
156 | '()
157 | (cons current-read (loop (read-line port)))))))))
158 |
159 | (define-syntax collect-shell-commands
160 | (syntax-rules ()
161 | ((collect-shell-commands commands ...)
162 | (map (lambda (el)
163 | (if (string? el)
164 | (collect-shell-command el)
165 | (eval el)))
166 | '(commands ...)))
167 | ((collect-shell-commands as-string commands ...)
168 | (map (lambda (el)
169 | (collect-shell-command el as-string))
170 | '(commands ...)))
171 | ((collect-shell-commands as-string trim-last-newline commands ...)
172 | (map (lambda (el)
173 | (collect-shell-command el as-string trim-last-newline))
174 | '(commands ...)))
175 | ))
176 |
177 | (define-macro (run-shell-commands . commands)
178 | `(map (lambda (el)
179 | (collect-shell-command el))
180 | ',commands))
181 |
182 | (define-syntax collect-multiple-shell-commands
183 | (syntax-rules ()
184 | ((collect-shell-command commands)
185 | (let ((commands-list
186 | (map (lambda (command)
187 | (collect-shell-command command))
188 | commands)))
189 | commands-list))))
190 |
191 | (define-syntax while
192 | (syntax-rules ()
193 | ((while condition body ...)
194 | (let loop ()
195 | (if condition
196 | (begin body ...
197 | (loop))
198 | #f)))))
199 |
200 | (define-syntax for
201 | (syntax-rules (in as accum-in from to bind)
202 | ((for var from x to y body ...)
203 | (let loop ((var x))
204 | (if (< y var)
205 | #f
206 | (begin body ...
207 | (loop (+ var 1))))))
208 | ((for element in list bind var body ...)
209 | (let (var)
210 | (map (lambda (element)
211 | body ...)
212 | list)))
213 | ((for element in list body ...)
214 | (map (lambda (element)
215 | body ...)
216 | list))
217 | ((for list as element body ...)
218 | (map (lambda (element)
219 | body ...)
220 | list))
221 | ((for list as element accum-in var body ...)
222 | (let (var)
223 | (map (lambda (element)
224 | body ...)
225 | list)))))
226 |
227 | (define-macro (for-cmd-line . body)
228 | "This macro is for parsing the command line of a function. while its core
229 | purpose is to take a list of flags, and what to do when they are encountered, it
230 | also defines two functions, shift and peek, which are called with no arguments.
231 | these functions both return the car of the list of command line strings, with
232 | shift removing the car, and peek leaving it intact. it can be called like so:
233 |
234 | (for-cmd-line
235 | ((-flag) (echo \"flag\")
236 | (let ((var (shift))
237 | (othervar (peek)))
238 | (cond ((string-equal var \"option\")
239 | (echo \"OPTION!\")
240 | (echo var))
241 | (t
242 | (echo othervar)))))
243 | ((--other-flag) (echo \"whatever this flag does)))
244 |
245 | the above example when called with:
246 | $ script -flag something otherthing --other-flag
247 | would expand into the following:
248 | (let ((sym (command-line)))
249 | (define (shift) ...)
250 | (define (peek) ...)
251 | (while (not (null? sym))
252 | (case (string->symbol (car sym))
253 | ((-flag) (shift) (echo \"flag\")
254 | (let ((var (shift))
255 | (othervar (peek)))
256 | (cond ((string-equal var \"option\")
257 | (echo \"OPTION!\")
258 | (echo var))
259 | (t
260 | (echo othervar)))))
261 | ((--other-flag) (shift) (echo \"whatever this flag does)))))
262 | and after running the -flag portion (which would come first in this example) the
263 | variable 'sym' would be equal "
264 | (let ((cmd-name (gensym))
265 | (new-body
266 | (map
267 | (lambda (sexp)
268 | (let ((flag (car sexp))
269 | (todo (cdr sexp)))
270 | (cons flag (cons '(shift) todo))))
271 | body)))
272 | `(let ((,cmd-name (command-line)))
273 | (define (shift)
274 | (catch 'wrong-type-arg
275 | (lambda ()
276 | (let ((c (car ,cmd-name)))
277 | (set! ,cmd-name (cdr ,cmd-name))
278 | c))
279 | (lambda (key . args)
280 | #f)))
281 | (define (peek)
282 | (catch 'wrong-type-arg
283 | (lambda ()
284 | (car ,cmd-name))
285 | (lambda (key . args)
286 | #f)))
287 | (while (not (null? ,cmd-name))
288 | ;; (echo ,cmd-name)
289 | (case (string->symbol (car ,cmd-name))
290 | ,@new-body
291 | (else
292 | (shift)))))))
293 |
294 | (define (flatten x)
295 | (cond ((null? x) '())
296 | ((pair? x)
297 | (append (flatten (car x)) (flatten (cdr x))))
298 | (else (list x))))
299 |
300 | (define (prefix? src prefix)
301 | "takes two lists and checks if prefix is the prefix of src"
302 | (when (and (not (null? prefix)) (not (null? src)))
303 | (let loop ((source src)
304 | (pfix prefix))
305 | (cond ((null? pfix)
306 | #t)
307 | ((null? source)
308 | #f)
309 | ((equal? (car source) (car pfix))
310 | (loop (cdr source) (cdr pfix)))
311 | (else
312 | #f)))))
313 |
314 | (define (append-reverse rev-head tail)
315 | (append (reverse rev-head) tail))
316 |
317 | (define (replace-substring string to-replace replace-with)
318 | "send in 3 strings, or, 3 lists of characters"
319 | (let ((haystack (if (string? string) (string->list string) string))
320 | (needle (if (string? to-replace) (string->list to-replace) to-replace))
321 | (replacement (if (string? replace-with) (string->list replace-with)
322 | replace-with))
323 | (needle-len (if (string? to-replace)
324 | (string-length to-replace)
325 | (length to-replace))))
326 | (let loop ((haystack haystack) (acc '()))
327 | (cond ((null? haystack)
328 | (list->string (reverse acc)))
329 | ((prefix? haystack needle)
330 | (loop (list-tail haystack needle-len)
331 | (append-reverse replacement acc)))
332 | (else
333 | (loop (cdr haystack) (cons (car haystack) acc)))))))
334 |
335 | (define (string-splitter string to-split)
336 | (let ((haystack (string->list string))
337 | (needle (string->list to-split))
338 | (needle-len (string-length to-replace)))
339 | (let loop ((haystack haystack) (accum '()) (grand '())) ;store total in grand
340 | (cond ((null? haystack)
341 | grand)
342 | ((prefix? haystack needle)
343 | (loop '() (cons (list->string (reverse accum)))))
344 | (else
345 | (loop (cdr haystack) (cons (car haystack) accum) grand))))))
346 |
347 | ;; (define (directory? path)
348 | ;; (with-throw-handler #t
349 | ;; (lambda () (equal? 'directory (stat:type (stat path))))
350 | ;; (lambda (key . args)
351 | ;; #f)))
352 |
353 | (define (join-strings-with string-list string)
354 | "takes a list of strings, and runs string-append on it after mixing with string
355 | strings, so passing \"hi\" \"there\" would result in string append being passed
356 | \"hi\" \" \" \"there\". "
357 | (let loop ((strings-list string-list)
358 | (accum '()))
359 | (if (null? strings-list)
360 | (let ((appender ""))
361 | (map (lambda (el)
362 | (set! appender (string-append appender el)))
363 | (reverse (cdr accum)))
364 | appender)
365 | (loop (cdr strings-list) (cons string
366 | (cons (car strings-list) accum))))))
367 |
368 | (define (join-strings string-list string)
369 | (join-strings-with string-list string))
370 |
371 | (define (char->string char)
372 | (list->string (list char)))
373 |
374 |
375 | ;; (define-macro (defsh name+args . body)
376 | ;; (let ((name (car name+args))
377 | ;; (argslist (cdr name+args))
378 | ;; args)
379 | ;; (if (null? (cdr (last-pair name+args))) ; the last pair isnt dotted (x . y)
380 | ;; (set! args (map (lambda (el)
381 | ;; "el is of the form (type name)"
382 | ;; (second el))
383 | ;; argslist))
384 | ;; (set! args (let loop ((preargs argslist)
385 | ;; (accum '())
386 | ;; ()))))
387 | ;; (let (()))))
388 |
389 | ;; (define-syntax bags
390 | ;; (syntax-rules ()
391 | ;; ((bags (name (argtype argname) ...) body ...)
392 | ;; (define (name )))))
393 |
394 | ;; (defsh (adder (number argname1) (number argname2))
395 | ;; (+ argname1 argname2))
396 |
397 | ;; (define (adder argname1 argname2)
398 | ;; (let ((argname1 (if (number? argname1)
399 | ;; argname1
400 | ;; (string->number argname1)))
401 | ;; (argname2 (if (number? argname2)
402 | ;; argname2
403 | ;; (string->number argname2))))
404 | ;; (+ argname1 argname2)))
405 |
--------------------------------------------------------------------------------
/gash-code.scm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/guile \
2 | -l gash-base-lib -e main -s
3 | !#
4 |
5 |
6 | ;; this let statement is to determine if gash is installed, or if it is already
7 | ;; loading extensions and libs. we initially load gash-base-lib, and then we
8 | ;; check if a variable placed in by ./conf exists. if it does, we dont need to
9 | ;; load anything. otherwise we need to load libgash.so and history.scm from the
10 | ;; local directory.
11 | (let ((extension-path (format #f "~a/libgash.so" (getcwd)))
12 | (init-function "init_gash_c"))
13 | (catch 'unbound-variable
14 | (lambda ()
15 | (unless header-loads-libgash
16 | (load-extension extension-path init-function)))
17 | (lambda (key . args)
18 | (load-extension extension-path init-function)
19 | (load "history.scm"))))
20 |
21 | (use-modules (ice-9 format)
22 | (ice-9 popen)
23 | (ice-9 rdelim)
24 | (ice-9 textual-ports)
25 | (ice-9 session)
26 | (ice-9 regex)
27 | (ice-9 buffered-input))
28 |
29 | (define *suppress-error-messages* #f)
30 |
31 | ;; (define (with-attempted-completion completer thunk)
32 | ;; (let ((old-comp *readline-alt-completion-function*))
33 | ;; (dynamic-wind
34 | ;; (lambda ()
35 | ;; (set! *readline-alt-completion-function* completer))
36 | ;; thunk
37 | ;; (lambda ()
38 | ;; (set! *readline-alt-completion-function* old-comp)))))
39 |
40 | ;; (load "/usr/local/lib/history.scm")
41 |
42 | (define home-directory
43 | (let* ((port (open-input-pipe "echo $HOME"))
44 | (dir (read-line port)))
45 | (close-port port)
46 | dir))
47 |
48 | (define *all-programs*
49 | (string-split (collect-shell-command "compgen -c" #t) #\newline))
50 |
51 | (define user-at-host
52 | (let* ((user-port (open-input-pipe "echo $USER"))
53 | (host-port (open-input-pipe "hostname"))
54 | (user (read-line user-port))
55 | (host (read-line host-port)))
56 | (close-port user-port)
57 | (close-port host-port)
58 | (format #f "~a@~a" user host)))
59 |
60 | (define (directory-contents dir)
61 | (let ((port (open-input-pipe
62 | (if (char=? (string-ref dir 0) #\/)
63 | (format #f "ls -a ~a" dir)
64 | (format #f "ls -a ~a/~a" (getcwd) dir)))))
65 | (let gather ((line (read-line port))
66 | (accum '()))
67 | (if (eof-object? line)
68 | (begin (close-port port) (reverse accum))
69 | (gather (read-line port) (cons line accum))))))
70 |
71 | (define (string-app-list string-list)
72 | (apply string-append string-list))
73 |
74 | ;;;
75 |
76 | (define scheme-switch #\§)
77 |
78 | (define* (walk-string-for-guile string #:optional (location
79 | (string-index string scheme-switch)))
80 | (let ((first-instance location))
81 | (let loop ((char-list (string->list (substring string (+ 1 first-instance))))
82 | (accum '())
83 | (paren-counter 0)
84 | (length 0))
85 | ;; (display char-list) (newline)
86 | (cond ((null? char-list)
87 | ;; (echo "null char-list")
88 | ;; (if (equal? paren-counter 1)
89 | ;; #f)
90 | (+ 1 length))
91 | ((char=? (car char-list) #\()
92 | ;; (echo "found an opening paren")
93 | (loop (cdr char-list) (cons (car char-list) accum)
94 | (+ paren-counter 1) (+ length 1)))
95 | ((char=? (car char-list) #\))
96 | ;; (echo "found a closing paren")
97 | (loop (cdr char-list) (cons (car char-list) accum)
98 | (- paren-counter 1) (+ length 1)))
99 | ((equal? paren-counter 0)
100 | ;; (echo "paren counter is 0")
101 | (+ 1 length))
102 | (else
103 | (loop (cdr char-list) (cons (car char-list) accum)
104 | paren-counter (+ length 1)))))))
105 |
106 | (define (extract-scheme-strings string)
107 | ;; (echo string)
108 | (if (not (string-index string scheme-switch))
109 | (list string)
110 | (let loop ((ref (string-index string scheme-switch))
111 | (tail 0)
112 | (acc '()))
113 | ;; (echo ref)
114 | (cond ((not ref)
115 | (reverse (cons (substring string tail) acc)))
116 | (else
117 | (let* ((end-scheme (walk-string-for-guile string ref))
118 | (scheme-string
119 | (substring string ref
120 | (+ ref end-scheme)))
121 | (pre-string (substring string tail ref)))
122 | (loop (string-index string scheme-switch (+ ref 1))
123 | (+ ref end-scheme)
124 | (cons scheme-string (cons pre-string acc)))))))))
125 |
126 | (define (eval/replace-scheme-string string-list)
127 | (let loop ((strings string-list)
128 | (acc '()))
129 | (cond ((null? strings)
130 | (reverse acc))
131 | ((string=? (car strings) "")
132 | (loop (cdr strings) (cons (car strings) acc)))
133 | ((char=? (string-ref (car strings) 0) scheme-switch)
134 | (let ((result
135 | (eval-string (substring (car strings) 1))))
136 | (loop (cdr strings)
137 | (cons
138 | (if (string? result)
139 | result
140 | "")
141 | acc))))
142 | (else
143 | (loop (cdr strings) (cons (car strings) acc))))))
144 |
145 | ;;; end guile parsing.
146 |
147 | (define (sh . string)
148 | (let* ((port (open-input-pipe string))
149 | (strs (get-string-all port)))
150 | (close-port port)
151 | strs))
152 |
153 | (define ($ string)
154 | (let ((s (collect-shell-command string #t #t)))
155 | (let ((expanded
156 | (string-app-list (eval/replace-scheme-string
157 | (extract-scheme-strings s)))))
158 | expanded))
159 | ;; (let ((port (open-input-pipe string))
160 | ;; (strs (get-string-all port)))
161 | ;; (close-port port)
162 | ;; (let ((expanded
163 | ;; (string-app-list (eval/replace-scheme-string
164 | ;; (extract-scheme-strings strs)))))
165 | ;; expanded))
166 | )
167 |
168 | ;; (define-macro ($ string))
169 |
170 | (define *builtins-alist*
171 | `(("cd" . ,(lambda (lst)
172 | (cond ((null? (cdr lst))
173 | (chdir home-directory)
174 | '())
175 | ((string=? (second lst) "~/")
176 | (begin (chdir home-directory)
177 | (cddr lst)))
178 | ((string=? (second lst) "")
179 | (begin (chdir home-directory)
180 | '()))
181 | ((directory? (cadr lst))
182 | (begin (chdir (cadr lst))
183 | (cddr lst)))
184 | (else
185 | (let cd-loop ((dir-str (second lst))
186 | (rem-str (cddr lst)))
187 | (cond ((null? rem-str)
188 | ;; (display "in null? dir-str: ")(echo dir-str)
189 | (when (directory? dir-str)
190 | (chdir dir-str))
191 | '())
192 | ((directory? dir-str)
193 | ;; (display "in dir? dir-str: ")(echo dir-str)
194 | (chdir (cadr lst)) (cdr rem-str))
195 | (else
196 | ;; (echo dir-str)
197 | (cd-loop
198 | (string-append dir-str " " (car rem-str))
199 | (cdr rem-str)))))))))
200 | ("exit" . ,(lambda (lst)
201 | (exit 0)))
202 | ("reload" . ,(lambda (lst)
203 | (echo "Loading .gashrc")
204 | (load (format #f "~a/.gashrc" home-directory))
205 | '()))))
206 |
207 | (define (define-builtin name lambda)
208 | (set! *builtins-alist* (cons `(,name . ,lambda) *builtins-alist*)))
209 |
210 | (define *directory-stack* '())
211 |
212 | (define-builtin "pudir"
213 | (lambda (lst)
214 | (cond ((null? lst) lst)
215 | ((null? (cdr lst))
216 | (echo-color 1 "Enter a directory")
217 | '())
218 | ((directory? (second lst))
219 | (set! *directory-stack* (cons (getcwd) *directory-stack*))
220 | (echo-color 2 (format #f "Pushing from ~a to ~a"
221 | (getcwd) (second lst)))
222 | (chdir (second lst))
223 | (cddr lst))
224 | (else
225 | (echo-color 1 "unknown directory, try again")
226 | (cddr lst)))))
227 |
228 | (define-builtin "podir"
229 | (lambda (lst)
230 | (cond ((null? lst) lst)
231 | ((null? *directory-stack*)
232 | (echo-color 1 "Directory stack is empty")
233 | (cdr lst))
234 | (else
235 | (echo-color 2 (format #f "Popping from ~a to ~a"
236 | (getcwd) (car *directory-stack*)))
237 | (chdir (car *directory-stack*))
238 | (set! *directory-stack* (cdr *directory-stack*))
239 | (cdr lst)))))
240 |
241 | (define *base-shorthand* ; this is for resetting the shorthand alist, should
242 | '(("ls" . "ls --color"))) ; one put to many entries.
243 |
244 | (define *shorthand-alist*
245 | '(("ls" . "ls --color")))
246 |
247 | (define (define-shorthand from to)
248 | (set! *shorthand-alist* (cons `(,from . ,to) *shorthand-alist*)))
249 |
250 | (define (replace-shorthand str-list)
251 | (let loop ((lst str-list)
252 | (accum '()))
253 | (if (null? lst)
254 | (reverse accum)
255 | ;; (join-strings " ")
256 | (let ((shorthand? (assoc (car lst) *shorthand-alist*)))
257 | (if shorthand?
258 | (loop (cdr lst) (cons (cdr shorthand?) accum))
259 | (loop (cdr lst) (cons (car lst) accum)))))))
260 |
261 | (define (generate-prompt)
262 | (let ((curdir (getcwd)))
263 | (if (string=? curdir home-directory)
264 | (format #f "~a ~a" user-at-host "~")
265 | (let ((p (substring curdir (+ 1 (string-index-right curdir #\/)))))
266 | (format #f "~a ~a" user-at-host p)))))
267 |
268 | (define commands-completion-function
269 | (let ((completions '()))
270 | (lambda (text cont?)
271 | (if (not cont?)
272 | (set! completions
273 | (let loop ((cmp *all-programs*)
274 | (accum '()))
275 | (if (null? cmp)
276 | accum
277 | (if (string-prefix? text (car cmp))
278 | (loop (cdr cmp) (cons (car cmp) accum))
279 | (loop (cdr cmp) accum))))))
280 | (if (null? completions)
281 | #f
282 | (let ((retval (car completions)))
283 | (begin (set! completions (cdr completions))
284 | retval))))))
285 |
286 | (define apropos-completion-function-test
287 | (let ((completions '()))
288 | (lambda (text cont?)
289 | ;; (echo "in apropos scheme function")
290 | (if (not cont?)
291 | (set! completions
292 | (map symbol->string
293 | (apropos-internal
294 | (string-append "^" (regexp-quote text))))))
295 | (if (null? completions)
296 | #f
297 | (let ((retval (car completions)))
298 | ;; (echo "completions not null, and state not #f")
299 | (begin (set! completions (cdr completions))
300 | retval))))))
301 |
302 | (define-macro (make-completer . body)
303 | "This takes a body, which can reference the variable current-word. This is
304 | more useful than just having text. text is divided based on many things, so if
305 | one types §(for and presses tab, it will complete based on for, as the §( is
306 | treated as a seperate thing. so we have 4 total things we can reference:
307 | start and end, which are our bounds within (get-line-contents), as well as
308 | text and current-word, which are our current completion text, and the last word
309 | in the line (meaning the final space to the end of the line)"
310 | `(lambda (text start end)
311 | (let ((current-word (last (string-split (get-line-contents) #\space))))
312 | ,@body)))
313 |
314 | (define default-gash-begin-scheme-string
315 | (format #f "~a(" scheme-switch))
316 |
317 | (define default-gash-completer
318 | (make-completer
319 | (cond ((string-prefix? default-gash-begin-scheme-string current-word)
320 | (set! *readline-generator-function* apropos-completion-function-test)
321 | #t)
322 | ((string-prefix? "(" current-word)
323 | (set! *readline-generator-function* apropos-completion-function-test)
324 | #t)
325 | ((equal? start 0)
326 | (set! *readline-generator-function* commands-completion-function)
327 | #t)
328 | (else #f))))
329 |
330 | (define (completer-switch text start end)
331 | (let* ((line (get-line-contents))
332 | (split-line (string-split line #\space))
333 | (current-word (last split-line)))
334 | (cond ((string-prefix? "§(" current-word)
335 | (set! *readline-generator-function* apropos-completion-function-test)
336 | #t)
337 | ((string-prefix? "(" current-word)
338 | (set! *readline-generator-function* apropos-completion-function-test)
339 | #t)
340 | ((equal? start 0)
341 | (set! *readline-generator-function* commands-completion-function)
342 | #t)
343 | (else #f))))
344 |
345 | (define (completer-for-alt text start end)
346 | "return #f to indicate we want to return NULL in the c function and
347 | subsequently use filename completion. return #t to call the
348 | *readline-generator-function* that MUST be defined. if we want to switch
349 | between readline generator functions then EVERY condition MUST set up its
350 | own readline function, or return #f. "
351 | ;; (echo "in completer-for-alt")
352 | (cond ((equal? start 0)
353 | ;; (echo "start is 0")
354 | (echo (get-line-contents))
355 | (set! *readline-generator-function* commands-completion-function)
356 | #t)
357 | ;; ((string=? text "")
358 | ;; #f)
359 | ;; ((string=? "§(" text)
360 | ;; (echo text) #t)
361 | ((string-prefix? "§(" text)
362 | (set! *readline-generator-function* apropos-completion-function-test)
363 | ;; (echo "readline-generator-function is apropos function")
364 | (echo (get-line-contents))
365 | #t)
366 | (else #f)))
367 |
368 | (define (read-test)
369 | (read-with-prompt (generate-prompt)))
370 |
371 | (define (read-attempt-comp)
372 | ;; (set! *readline-alt-completion-function* completer-for-alt)
373 | ;; (set! *readline-alt-completion-function* completer-switch)
374 | (set! *readline-alt-completion-function* default-gash-completer)
375 | (read-with-prompt (generate-prompt)))
376 |
377 | (define (read-and-interpret)
378 | ;; (echo "main-loop")
379 | (let ((prompt ;; (get-string-from-user)
380 | ;; (read-with-prompt (generate-prompt))
381 | (read-attempt-comp)
382 | ))
383 | ;; (display "prompted text: ") (echo prompt)
384 | (when *history*
385 | (add-history-item prompt))
386 | (when prompt ; unless (not prompt)
387 | (if (string=? prompt "")
388 | (read-and-interpret)
389 | (let* ((scheme-replaced
390 | (string-app-list
391 | (eval/replace-scheme-string (extract-scheme-strings prompt))))
392 | (tokens (string-split scheme-replaced #\space))
393 | (func (assoc (car tokens)
394 | *builtins-alist*)))
395 | ;; (display "scheme replaced string: ")(echo scheme-replaced)
396 | (if func ;; if the first element is a builtin
397 | (let ((strs ((cdr func) tokens)))
398 | (unless (null? strs)
399 | (system (join-strings (replace-shorthand strs) " "))))
400 | (let ((longhand (replace-shorthand tokens)))
401 | (system (join-strings longhand " ")))))))))
402 |
403 | (define (loop-handler)
404 | (with-throw-handler #t
405 | (lambda ()
406 | (while 1
407 | (read-and-interpret)))
408 | (lambda (key . args)
409 | (cond ((equal? key 'quit)
410 | (exit))
411 | (else
412 | (unless *suppress-error-messages*
413 | (display-color 1 "ERROR: ")
414 | (display key) (display ", ")
415 | (map (lambda (el) (display el) (display ", ")) args)
416 | ;; (newline)
417 | ;; (display (format args))
418 | )
419 | ;; (echo args)
420 | (loop-handler))))))
421 |
422 | (define builtins-list-for-completions
423 | ;; complete for builtins as well in the first position.
424 | (map (lambda (el)
425 | (car el))
426 | *builtins-alist*))
427 |
428 | (define (main . args)
429 | (load (string-append home-directory "/.gashrc"))
430 | (display "loaded ") (echo (string-append home-directory "/.gashrc"))
431 | (set! *all-programs* (append builtins-list-for-completions *all-programs*))
432 | ;; (let ((port (open-file "gash.log" "w")))
433 | ;; (display "GASH logfile" port) (newline port) (newline port)
434 | ;; (close-port port))
435 | (loop-handler))
436 |
437 |
438 |
--------------------------------------------------------------------------------
/history.scm:
--------------------------------------------------------------------------------
1 | (define *history* #t)
2 |
3 | (define *max-history* 1000)
4 |
5 | (define *history-count* 0)
6 |
7 | (define *history-holder* '())
8 |
9 | (define *history-rules-inclusive* #f)
10 |
11 | (define *history-rules* '())
12 |
13 | (define (define-history-rule function)
14 | "adds a lamda to the list of lambdas to compute whether or not to add an item
15 | to the history list. "
16 | (set! *history-rules* (cons function *history-rules*)))
17 |
18 | (define (add-history-item text)
19 | (let ((list-of-t-f (map (lambda (el)
20 | (el text))
21 | *history-rules*)))
22 | (if *history-rules-inclusive*
23 | (if (member #t list-of-t-f)
24 | (begin (set! *history-count* (+ *history-count* 1))
25 | (set! *history-holder* (cons text *history-holder*))))
26 | (if (not (member #f list-of-t-f))
27 | (begin (set! *history-count* (+ *history-count* 1))
28 | (set! *history-holder* (cons text *history-holder*))))))
29 | (if (or (equal? *history-count* *max-history*)
30 | (> *history-count* *max-history*))
31 | (begin ;; (echo "in if true")
32 | (set! *history-holder* (list-head *history-holder*
33 | (- *max-history* 1)))
34 | (set! *history-count* (- *max-history* 1)))))
35 |
36 | (define (history-previous-entry . l)
37 | (if (null? l)
38 | (second *history-holder*)
39 | (let ((contents (cdr *history-holder*))
40 | (num (car l)))
41 | (if (> num (length contents))
42 | ;; (echo-color 1 "")
43 | (throw 'out-of-range "Within history-previous-entry: attempted to reference history item that doesnt exist")
44 | (list-ref contents num)))))
45 |
--------------------------------------------------------------------------------
/libgash.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #define MAXCOM 1000 // max number of letters to be supported
13 | #define MAXLIST 100 // max number of commands to be supported
14 |
15 | // Clearing the shell using escape sequences
16 | #define clear() printf("\033[H\033[J")
17 |
18 | char* cat3(const char *s1, const char *s2, const char *s3)
19 | {
20 | char *ret = malloc(strlen(s1) + strlen(s2) + strlen(s3) + 1);
21 | strcpy(ret, s1);
22 | strcat(ret, s2);
23 | strcat(ret, s3);
24 | return ret;
25 | }
26 |
27 | char* concatenate(const char *s1, const char *s2, const char *s3, const char *s4)
28 | {
29 | char *ret = malloc(strlen(s1) + strlen(s2) + strlen(s3) + strlen(s4) + 1);
30 | strcpy(ret, s1);
31 | strcat(ret, s2);
32 | strcat(ret, s3);
33 | strcat(ret, s4);
34 | return ret;
35 | }
36 |
37 | // get stuff from the user.
38 | int get_string_from_user(char* str)
39 | {
40 | char* buffer;
41 | char* prompt;
42 | char* pre_prompt;
43 | char *user=getenv("USER");
44 | char hostname [1024];
45 | gethostname(hostname, 1023);
46 | char cwd[PATH_MAX];
47 | if (getcwd(cwd, sizeof(cwd) - 1) == NULL){
48 | strcpy(cwd, "ERR finding directory");
49 | }
50 | // we need to purge all but the last entity of cwd
51 |
52 |
53 | pre_prompt = concatenate("[\033[38;5;6m", user, "@", hostname);
54 | prompt = concatenate(pre_prompt, " ", cwd, "\033[0m]» ");
55 | free(pre_prompt);
56 | // char* username = getenv("USER");
57 | buffer = readline(prompt);
58 | free(prompt);
59 | /* if (buffer && *buffer){ */
60 | /* add_history(buffer); */
61 | /* strcpy(str, buffer); */
62 | /* return 0; */
63 | /* } */
64 | if (strlen(buffer) != 0) {
65 | add_history(buffer);
66 | strcpy(str, buffer);
67 | return 0;
68 | } else {
69 | return 1;
70 | }
71 | }
72 |
73 | int get_string_from_user_with_prompt(char* str, char* prompt)
74 | {
75 | char* buffer;
76 | char* directory;
77 | // char* username = getenv("USER");
78 | // readline uses \001 and \002 to determine what should be counted when
79 | // counting the prompt characters.
80 | char* printer = cat3("[\001\033[38;5;6m\002", prompt, "\001\033[m\002]» ");
81 | // dont forget to free printer - its cat-ed so we need to free it.
82 | fflush(stdout);
83 | // printf("in read-with-prompt, before reading\n");
84 | buffer = readline(printer);
85 | // printf("after reading\n");
86 | // buffer = readline ("prompt");
87 |
88 | free(printer);
89 | if (buffer == NULL){
90 | return 1;}
91 | if (strlen(buffer) != 0) {
92 | add_history(buffer);
93 | strcpy(str, buffer);
94 | return 0;
95 | } else {
96 | return 1;
97 | }
98 | }
99 |
100 | /*
101 | char **command_generator(const char *text, int state)
102 | {
103 | SCM function_sym = scm_c_lookup("command-completer");
104 | SCM func_val = scm_variable_ref(function_sym);
105 | SCM ret_val = scm_call_2(func_val, scm_from_locale_string(text),
106 | scm_from_bool(state));
107 | if (scm_is_bool(ret_val) == 1)
108 | return ((char *)NULL);
109 | return scm_from_locale_string(ret_val);
110 | }
111 |
112 | char **smart_completion(char *text, int start, int end)
113 | {
114 | char **matches;
115 |
116 | matches = (char **)NULL;
117 |
118 | if (start == 0)
119 | matches = rl_completion_matches(text, command_generator);
120 | return (matches);
121 | }
122 |
123 | char **completer_test(const char *text, int state)
124 | {
125 | SCM function_sym = scm_c_lookup("command-completer");
126 | SCM func_val = scm_variable_ref(function_sym);
127 | SCM ret_val = scm_call_2(func_val, scm_from_locale_string(text),
128 | scm_from_bool(state));
129 | if (scm_is_bool(ret_val) == 1)
130 | return ((char *)NULL);
131 | return scm_from_locale_string(ret_val);
132 | }
133 |
134 | void initialize_readline ()
135 | {
136 | rl_readline_name = "GASH";
137 | rl_attempted_completion_function = smart_completion;
138 | }
139 | */
140 |
141 |
142 | SCM get_string_from_user_scm_wrapper()
143 | {
144 | char str[MAXCOM];
145 | int x = get_string_from_user(str);
146 | if (x == 0)
147 | return scm_from_locale_string(str);
148 | // return scm_from_locale_string(str);
149 | return scm_from_locale_string("");
150 | }
151 |
152 | SCM is_string_directory(SCM path)
153 | {
154 | struct stat sb;
155 | int exists = stat(scm_to_locale_string(path), &sb);
156 | if (exists == -1)
157 | return scm_from_bool(0);
158 | if (exists == 0 && S_ISDIR(sb.st_mode))
159 | return scm_from_bool(1);
160 | return scm_from_bool(0);
161 | }
162 |
163 | // int get_string_from_user_with_prompt(char* str, char* prompt)
164 | SCM get_string_from_user_with_prompt_scm_wrapper(SCM prompt)
165 | {
166 | char str[MAXCOM];
167 | int x = get_string_from_user_with_prompt(str, scm_to_locale_string(prompt));
168 | if (x == 0)
169 | return scm_from_locale_string(str);
170 | return scm_from_bool(0);
171 | }
172 |
173 | SCM scheme_strncmp(SCM string1, SCM string2, SCM length)
174 | {
175 | return scm_from_int
176 | (strncmp(scm_to_locale_string(string1),
177 | scm_to_locale_string(string2),
178 | scm_to_int(length)));
179 | }
180 |
181 | SCM scheme_expose_filename_completion_function(SCM text, SCM state)
182 | {
183 | // printf("within exposed function\n");
184 | char *str = rl_filename_completion_function(scm_to_locale_string(text),
185 | scm_to_int(state));
186 | // printf("after filename completion called\n");
187 | if (str == NULL){
188 | // printf("str is NULL\n");
189 | return scm_from_bool(0);
190 | }
191 | // printf("str is not NULL\n");
192 | return scm_from_locale_string(str);
193 | }
194 |
195 | SCM scm_readline_generator_function_var;
196 |
197 | char * scheme_generator_function(char *text, int state)
198 | {
199 | char *ret;
200 | SCM res, t, s;
201 | // printf("in scheme_generator_function\n");
202 | SCM strf = SCM_VARIABLE_REF(scm_readline_generator_function_var);
203 | // printf("pre if in scheme_generator_function\n");
204 | if (scm_is_false(strf)){
205 | printf("in the if in scheme_generator_function\n");
206 | return ((char *) NULL);
207 | }
208 | // printf("post if in scheme_generator_function\n");
209 | t = scm_from_locale_string(text);
210 | s = scm_from_bool(state);
211 | // printf("pre res set\n");
212 | res = scm_apply (strf, scm_list_2(t, s), SCM_EOL);
213 | // printf("res is set\n");
214 | if (scm_is_false(res)){
215 | return ((char *)NULL);
216 | }
217 | ret = scm_to_locale_string(res);
218 | // printf("weve assigned ret in scheme_generator_function\n");
219 |
220 | return ret;
221 | }
222 |
223 | SCM scm_get_rl_line_buffer()
224 | {
225 | return scm_from_locale_string(rl_line_buffer);
226 | }
227 |
228 | SCM scm_readline_alt_completion_function_var;
229 | SCM scm_readline_matches_fun;
230 |
231 | char **
232 | alt_completer(char *text, int start, int end)
233 | {
234 | SCM compf = SCM_VARIABLE_REF (scm_readline_alt_completion_function_var);
235 | SCM res, t, s, e;
236 | int length, i;
237 | char ** reter = (char **)NULL;
238 | // printf("pre if statement\n");
239 | if (scm_is_false (compf)){
240 | // printf("completer-for-alt returned false");
241 | return reter;
242 | }
243 | else {
244 | // printf("compf WASNT false\n");
245 | t = scm_from_locale_string(text);
246 | s = scm_from_int(start);
247 | e = scm_from_int(end);
248 | // printf("pre scm_apply\n");
249 | res = scm_apply (compf, scm_list_3 (t, s, e), SCM_EOL);
250 | // printf("passed res = scm_apply (compf...)\n");
251 | if (scm_is_false (res)) {
252 | // printf("res is false\n");
253 | return reter;
254 | }
255 | // printf("about to set reter...\n");
256 | reter = rl_completion_matches(text, scheme_generator_function);
257 | // printf("reter is set\n");
258 | /* for (i = 0; i < length ; i++) {
259 | reter[i] = scm_to_locale_string(scm_car(res));
260 | printf(reter[i]);
261 | printf("\n");
262 | res = scm_cdr(res);
263 | } */
264 |
265 | return reter ; //(reter);
266 | }
267 | }
268 |
269 | /* int log(char *text) */
270 | /* { */
271 | /* FILE *log; */
272 | /* log = fopen("gash.log", "a"); */
273 | /* if (log == NULL){ */
274 | /* fclose(log); */
275 | /* return 0; */
276 | /* } */
277 | /* fprintf(log, text); */
278 | /* fclose(log); */
279 | /* return 1; */
280 | /* } */
281 |
282 | /* SCM scm_write_to_log(SCM text) */
283 | /* { */
284 | /* int ret = log(scm_to_locale_string(text)); */
285 | /* return scm_from_bool(ret); */
286 | /* } */
287 |
288 | void init_gash_c()
289 | {
290 | /* FILE * logg = fopen("gash.log", "w"); */
291 | /* fclose(logg); */
292 | /* int i = log("beginning GASH log\n\n"); */
293 |
294 | scm_readline_generator_function_var
295 | = scm_c_define("*readline-generator-function*", SCM_BOOL_F);
296 | scm_readline_alt_completion_function_var
297 | = scm_c_define("*readline-alt-completion-function*", SCM_BOOL_F);
298 | rl_attempted_completion_function = (rl_compentry_func_t*) alt_completer;
299 |
300 | // scm_c_define_gsubr("write-to-log", 1, 0, 0, scm_write_to_log);
301 | scm_c_define_gsubr("get-line-contents", 0, 0, 0, scm_get_rl_line_buffer);
302 | scm_c_define_gsubr("exposed-file-completion-function", 2, 0, 0,
303 | scheme_expose_filename_completion_function);
304 | scm_c_define_gsubr
305 | ("c-strncmp", 3, 0, 0, scheme_strncmp);
306 | scm_c_define_gsubr
307 | ("get-string-from-user", 0, 0, 0, get_string_from_user_scm_wrapper);
308 | scm_c_define_gsubr
309 | ("read-with-prompt", 1, 0, 0, get_string_from_user_with_prompt_scm_wrapper);
310 | scm_c_define_gsubr
311 | ("directory?", 1, 0, 0, is_string_directory);
312 | }
313 |
314 | /* compile with:
315 | gcc `pkg-config --cflags guile-2.2` -shared -o lib-c-funcs.so -fPIC c-funcs.c -l readline
316 | */
317 |
--------------------------------------------------------------------------------
/reference.org:
--------------------------------------------------------------------------------
1 | * This is a reference manual thing for GASH.
2 | This document contains a list of variables and functions, and describes general functionality of GASH.
3 | ** History
4 | *** Variables:
5 | - *history*
6 | This variable controls whether history is enabled. Set to #f to disable all history
7 | - *max-history*
8 | Controls the maximum number of stored history entries. Defaults to 1000
9 | - *history-count*
10 | The current number of items in history
11 | - *history-holder*
12 | This stores the history entries, in a list.
13 | - *history-rules*
14 | A list of functions that are used to determine when to add something to the history.
15 | - *history-rules-inclusive*
16 | This controls behavior when adding an item to history. To add an item, we call every function in *history-rules* on the text we want to add. Each of these functions MUST return either #t or #f. Once we have a list of every functions true/false return value, we use *history-rules-inclusive*. If its #t, then if a SINGLE function in *history-rules* returned true, we add the text to *history-holder*. If *history-rules-inclusive* is #f, then if a single function returned false we dont add the text to history.
17 | *** Functions:
18 | - define-history-rule function
19 | Adds a single rule to *history-rules* in the form of function. Function MUST return true/false. Example call:
20 | #+BEGIN_SRC guile
21 | (define-history-rule
22 | (lambda (txt)
23 | (if (string=? txt (history-prev-entry-internal))
24 | #f
25 | #t)))
26 | #+END_SRC
27 | - add-history-item text
28 | takes a string, text, and performs a series of checks via *history-rules* to determine whether or not to add text to the history. Example call: (add-history-item "some text for the history")
29 | - history-previous-entry . l
30 | Takes an optional argument, l, which if provided should be an integer. If its provided we get the lth element within history, NOT counting the first element. This is due to the usage of add-history-item within our main loop. We add an item to history immediatly after prompting for it. Therefore, the VERY FIRST item in history is the previous line. This function is designed for use from the shell, and we dont want to return the line we just typed in, so we return the actual previous line, which is in the second position in history, not first.
31 | - history-prev-entry-internal
32 | This takes no arguments - its for use within gash functions. it returns the item most recently added to history. Youll notice its presence in the source block above. It is used instead of history-previous-entry because it is called in the history adding function to determine whether to add something. thus, if we want to get the actual previous line, we want the actual head of the history list.
33 | *** Functionality:
34 | This is provided for grabbing history items and using them within the shell and within guile. These functions and variables have NO relation to the readline history. However it would be optimal to integrate the two, instead of having two seperate history stacks.
35 | ** Errors
36 | *** Variable:
37 | - *supress-error-messages*
38 | This variable defaults to #f, set to #t to suppress all error messages.
39 | *** Functions:
40 | *** Functionality:
41 | GASH handles errors such that they will (hopefully) never cause gash to exit. We do this by wrapping up our loop within a call to with-throw-handler that is passed #t for the key. This causes it to match with EVERY key thrown. If an error is encountered, we check if the key is 'quit, and if it is we call exit. otherwise, we re-call our loop handler. Before that, however, if *supress-error-messages* is #f we display our error for the user.
42 | ** Completion
43 | *** Variables:
44 | - *readline-generator-function*
45 | This variable holds a function which we will call for completions from readline. This function is a traditional readline generator function, which takes text and state variables. These types of functions are covered in the readline portion of the guile manual.
46 | - *readline-alt-completion-function*
47 | Similar to the above variable, this holds a function. This function should take text, start, and end variables. This function should return #t or #f to choose whether to use our *readline-generator-function* to make completions, or if we should use the builtin filename completion. If we return #t we will use our generator function.
48 | *** Functions:
49 | *** Functionality:
50 | I didnt find the functionality I needed within the basic guile readline library, so I added my own bindings via libgash.c.
51 | ** Shorthand and Builtins
52 | *** Variables:
53 | *** Functions:
54 | - define-shorthand from to
55 | defines a shorthand key-value pair and adds it to the shorthand alist. every instance of from will be set to to
56 | - define-builtin name lambda
57 | adds a key value paer of name . lambda to the builtins alist. Name should be a string, and lambda should be a function to call which takes a list and returns a list. The list taken in is a list of tokens - its a tokenized version of the command line. This list includes the builtin that triggered it. The builtins function should do its thing, and then return a list of tokens to be run. So, for example, we could pass something that echoes the current working directory after dealing with the logic of cd.
58 |
59 | *** Functionality:
60 |
61 |
--------------------------------------------------------------------------------