├── LICENSE
├── README.md
├── ddgsearch
├── dkr
├── fv
├── fzaur
├── fzbuku
├── fzgit
├── fzmp
├── fzmv
├── fzrepl
├── fztop
├── gitup
├── igr
├── ix
├── js
├── pkgrm
├── pkgsearch
├── pkgup
├── sshget
└── wifi
/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 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
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 | {project} Copyright (C) {year} {fullname}
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 | # fzf-scripts
2 |
3 | This is a collection of scripts I've written that use [fzf](https://github.com/junegunn/fzf)
4 |
5 | Almost all of them require various tools from coreutils like `awk` `sed` `cut`, and probably make use of GNU extensions.
6 |
7 | ## [dkr](dkr)
8 |
9 | an interactive wrapper around some docker commands
10 |
11 | ## [fv](fv)
12 |
13 | Lists or searches for files and opens them with a command, defaults to `vim`. Kind of a shortcut for `vim $(ag 'foo' | fzf)`, lists files if no search string is given.
14 |
15 | ## [fzgit](fzgit)
16 |
17 | Interactive git wrapper. Very much still a work in progress, but it has some very cool functions already.
18 |
19 | *depends on `git` and `perl`*
20 |
21 | ## [fzbuku](fzbuku)
22 |
23 | A small wrapper around [buku](https://github.com/jarun/Buku) to search bookmarks
24 |
25 | ## [fzmp](fzmp)
26 |
27 | Lists and searches for songs in an MPD library by artist, album, or playlist. I wrote a [blog post](https://danielfgray.gitlab.io/computers/fzmp) about writing this script.
28 |
29 | *depends on `mpc`*
30 |
31 | ## [fzmv](fzmv)
32 |
33 | Interactively move files. It was originally just an experiment to see what it would be like to make a file explorer with fzf.
34 |
35 | ## [fzrepl](fzrepl)
36 |
37 | runs stdin against programs like sed, awk, jq and shows the result in the preview window
38 |
39 | ## [ddgsearch](ddgsearch)
40 |
41 | A wrapper around [ddgr](https://github.com/jarun/ddgr) to search the web using DuckDuckGo.
42 | Accepts all `ddgr` command line arguments. For example, to search Wikipedia for "hello world":
43 |
44 | ```sh
45 | ddgsearch \!w hello world
46 | ```
47 |
48 | *depends on `jq` and `ddgr`*
49 |
50 | ## [igr](igr)
51 |
52 | Interactive grep/rg wrapper
53 |
54 | ## [ix](ix)
55 |
56 | Uploads files to [ix.io](http://ix.io) and allows listing and editing of uploads.
57 |
58 | *depends on `curl`*
59 |
60 | ## [js](js)
61 |
62 | Searches [npmjs.com](https://npmjs.com) and installs packages with `yarn` if available or `npm`.
63 |
64 | *depends on npm and [jq](https://stedolan.github.io/jq/)*
65 |
66 | ## [pkgsearch](pkgsearch)
67 |
68 | Searches repos and installs multiple packages. Currently works with Debian, Ubuntu and Arch, and experimental support for Fedora and Void.
69 |
70 | ## [pkgrm](pkgrm)
71 |
72 | Lists and removes packages, optionally sorts by size.
73 |
74 | *depends on `pacman`*
75 |
76 | ## [sshget](sshget)
77 |
78 | Lists files from remote servers and `rsync`s them to the current directory
79 |
80 | ## [wifi](wifi)
81 |
82 | List and connect to wifi networks
83 |
84 | *depends on `nmcli`*
85 |
86 | # Install
87 |
88 | Currently there's no installation script, but if you clone the repo you can easily symlink the scripts here with something like:
89 |
90 | ```sh
91 | cd /path/to/repo/fzf-scripts
92 | find -maxdepth 1 -executable -type f -exec ln -s -t $HOME/.local/bin $PWD/fzf-scripts/{} \;
93 | ```
94 |
95 | # Notable Mentions
96 |
97 | * [forgit](https://github.com/wfxr/forgit) - a better version of fzgit
98 | * [fzf-tab](https://github.com/Aloxaf/fzf-tab) - use fzf to tab-complete everything in your shell
99 |
100 | # Legal
101 |
102 | Copyright (C) 2023 Ronald Joe Record
103 | Copyright (C) 2016 Daniel F Gray
104 |
105 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
106 |
107 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
108 |
109 | You should have received a copy of the GNU General Public License along with this program. If not, see .
110 |
--------------------------------------------------------------------------------
/ddgsearch:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -r esc=$'\033'
4 | declare -r c_reset="${esc}[0m"
5 | declare -r c_red="${esc}[31m"
6 |
7 | err() {
8 | printf "${c_red}%s${c_reset}\n" "$*" >&2
9 | }
10 |
11 | die() {
12 | [[ -n "$1" ]] && err "$1"
13 | exit 1
14 | }
15 |
16 | has() {
17 | local verbose=0
18 | if [[ $1 == '-v' ]]; then
19 | verbose=1
20 | shift
21 | fi
22 | for c; do c="${c%% *}"
23 | if ! command -v "$c" &> /dev/null; then
24 | (( verbose > 0 )) && err "$c not found"
25 | return 1
26 | fi
27 | done
28 | }
29 |
30 | select_from() {
31 | local o c cmd OPTARG OPTIND
32 | cmd='command -v'
33 | while getopts 'c:' o; do
34 | case "$o" in
35 | c) cmd="$OPTARG" ;;
36 | esac
37 | done
38 | shift "$((OPTIND-1))"
39 | for c; do
40 | if $cmd "${c%% *}" &> /dev/null; then
41 | echo "$c"
42 | return 0
43 | fi
44 | done
45 | return 1
46 | }
47 |
48 | openurl() {
49 | local url="$1"
50 | local browser
51 | case "$url" in
52 | *youtube.com*|*youtu.be*|*vimeo.com*)
53 | browser=$(select_from mpv mplayer2 mplayer) ;;
54 | *)
55 | browser=$(select_from -c "pgrep -u $USER -i" firefox chromium-browser chrome)
56 | [[ -z $browser ]] && browser='w3m' ;;
57 | esac
58 | $browser "$url"
59 | }
60 |
61 | has -v ddgr jq fzf || die
62 |
63 | if [[ -z "$*" ]]; then
64 | die 'nothing to search for'
65 | fi
66 |
67 | response=$( ddgr --json --noprompt --expand "$*" ) || die 'error connecting to DuckDuckGo, check connection'
68 | json=$(jq -rc '. | map("\(.url)\t\(.title) - \(.abstract)") | .[]' <<< "$response") || die 'error parsing results :('
69 | url=$(fzf -e --ansi --cycle --inline-info --select-1 --with-nth=2.. <<< "$json" | awk '{print $1}')
70 |
71 | if [[ -n $url ]]; then
72 | openurl "$url"
73 | fi
74 |
--------------------------------------------------------------------------------
/dkr:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -A aliases
4 | declare -A helptext
5 |
6 | has() {
7 | local v c
8 | if [[ $1 = '-v' ]]; then
9 | v=1
10 | shift
11 | fi
12 | for c; do c="${c%% *}"
13 | if ! command -v "$c" &> /dev/null; then
14 | (( v > 0 )) && err "$c not found"
15 | return 1
16 | fi
17 | done
18 | }
19 |
20 | aliases[h]=help
21 | aliases[-h]=help
22 | aliases[--help]=help
23 | helptext[help]='show this help'
24 | subcmd_help() {
25 | local formattedhelptext
26 |
27 | formattedhelptext=$(for c in "${subcmds_avail[@]}"; do
28 | printf " %s\n %s\n" "$c" "${helptext[$c]}"
29 | done)
30 | LESS=-FEXR less <<-HELP
31 | $0
32 |
33 | ${formattedhelptext}
34 | HELP
35 | }
36 |
37 | helptext[ps]='show a list of running processes'
38 | subcmd_ps() {
39 | fzf \
40 | --bind='start:reload:docker ps' \
41 | --bind='enter:execute:docker exec -it {1} sh' \
42 | --bind='ctrl-d:execute-silent(docker stop {1})+reload:docker ps' \
43 | --bind='?:toggle-preview' \
44 | --bind='ctrl-l:clear-screen+reload:docker ps' \
45 | --preview='docker logs -f {1}' \
46 | --header=' opens sh inside container, to kill' \
47 | --reverse \
48 | --height=100% \
49 | --header-lines=1 \
50 | --preview-window=cycle,follow,80%:down
51 | }
52 |
53 | mapfile -t subcmds_avail < <(compgen -A function | awk '/^subcmd_/ { sub(/^subcmd_/, "", $0); print }')
54 |
55 | nocmd() {
56 | cmd=$(for c in "${subcmds_avail[@]}"; do
57 | printf "$c\t${help}\t${helptext[$c]}\n"
58 | done)
59 | subcmd_$(column -t -s $'\t' <<< "$cmd" | fzf | awk '{print $1}')
60 | }
61 |
62 | if (( $# < 1 )); then
63 | nocmd
64 | exit 1
65 | elif has "subcmd_$1"; then
66 | subcmd="subcmd_$1"
67 | shift
68 | "$subcmd" "$@"
69 | elif [[ -v aliases[$1] ]]; then
70 | subcmd=subcmd_${aliases[$1]}
71 | shift
72 | "$subcmd" "$@"
73 | else
74 | echo 'unknown command'
75 | subcmd_help
76 | exit 1
77 | fi
78 |
--------------------------------------------------------------------------------
/fv:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | usage() {
4 | LESS=-FEXR less <<'HELP'
5 | fv [OPTIONS] [SEARCH]
6 | fuzzy file filtering and command executing
7 |
8 | a) allfiles=1 ;;
9 | c) cmd="$OPTARG" ;;
10 | d) dtach=1 ;;
11 | o) loop=1 ;;
12 | s) small=1 ;;
13 |
14 | -a search all dirs and hidden files (possibly quirky)
15 | -c command to execute [defaults to vim]
16 | -d run in background (for ie non-terminal programs)
17 | -h show this help
18 | -l additional arguments to pass to filtering program
19 | -o run continuously
20 | -s run in a smaller window
21 | HELP
22 | }
23 |
24 | declare cmd=''
25 | declare cmdopts=()
26 | declare search_str=''
27 | declare search_cmd=''
28 | declare search_opts=()
29 | declare allfiles=''
30 | declare loop
31 | declare small
32 | declare -A colors
33 | colors[red]=$(tput setaf 1)
34 | colors[green]=$(tput setaf 2)
35 | colors[blue]=$(tput setaf 4)
36 | colors[reset]=$(tput sgr0)
37 |
38 | color() {
39 | local c
40 | c="$1"
41 | shift
42 | printf '%s' "${colors[$c]}"
43 | printf '%s\n' "$@"
44 | printf '%s' "${colors[reset]}"
45 | }
46 |
47 | err() {
48 | color red "$@" >&2
49 | }
50 |
51 | die() {
52 | [[ -n "$1" ]] && err "$1"
53 | exit 1
54 | }
55 |
56 | has() {
57 | local o c verbose
58 | verbose=0
59 | while getopts 'v' o; do
60 | case "$o" in
61 | v) v=1 ;;
62 | esac
63 | done
64 | shift "$((OPTIND-1))"
65 | for c; do c="${c%% *}"
66 | if ! command -v "$c" &> /dev/null; then
67 | (( verbose > 0 )) && err "$c not found"
68 | return 1
69 | fi
70 | done
71 | }
72 |
73 | select_from() {
74 | local o c cmd OPTARG OPTIND
75 | cmd='command -v'
76 | while getopts 'c:' o; do
77 | case "$o" in
78 | c) cmd="$OPTARG" ;;
79 | esac
80 | done
81 | shift "$((OPTIND-1))"
82 | for c; do
83 | if $cmd "${c%% *}" &> /dev/null; then
84 | echo "$c"
85 | return 0
86 | fi
87 | done
88 | return 1
89 | }
90 |
91 | while getopts 'ac:dhlos' opt; do
92 | case "$opt" in
93 | a) allfiles=1 ;;
94 | c) cmd="$OPTARG" ;;
95 | d) dtach=1 ;;
96 | h) usage; exit 0 ;;
97 | l) search_opts+=( '-l' ) ;;
98 | o) loop=1 ;;
99 | s) small=1 ;;
100 | esac
101 | done
102 | shift "$((OPTIND-1))"
103 |
104 | has -v 'fzf' || die
105 |
106 | if [[ -v FV_CMD ]]; then
107 | cmd="$FV_CMD"
108 | elif [[ -z "$cmd" ]]; then
109 | cmd=$(select_from 'v' 'vim')
110 | fi
111 |
112 |
113 | if [[ -v FV_SEARCH ]]; then
114 | search_cmd="$FV_SEARCH"
115 | else
116 | search_cmd=$(select_from 'ag' 'ack' 'grep')
117 | fi
118 |
119 | if [[ "$search_cmd" == 'grep' ]]; then
120 | err 'grep is slow, you should strongly consider installing ag or ack'
121 | sleep .75
122 | fi
123 |
124 | if [[ -n "$1" ]]; then
125 | if [[ -e "$1" ]]; then
126 | search_opts+=( "$1" )
127 | else
128 | search_str="$1"
129 | fi
130 | shift
131 | fi
132 |
133 | case "$search_cmd" in
134 | 'ag')
135 | search_opts+=( '--color' )
136 | if [[ -n "$allfiles" ]]; then
137 | search_opts+=( '-u' '--hidden' )
138 | fi
139 | if [[ "$search_str" == '' ]]; then
140 | search_opts+=( '-l' )
141 | fi ;;
142 | 'ack')
143 | if [[ "$search_str" == '' ]]; then
144 | if [[ -z "$allfiles" ]]; then
145 | search_opts+=( '-f' )
146 | else
147 | search_opts+=( '-g' '^[^\.]' )
148 | fi
149 | else
150 | search_opts+=( '-l' )
151 | # search_opts+=( '--match' )
152 | fi ;;
153 | 'grep')
154 | search_opts+=( '-r' '-I' )
155 | if [[ -z "$allfiles" ]]; then
156 | if [[ -r ~/.ignore ]]; then
157 | while read -r line; do
158 | search_opts+=( "--exclude-dir=$line" )
159 | done < ~/.ignore
160 | else
161 | search_opts+=( '--exclude-dir=bower_components' )
162 | search_opts+=( '--exclude-dir=node_modules' )
163 | search_opts+=( '--exclude-dir=jspm_packages' )
164 | search_opts+=( '--exclude-dir=.cvs' )
165 | search_opts+=( '--exclude-dir=.git' )
166 | search_opts+=( '--exclude-dir=.hg' )
167 | search_opts+=( '--exclude-dir=.svn' )
168 | fi
169 | fi
170 | if [[ -z "$search_str" ]]; then
171 | search_opts+=( -F '' )
172 | else
173 | search_opts+=( -P )
174 | fi ;;
175 | esac
176 |
177 | if [[ "$search_str" != '' ]]; then
178 | search_opts+=( "$search_str" )
179 | fi
180 |
181 | main() {
182 | local highlight
183 | highlight=$(select_from 'bat --color=always --style=header' 'highlight -q --force -O ansi')
184 | choices=$($search_cmd "${search_opts[@]}" 2> /dev/null |
185 | fzf --ansi --multi --preview="[[ \$(file -ib {}) = *text* ]] && ${highlight} {}") || exit 1
186 |
187 | if [[ "$search_str" != '' ]]; then
188 | if [[ $search_cmd == 'ag' ]]; then
189 | choices=$(cut -d: -f1 <<< "$choices")
190 | fi
191 | fi
192 |
193 | mapfile -t choices <<< "$choices"
194 |
195 | if [[ $dtach ]]; then
196 | ($cmd "${cmdopts[@]}" "${choices[@]}" &> /dev/null &)
197 | else
198 | $cmd "${cmdopts[@]}" "${choices[@]}"
199 | fi
200 | }
201 |
202 | if [[ -n "$loop" ]]; then
203 | while main; do
204 | true
205 | done
206 | else
207 | main
208 | fi
209 |
--------------------------------------------------------------------------------
/fzaur:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -A aliases
4 | declare -A helptext
5 | declare -r c_reset=$(tput sgr0)
6 | declare -r c_red=$(tput setaf 1)
7 | declare -r c_green=$(tput setaf 2)
8 | declare -r c_yellow=$(tput setaf 3)
9 | declare -r c_grey=$(tput setaf 8)
10 |
11 | err() {
12 | printf "${c_red}%s${c_reset}\n" "$*" >&2
13 | }
14 |
15 | die() {
16 | if (( $# > 0 )); then
17 | err "$@"
18 | fi
19 | exit 1
20 | }
21 |
22 | has() {
23 | local v c
24 | if [[ $1 = '-v' ]]; then
25 | v=1
26 | shift
27 | fi
28 | for c; do c="${c%% *}"
29 | if ! command -v "$c" &> /dev/null; then
30 | (( v > 0 )) && err "$c not found"
31 | return 1
32 | fi
33 | done
34 | }
35 |
36 | aliases[h]=help
37 | aliases[-h]=help
38 | aliases[--help]=help
39 | helptext[help]='show this help'
40 | subcmd_help() {
41 | local formattedhelptext
42 |
43 | formattedhelptext=$(for c in "${subcmds_avail[@]}"; do
44 | printf " %s\n %s\n" "$c" "${helptext[$c]}"
45 | done)
46 | LESS=-FEXR less <<-HELP
47 | $0
48 |
49 | ${formattedhelptext}
50 | HELP
51 | }
52 |
53 | aliases[s]=search
54 | aliases[-s]=search
55 | helptext[search]='search packages on arch user repositories'
56 | subcmd_search() {
57 | local q="$*" choices
58 | # local search_cmd='curl -s https://www.archlinux.org/packages/search/json/ | jq -r ".results[] | select(.Name | contains(\"{q}\")) | .Name"'
59 | local url_search='https://aur.archlinux.org/rpc/v5/search/'
60 | local jq_package_listing=".results | sort_by(.NumVotes) | reverse[] | \"${c_yellow}\(.Name)${c_grey} - \(if .OutOfDate then \"${c_red}[out of date] \" else \"\" end)${c_green}▲\(.NumVotes)${c_grey} - ${c_reset}\(.Description)\""
61 |
62 | local url_info='https://aur.archlinux.org/rpc/v5/info?arg[]='
63 | local jq_package_info='.results[]'
64 |
65 | local cmd_search="curl -sL '${url_search}{q}' | jq -r '$jq_package_listing'"
66 | mapfile -t choices < <(fzf -m --phony --query="$q" \
67 | --preview="curl -sL '${url_info}{1}' | jq -C '$jq_package_info'" \
68 | --bind=change:"reload(${cmd_search})" \
69 | --bind=start:"reload(${cmd_search})" | awk '{print $1}')
70 |
71 | (( ${#choices[@]} < 1 )) && exit 0
72 | clone_package "${choices[0]}"
73 | }
74 |
75 | clone_package() {
76 | local pkg="$1" url
77 | if [[ $pkg != http* ]]; then
78 | url="https://aur.archlinux.org/${pkg}"
79 | fi
80 | # TODO: make this configurable
81 | local clonedir=~/.cache/fzaur
82 | if [[ ! -d "$clonedir/$pkg" ]]; then
83 | mkdir -p "$clonedir"
84 | fi
85 | cd "$clonedir" || die "failed to mkdir $clonedir"
86 | if [[ -d "$pkg" ]]; then
87 | cd "$pkg" 2> /dev/null || die 'failed to cd into package'
88 | if [[ ! -d .git ]]; then
89 | die "$clonedir/$pkg already exists but is not a git repo"
90 | fi
91 | git pull
92 | else
93 | git clone "$url" || die 'failed to clone package'
94 | cd "$pkg" 2> /dev/null || die 'failed to clone package'
95 | fi
96 | $EDITOR $PWD/PKGBUILD
97 | read -r -n 1 -p "press y to run ${c_green}makepkg -si${c_reset} or any other key to abort: "
98 | [[ $REPLY != y ]] && exit 1
99 | makepkg -si
100 | }
101 |
102 | has -v fzf jq curl || die
103 |
104 | mapfile -t subcmds_avail < <(compgen -A function | awk '/^subcmd_/ { sub(/^subcmd_/, "", $0); print }')
105 |
106 | nocmd() {
107 | local cmd=$(for c in "${subcmds_avail[@]}"; do
108 | printf "$c\t${help}\t${helptext[$c]}\n"
109 | done)
110 | local choice=$(<<< "$cmd" column -t -s $'\t' | fzf | awk '{print $1}')
111 | if [[ -z $choice ]]; then exit 1; fi
112 | subcmd_$choice
113 | }
114 |
115 | if (( $# < 1 )); then
116 | nocmd
117 | exit 1
118 | elif has "subcmd_$1"; then
119 | subcmd="subcmd_$1"
120 | shift
121 | "$subcmd" "$@"
122 | elif [[ -v aliases[$1] ]]; then
123 | subcmd=subcmd_${aliases[$1]}
124 | shift
125 | "$subcmd" "$@"
126 | else
127 | echo "unknown command \"$1\""
128 | subcmd_help
129 | exit 1
130 | fi
131 |
--------------------------------------------------------------------------------
/fzbuku:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | _video() {
4 | x-terminal-emulator -t mpv -e "mpv '$1'"
5 | }
6 | export -f _video
7 |
8 | _open() {
9 | case $1 in
10 | *youtube.com*) _video "$1" ;;
11 | *youtu.be*) _video "$1" ;;
12 | *vimeo.com*) _video "$1" ;;
13 | *) x-www-browser "$1" ;;
14 | esac
15 | }
16 | export -f _open
17 |
18 | printf -v jq '.[] | "\(.index) \(.uri) %s\(.tags)%s \(.title)"' "$(tput setaf 7)" "$(tput sgr0)"
19 |
20 | main() {
21 | local choice=()
22 | mapfile -t choice < <(buku -p -j |
23 | jq -r "$jq" |
24 | SHELL=bash fzf \
25 | --ansi \
26 | --tac \
27 | --bind='enter:execute: _open {2}' \
28 | --expect='ctrl-d,ctrl-e' \
29 | --delimiter=' ' \
30 | --height=100% \
31 | --no-hscroll \
32 | --preview-window=down \
33 | --preview='buku -p {1}; w3m {2}' \
34 | --query="$*" \
35 | --with-nth=3..)
36 |
37 | selection=${choice[@]:1}
38 |
39 | case ${choice[0]} in
40 | ctrl-d)
41 | buku -d ${selection[0]%% *}
42 | main
43 | ;;
44 | ctrl-e)
45 | buku -w ${selection[0]%% *}
46 | main
47 | ;;
48 | esac
49 | }
50 |
51 | main "$*"
52 |
--------------------------------------------------------------------------------
/fzgit:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -A aliases
4 | declare -A helptext
5 | declare -r c_reset=$(tput sgr0)
6 | declare -r c_red=$(tput setaf 1)
7 | declare -r c_green=$(tput setaf 2)
8 | declare -r c_yellow=$(tput setaf 3)
9 | declare -r c_grey=$(tput setaf 8)
10 |
11 | err() {
12 | printf "${c_red}%s${c_reset}\n" "$*" >&2
13 | }
14 |
15 | die() {
16 | if (( $# > 0 )); then
17 | err "$@"
18 | fi
19 | exit 1
20 | }
21 |
22 | has() {
23 | local v c
24 | if [[ $1 = '-v' ]]; then
25 | v=1
26 | shift
27 | fi
28 | for c; do c="${c%% *}"
29 | if ! command -v "$c" &> /dev/null; then
30 | (( v > 0 )) && err "$c not found"
31 | return 1
32 | fi
33 | done
34 | }
35 |
36 | aliases[-h]=help
37 | aliases[--help]=help
38 | helptext[help]='show this help'
39 | subcmd_help() {
40 | local formattedhelptext
41 |
42 | formattedhelptext=$(for c in "${subcmds_avail[@]}"; do
43 | printf " %s\n %s\n" "$c" "${helptext[$c]}"
44 | done)
45 | LESS=-FEXR less <<-HELP
46 | $0
47 |
48 | ${formattedhelptext}
49 | HELP
50 | }
51 |
52 | fzf() {
53 | local prompt
54 | if [[ $1 == --prompt=* ]]; then
55 | prompt="${1##*=}>"
56 | shift
57 | fi
58 | branch=$(git rev-parse --abbrev-ref HEAD)
59 | opts=( --prompt="fzgit${branch}>${prompt} " )
60 | [[ -v FZGIT_OPTIONS ]] && opts=( $FZGIT_OPTIONS )
61 | command fzf "${opts[@]}" \
62 | --inline-info \
63 | --ansi \
64 | --no-clear \
65 | "$@"
66 | }
67 |
68 | helptext[diff]='Show changes between commits, commit and working tree, etc'
69 | subcmd_diff() {
70 | if (( $# > 0 )); then git diff "$@"; return; fi
71 | fzf \
72 | --bind='start:reload:git -c color.status=always status -su' \
73 | --nth=2.. \
74 | --preview='git diff --color=always {2..} | delta -w $FZF_PREVIEW_COLUMNS' \
75 | --bind='enter:execute:git diff --color=always {2..}' \
76 | --preview-window=70%
77 | }
78 |
79 | helptext[add]='Add file contents to the index'
80 | subcmd_add() {
81 | if (( $# > 0 )); then git add "$@"; return; fi
82 | local diff
83 | diff=$(git diff --color=always | perl -pwe 's/^(\e\[[0-9;]*m)*(?=diff)/\0/m' | fzf --read0)
84 | [[ -z $diff ]] && return
85 | git apply --check --cached <<< "$diff" &&
86 | git apply --cached <<< "$diff" &&
87 | git apply --stat <<< "$diff"
88 | subcmd_add
89 | }
90 |
91 | helptext[status]='Show the working tree status'
92 | subcmd_status() {
93 | local preview='git diff --color=always {2..}'
94 | fzf \
95 | --nth=2.. \
96 | --bind='start:reload:git -c color.status=always status -s' \
97 | --preview="$preview" \
98 | --bind='enter:execute:git add -p {2..}'
99 | }
100 |
101 | helptext[checkout]='Checkout a branch or paths to the working tree'
102 | subcmd_checkout() { # {{{
103 | local list response key branch header
104 | if (( $# > 0 )); then git checkout "$@"; return; fi
105 | {
106 | git branch --all --color -vv
107 | git tag
108 | } |
109 | fzf --prompt='checkout' \
110 | --header="$header" \
111 | --bind=enter:execute:"git checkout \$(perl -pe 's/^\*?\s*(remotes\/[^\/]*\/)?([^ ]+).*/\2/' <<< {})"
112 |
113 | }
114 |
115 | helptext[stash-ls]='List the stash entries that you currently have'
116 | subcmd_stash-ls() {
117 | if (( $# > 0 )); then git stash "$@"; return; fi
118 | local header='use ctrl-d to show a diff or ctrl-b to create a new branch'
119 | git stash list --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs" |
120 | fzf --prompt='stash' --no-sort --header="$header" \
121 | --bind='ctrl-d:execute: git diff {1} --color=always | less -R' \
122 | --bind='ctrl-b:execute(git stash branch "stash-{1}" {1})+abort' \
123 | --preview='git diff --color {1}'
124 | }
125 |
126 | has -v fzf perl git || die
127 |
128 | mapfile -t subcmds_avail < <(compgen -A function | awk '/^subcmd_/ { sub(/^subcmd_/, "", $0); print }')
129 |
130 | nocmd() {
131 | local cmd
132 | cmd=$(for c in "${subcmds_avail[@]}"; do
133 | printf "$c\t${help}\t${helptext[$c]}\n"
134 | done)
135 | cmd=$(column -t -s $'\t' <<< "$cmd" | fzf | awk '{print $1}')
136 | if [[ -n $cmd ]]; then
137 | subcmd_$cmd
138 | else
139 | exit 1
140 | fi
141 | }
142 |
143 |
144 | if (( $# < 1 )); then
145 | nocmd
146 | exit 1
147 | elif has "subcmd_$1"; then
148 | subcmd="subcmd_$1"
149 | shift
150 | "$subcmd" "$@"
151 | elif [[ -v aliases[$1] ]]; then
152 | subcmd=subcmd_${aliases[$1]}
153 | shift
154 | "$subcmd" "$@"
155 | else
156 | exec git "$@"
157 | fi
158 |
--------------------------------------------------------------------------------
/fzmp:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -r config_file="${XDG_CONFIG_DIR:-$HOME/.config}/fzmp/conf"
4 |
5 | usage() {
6 | LESS=-FEXR less < go to the next song in the playlist
20 | < go to the previous song in the playlist
21 | Ctrl-d delete the selected songs from the playlist
22 | Ctrl-s save current playlist
23 | Ctrl-p toggle play/pause
24 | -P --playlists
25 | list saved playlists (or F5 when running)
26 | -h --help
27 | print this help
28 |
29 | CONFIGURATION:
30 | A configuration file can be defined at $config_file
31 | If a line begins with '#' it is treated as a comment and ignored
32 | The configuration file reads the following options:
33 |
34 | default_view
35 | Must be 'artists' 'songs' 'playlist' or 'genres'
36 | full_song_format
37 | A format string to be passed directly to \`mpc format -f\` in
38 | 'playlist' and 'all' views. Defaults to:
39 | [[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]
40 | For colorized output try:
41 | [[[\\e\\[32m%artist%\\e\\[0m / ][\\e\\[31m[(%date%) ]%album%\\e\\[0m / ][\\e\\[34m[%track% - ][%title%]\\e\\[0m]]|%file%]
42 | playlist_view_key (default F1)
43 | track_view_key (default F2)
44 | artist_view_key (default F3)
45 | genre_view_key (default F4)
46 | allows customizing which keys fire the different views
47 | findadd_key
48 | adds all songs under the cursor by artist/genre/album
49 | (default ctrl-space)
50 | fzf_options
51 | Command line options to be passed directly to fzf.
52 | Changing this will override the default options:
53 | --height='100%' +s -e -i --reverse --cycle
54 | To use the jump feature of fzf you can try:
55 | --bind=\`:jump --height='100%' +s -e -i --reverse --cycle
56 | It also helps to have a bind for toggle-all:
57 | --bind=ctrl-t:toggle-all --bind=\`:jump --height=100% +s -e -i --reverse --cycle
58 | individual sessions can override with the environment variable FZMP_FZF_OPTIONS
59 | fzmp will also inherit options from FZF_DEFAULT_OPTS
60 | HELP
61 | }
62 |
63 | declare default_filter='filter_by_playlist'
64 | declare track_format='[[[%artist% / ][[(%date%) ]%album% / ][[%track% - ][%title%]]]|%file%]'
65 | declare -r album_listing="mpc find -f '%album%\t%track%\t%title%' artist {} | awk -F'\t' '{ if(album != \$1) { album=\$1; print album } printf \" %2d. %s\n\", \$2, \$3 }'"
66 | declare -a config_err
67 |
68 | declare key_bindings
69 | declare -A bindings
70 | bindings=(
71 | [playlist]='f1'
72 | [track]='f2'
73 | [artist]='f3'
74 | [genre]='f4'
75 | [playlists]='f5'
76 | [findadd]='ctrl-space'
77 | )
78 |
79 | do_binding() {
80 | local b
81 | b=$(action_from_keybind "$1")
82 | shift
83 | case "$b" in
84 | playlist) filter_by_playlist ;;
85 | playlists) pick_playlist ;;
86 | track) filter_by_songs ;;
87 | artist) filter_by_artists ;;
88 | genre) filter_by_genres ;;
89 | *) [[ -n $1 ]] && { "$@"; return 0; } ;;
90 | esac
91 | return 1
92 | }
93 |
94 | action_from_keybind() {
95 | for a in "${!bindings[@]}"; do
96 | if [[ $1 == "${bindings[$a]}" ]]; then
97 | printf '%s' "$a"
98 | return 0
99 | fi
100 | done
101 | return 1
102 | }
103 |
104 | declare -A colors
105 | colors[red]=$(tput setaf 1)
106 | colors[green]=$(tput setaf 2)
107 | colors[blue]=$(tput setaf 4)
108 | colors[reset]=$(tput sgr0)
109 |
110 | info() {
111 | color green "$@" >&2
112 | }
113 |
114 | color() {
115 | local c
116 | c="$1"
117 | shift
118 | printf '%s' "${colors[$c]}"
119 | printf '%s\n' "$@"
120 | printf '%s' "${colors[reset]}"
121 | }
122 |
123 | err() {
124 | color red "$@" >&2
125 | }
126 |
127 | die() {
128 | [[ -n "$1" ]] && err "$*"
129 | exit 1
130 | }
131 |
132 | has() {
133 | local loud=0
134 | if [[ $1 == '-v' ]]; then
135 | loud=1
136 | shift
137 | fi
138 | for c; do c="${c%% *}"
139 | if ! command -v "$c" &> /dev/null; then
140 | (( loud > 0 )) && err "$c not found"
141 | return 1
142 | fi
143 | done
144 | }
145 |
146 | is_running() {
147 | pgrep "$1" &> /dev/null
148 | }
149 |
150 | fzf() {
151 | local opts
152 | opts=( --reverse --cycle --height=100% )
153 | [[ -v FZMP_FZF_OPTIONS ]] && opts=( $FZMP_FZF_OPTIONS )
154 | if has fzf; then
155 | command fzf \
156 | --inline-info \
157 | --ansi \
158 | --no-clear \
159 | "${opts[@]}" "$@"
160 | elif has sk; then
161 | command sk \
162 | --inline-info \
163 | --ansi \
164 | "${opts[@]}" "$@"
165 | else
166 | err 'no filter found'
167 | fi
168 | }
169 |
170 | parse_config_file() {
171 | local line key val nr=0 e
172 | while IFS= read -r line; do
173 | (( ++nr ))
174 | [[ -z "$line" || "$line" = '#'* ]] && continue
175 | read -r key <<< "${line%% *}"
176 | read -r val <<< "${line#* }"
177 | if [[ -z "$val" ]]; then
178 | config_err+=( "missing value for \"$key\" in config file on line $nr" )
179 | continue
180 | fi
181 | case "$key" in
182 | full_song_format) track_format="$val" ;;
183 | fzf_options) FZMP_FZF_OPTIONS="$val" ;;
184 | default_view)
185 | if [[ "$val" =~ ^playlist$|^songs$|^artists$|^genres$|^playlists$ ]]; then
186 | default_filter="filter_by_$val"
187 | else
188 | config_err+=( "unknown format \"$val\" in config file on line $nr" )
189 | config_err+=( "default_view must be 'playlist' 'songs' 'artists' 'genres' or 'playlists'" )
190 | fi ;;
191 | playlist_view_key) bindings[playlist]="$val" ;;
192 | artist_view_key) bindings[artist]="$val" ;;
193 | track_view_key) bindings[track]="$val" ;;
194 | genre_view_key) bindings[genre]="$val" ;;
195 | playlists_view_key) bindings[playlists]="$val" ;;
196 | findadd_key) bindings[findadd]="$val" ;;
197 | *) config_err+=( "unknown key \"$key\" in config file on line $nr" )
198 | esac
199 | done < "$config_file"
200 | if (( ${#config_err[@]} > 0 )); then
201 | err 'there were errors parsing config file:'
202 | for e in "${config_err[@]}"; do
203 | err " $e"
204 | done
205 | fi
206 | }
207 |
208 | filter_by_songs() {
209 | local choice
210 | mapfile -t choice < <(mpc search -f "%file%\t$track_format" filename '' |
211 | fzf --prompt='songs > ' \
212 | --multi \
213 | --with-nth='2..' \
214 | --delimiter='\t' \
215 | --bind='ctrl-space:execute-silent:printf "%s\n" {+} | cut -f1 | mpc add' \
216 | --expect="${key_bindings},enter" |
217 | cut -f1)
218 | case "${choice[0]}" in
219 | 'enter') printf '%s\n' "${choice[@]:1}" | add_songs play ;;
220 | *) do_binding "${choice[0]}" || exit
221 | esac
222 | }
223 |
224 | filter_by_genres() {
225 | local choice
226 | mapfile -t choice < <(mpc search -f '%genre%' genre '' |
227 | awk 'NF' | sort | uniq -c | sort -rn |
228 | fzf --prompt='genres > ' \
229 | --preview='mpc find -f "%artist%" genre {2..} | sort -u' \
230 | --bind="${bindings[findadd]}:execute-silent:mpc findadd genre {2..}" \
231 | --expect="${key_bindings},enter" |
232 | sed -r 's/^\s*[0-9]+\s*//')
233 | (( ${#choice[@]} > 0 )) || die
234 | case "${choice[0]}" in
235 | enter) filter_by_artist_from_genre "${choice[1]}" ;;
236 | *) do_binding "${choice[0]}" || "$default_filter" ;;
237 | esac
238 | }
239 |
240 | filter_by_artist_from_genre() {
241 | local artist genre choice
242 | genre="$1"
243 | mapfile -t choice < <(mpc find -f '%artist%' genre "$genre" |
244 | sort -u | awk 'NF' | sort -u |
245 | fzf --prompt="$genre > " \
246 | --preview="$album_listing" \
247 | --expect="${key_bindings},enter" \
248 | --bind="${bindings[findadd]}:execute-silent:mpc findadd artist {}")
249 | (( ${#choice[@]} > 0 )) || filter_by_genres
250 | case "${choice[0]}" in
251 | enter) filter_by_album_from_artist "${choice[1]}" ;;
252 | *) do_binding "${choice[0]}" || "$filter_by_genres" ;;
253 | esac
254 | }
255 |
256 | filter_by_artists() {
257 | local choice
258 | mapfile -t choice < <(mpc list artist |
259 | fzf --prompt='artists > ' \
260 | --preview="$album_listing" \
261 | --bind="${bindings[findadd]}:execute-silent:mpc findadd artist {}" \
262 | --expect="${key_bindings},enter")
263 | (( ${#choice[@]} > 0 )) || die
264 | case "${choice[0]}" in
265 | 'enter') filter_by_album_from_artist "${choice[1]}" ;;
266 | *) do_binding "${choice[0]}" || "$default_filter" ;;
267 | esac
268 | }
269 |
270 | filter_by_album_from_artist() {
271 | local album artist choice
272 | [[ -z "$1" ]] && filter_by_artists
273 | artist="$1"
274 | printf -v qartist '%q' "$1"
275 | mapfile -t choice < <(mpc find -f '[(%date%)]\t[%album%]' artist "$artist" |
276 | sort -h | uniq |
277 | fzf --prompt="$artist > " \
278 | --preview="mpc find -f '[[[%track% - ][%title%]]|%file%]' artist ${qartist} album {2}" \
279 | --expect="${key_bindings},enter" \
280 | --bind="${bindings[findadd]}:execute-silent:mpc findadd album {2..} artist ${qartist}" \
281 | --delimiter='\t' |
282 | cut -f2)
283 | case "${choice[0]}" in
284 | 'enter') filter_songs_from_album "$artist" "${choice[1]}" ;;
285 | *) do_binding "${choice[0]}" || filter_by_artists ;;
286 | esac
287 | }
288 |
289 | filter_songs_from_album() {
290 | local album artist choice
291 | [[ -z "$1" || -z "$2" ]] && exit 255
292 | artist="$1"
293 | album="$2"
294 | mapfile -t choice < <(mpc find -f '%file%\t[[[%track% - ][%title%]]|%file%]' artist "${artist}" album "${album}" |
295 | fzf --prompt="$artist - $album > " \
296 | --multi \
297 | --with-nth='2..' \
298 | --delimiter='\t' \
299 | --expect="${key_bindings},enter" |
300 | cut -f1)
301 | case "${choice[0]}" in
302 | 'enter') printf '%s\n' "${choice[@]:1}" | add_songs play ;;
303 | *) do_binding "${choice[0]}" || filter_by_album_from_artist "$artist" ;;
304 | esac
305 | }
306 |
307 | filter_by_playlist() {
308 | local choice
309 | current_song=$(mpc current -f "$track_format")
310 | mapfile -t choice < <(mpc playlist -f "%position%\t$track_format" |
311 | fzf --prompt='playlist > ' \
312 | --multi \
313 | ${current_song:+--header="now playing: ${current_song}"} \
314 | --delimiter='\t' \
315 | --with-nth='2..' \
316 | --bind='ctrl-p:execute-silent:mpc toggle' \
317 | --expect="${key_bindings},>,<,ctrl-d,enter,ctrl-s" |
318 | cut -f1) || die
319 | case "${choice[0]}" in
320 | '>') mpc -q next; filter_by_playlist ;;
321 | '<') mpc -q prev; filter_by_playlist ;;
322 | 'enter') [[ -n "${choice[1]}" ]] && mpc -q play "${choice[@]:1}" && filter_by_playlist ;;
323 | 'ctrl-d') [[ -n "${choice[1]}" ]] && mpc -q del "${choice[@]:1}" && filter_by_playlist ;;
324 | 'ctrl-s') save_playlist; filter_by_playlist ;;
325 | *) do_binding "${choice[0]}" || exit ;;
326 | esac
327 | }
328 |
329 | save_playlist() {
330 | local name playlists confirm
331 | tput clear
332 | # if [[ -z $(mpc playlist) ]]; then
333 | # color red 'cannot save empty playlist'
334 | # sleep 0.7
335 | # return 1
336 | # fi
337 | read -r -e -p 'Enter playlist name: ' name
338 | [[ -z $name ]] && return 1
339 | playlists=$(mpc lsplaylists)
340 | if [[ $playlists = *"$name"* ]]; then
341 | diff -s --suppress-common-lines --color=always --label="$name" --label='playlist' <(mpc playlist -f '%file%' "$name") <(mpc playlist -f '%file%')
342 | read -r -n 1 -p 'Are you sure you want to overwrite this playlist? (press y) ' confirm || return
343 | if [[ ${confirm,} = y ]]; then
344 | mpc rm "$name"
345 | else
346 | return
347 | fi
348 | fi
349 | mpc save "$name"
350 | }
351 |
352 | pick_playlist() {
353 | local choice
354 | mapfile -t choice < <(mpc lsplaylists |
355 | fzf --prompt='playlists > ' \
356 | --multi \
357 | --preview='mpc playlist {1}' \
358 | --delimiter='\t' \
359 | --bind='ctrl-space:execute-silent:mpc load {1}' \
360 | --expect="${key_bindings},ctrl-d,enter")
361 | case "${choice[0]}" in
362 | 'enter') mpc playlist -f '%file%' "${choice[1]}" | add_songs play && filter_by_playlist ;;
363 | 'ctrl-d')
364 | tput clear
365 | read -r -n 1 -p 'Are you sure you want to delete this playlist? (press y) ' confirm
366 | if [[ ${confirm} = y ]]; then
367 | mpc rm "${choice[1]}"
368 | pick_playlist
369 | fi ;;
370 | *) do_binding "${choice[0]}" || exit
371 | esac
372 | }
373 |
374 | add_songs() {
375 | local songs index
376 | mapfile -t songs
377 | (( "${#songs[@]}" > 0 )) || die
378 | printf '%s\n' "${songs[@]}" | mpc -q add
379 | [[ $1 == play ]] || return
380 | index=$(mpc playlist | wc -l)
381 | if (( ${#songs[@]} > 1 )); then
382 | index=$(( index - ${#songs[@]} + 1))
383 | fi
384 | mpc -q play "$index"
385 | filter_by_playlist
386 | }
387 |
388 | finish() {
389 | tput rmcup
390 | }
391 | trap finish EXIT SIGINT SIGTERM
392 |
393 | parse_config_file
394 | IFS=',' key_bindings="${bindings[*]}"
395 | key_bindings="${key_bindings/,${bindings[findadd]}}"
396 | findadd_key="${bindings[findadd]}"
397 |
398 | while :; do
399 | case "$1" in
400 | -A|--all) default_filter='filter_by_songs'; shift ;;
401 | -a|--artist) default_filter='filter_by_artists'; shift ;;
402 | -p|--playlist) default_filter='filter_by_playlist'; shift ;;
403 | -P|--playlists) default_filter='pick_playlist'; shift ;;
404 | -g|--genre) default_filter='filter_by_genres'; shift ;;
405 | -h|--help) usage; exit ;;
406 | *) break
407 | esac
408 | done
409 |
410 | has -v fzf mpc || die
411 | is_running mpd || [[ -v MPD_HOST ]] || die "can't connect to mpd"
412 |
413 | tput smcup
414 | "$default_filter"
415 |
--------------------------------------------------------------------------------
/fzmv:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -r esc=$'\033'
4 | declare -r c_reset="${esc}[0m"
5 | declare -r c_red="${esc}[31m"
6 | declare dryrun verbose
7 |
8 | set -e
9 |
10 | err() {
11 | printf "${c_red}%s${c_reset}\n" "$*" >&2
12 | }
13 |
14 | die() {
15 | exit 1
16 | }
17 |
18 | has() {
19 | local verbose=0
20 | if [[ $1 == '-v' ]]; then
21 | verbose=1
22 | shift
23 | fi
24 | for c; do c="${c%% *}"
25 | if ! command -v "$c" &> /dev/null; then
26 | (( verbose > 0 )) && err "$c not found"
27 | return 1
28 | fi
29 | done
30 | }
31 |
32 | has -v fzf || die
33 |
34 | fzf() {
35 | command fzf --cycle "$@"
36 | }
37 |
38 | pick_files() {
39 | local files fzpick
40 | find . -maxdepth 1 2> /dev/null |
41 | sort -h |
42 | sed '1d; s|^\./||' |
43 | while read -r f; do
44 | if [[ -d "$f" ]]; then
45 | printf '%s/\n' "$f"
46 | elif [[ -L "$f" ]]; then
47 | printf '%s@\n' "$f"
48 | else
49 | printf '%s\n' "$f"
50 | fi
51 | done |
52 | fzf --multi --header='move these files' || return 1
53 | }
54 |
55 | pick_destination() {
56 | local cwd browse_dir browse_info query dirs
57 | cwd=$(pwd)
58 | while [[ "$browse_dir" != "$cwd" ]]; do
59 | mapfile -t browse_info < <(
60 | { echo '..'; find . -maxdepth 1 -type d 2> /dev/null; } |
61 | sed 's|^./||' |
62 | sort -h |
63 | fzf --print-query \
64 | --history="${HOME}/.cache/fzmv_history" \
65 | --header="${errors:-move files here}")
66 | query=${browse_info[0]}
67 | browse_dir=${browse_info[1]}
68 | files=( "${browse_info[@]:2}" )
69 | [[ -d "$query" ]] && browse_dir="$query"
70 | [[ ! -d "$browse_dir" ]] && return 1
71 | if [[ "$browse_dir" == '.' && $(realpath "$browse_dir") != "$cwd" ]]; then
72 | realpath "$browse_dir"
73 | break
74 | else
75 | cd "$browse_dir" || die
76 | continue
77 | fi
78 | done
79 | }
80 |
81 | while (( $# > 0 )); do
82 | case $1 in
83 | -t|--test) dryrun=true ;;
84 | -v|--verbose) verbose=1 ;;
85 | esac
86 | shift
87 | done
88 |
89 | mapfile -t files < <(pick_files)
90 | (( ${#files[@]} > 0 )) || exit 1
91 | destination=$(pick_destination) || exit 1
92 | ${dryrun:+echo} mv ${verbose:+-v} -t "$destination" "${files[@]}"
93 |
--------------------------------------------------------------------------------
/fzrepl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | usage() {
4 | less -FEXR <<'HELP'
5 | fzrepl
6 | interactively edit stdin using stream filters like awk, sed, jq
7 |
8 | -c, --cmd command used to filter input
9 | -q, --query default command string to use
10 |
11 | command history can be saved to a file by setting the environment variable
12 | FZREPL_FILE
13 |
14 | examples:
15 | echo 'foo bar' | fzrepl -c 'awk {q}' -q '{print}'
16 | echo 'hello world' | fzrepl -q p 'sed -n {q}'
17 | FZREPL_FILE=jqhistory fzrepl jq package.json
18 | HELP
19 | }
20 |
21 | # TODO: better "wrapping", this is painful:
22 | # fzrepl 'node -e {q}' -q "done = data => data;\nlet A='';process.stdin.on('data',x=>A=A.concat(x.toString())).on('end',()=>{let d = done(A);process.stdout.write(`${String.prototype.trim.call(typeof d==='string'?d:JSON.stringify(d,null,2))}\n`)})"
23 |
24 | declare tmpfile=/tmp/fzreplinput
25 | declare cmd
26 | declare default_query
27 | declare output
28 |
29 | declare -A colors
30 | colors[red]=$(tput setaf 1)
31 | colors[green]=$(tput setaf 2)
32 | colors[reset]=$(tput sgr0)
33 |
34 | cleanup() {
35 | [[ -e "$tmpfile" ]] && rm "$tmpfile"
36 | }
37 | trap cleanup SIGHUP SIGINT SIGTERM
38 |
39 | color() {
40 | local color
41 | color="$1"; shift
42 | printf '%s' "${colors[$color]}" "$*" "${colors[reset]}"
43 | }
44 |
45 | err() {
46 | color red "$@" >&2
47 | return 1
48 | }
49 |
50 | die() {
51 | (( $# > 0 )) && err "$@"
52 | exit 1
53 | }
54 |
55 | for arg; do
56 | case $arg in
57 | -q|--query)
58 | [[ -z $2 || $2 = -* ]] && die "missing argument to $1"
59 | default_query="$2"
60 | shift 2 ;;
61 | -c|--cmd)
62 | [[ -z $2 || $2 = -* ]] && die "missing argument to $1"
63 | cmd="$2"
64 | shift 2 ;;
65 | -h|--help) usage; exit ;;
66 | *) break 2;
67 | esac
68 | done
69 |
70 | if [[ -z $cmd && -n $1 && ! -f $1 ]]; then
71 | cmd="$1"
72 | shift
73 | fi
74 |
75 | if [[ -z $cmd ]]; then
76 | usage
77 | exit 1
78 | fi
79 |
80 | if [[ $cmd != *'{q}'* ]]; then
81 | cmd+=' {q}'
82 | fi
83 |
84 | if [[ -n $1 && -f $1 ]]; then
85 | file=$1
86 | shift
87 | fi
88 |
89 | if [[ -z $file ]]; then
90 | file=/dev/stdin
91 | fi
92 |
93 | mapfile -t REPLY < <(
94 | tee "$tmpfile" < "$file" | fzf \
95 | --sync \
96 | --ansi \
97 | --height=100% \
98 | --disabled \
99 | --print-query \
100 | --query="$default_query" \
101 | ${FZREPL_FILE:+--history=$FZREPL_FILE} \
102 | --preview="$cmd < '$tmpfile'"
103 | )
104 |
105 | q="${REPLY[0]}"
106 | q=${q@Q}
107 | echo "${cmd//'{q}'/$q}"
108 |
--------------------------------------------------------------------------------
/fztop:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 |
4 | while :; do
5 | case "$1" in
6 | -h|--help)
7 | LESS=-FEXR less <&2
47 | }
48 |
49 | die() {
50 | [[ -n "$1" ]] && err "$1"
51 | exit 1
52 | }
53 |
54 | has() {
55 | local verbose
56 | if [[ $1 = '-v' ]]; then
57 | verbose=1
58 | shift
59 | fi
60 | for c; do c="${c%% *}"
61 | if ! command -v "$c" &> /dev/null; then
62 | (( "$verbose" > 0 )) && err "$c not found"
63 | return 1
64 | fi
65 | done
66 | }
67 |
68 | has -v fzf git || die
69 |
70 | while getopts ':hqp:i:F' x; do o="$OPTARG"
71 | case "$x" in
72 | h) usage; exit; ;;
73 | p) processes="$o" ;;
74 | q) (( ++quiet )) ;;
75 | i) IFS=',' read -ra ignore_dir <<< "$o" ;;
76 | F) (( ++force )) ;;
77 | esac
78 | done
79 | shift $(( OPTIND - 1 ))
80 |
81 | while :; do
82 | if [[ -d "$1" ]]; then
83 | dirs+=( "$1" )
84 | fi
85 | shift || break
86 | done
87 |
88 | for o in "${ignore_dir[@]}"; do
89 | ignore_dirs+=( -path "*/$o" -o )
90 | done
91 |
92 | (( ${#dirs[@]} > 0 )) || dirs=("$HOME")
93 |
94 | mapfile -t repos < <(find "${dirs[@]}" \
95 | \( "${ignore_dirs[@]}" \
96 | -fstype 'devfs' \
97 | -o -fstype 'devtmpfs' \
98 | -o -fstype 'proc' \
99 | \) -prune -o -name '.git' -printf '%h\n' 2> /dev/null |
100 | fzf --multi --cycle --inline-info +s -e ${force:+-f /})
101 |
102 | (( ${#repos[@]} > 0 )) || exit
103 |
104 | update() {
105 | local name dir
106 | dir="$1"
107 | name="${dir##*/}"
108 | (( quiet > 1 )) || color blue ":: updating $name"
109 | if git -C "$dir" pull ${quiet:+-q}; then
110 | (( quiet > 1 )) || color green ":: updated $name"
111 | else
112 | errs+=( "$name" )
113 | fi
114 | }
115 |
116 | for d in "${repos[@]}"; do
117 | (( count++ >= processes )) && wait -n
118 | update "$d" &
119 | done
120 | wait
121 |
122 | if (( "${#errs[@]}" > 0 )); then
123 | color red 'The following packages failed to update:'
124 | color red " ${errs[*]}"
125 | fi
126 | color green "updated ${#repos[@]} repos"
127 |
--------------------------------------------------------------------------------
/igr:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | select_from() {
4 | local c
5 | for c; do
6 | if command -v "${c%% *}" &> /dev/null; then
7 | echo "$c"
8 | return 0
9 | fi
10 | done
11 | return 1
12 | }
13 |
14 | preview=$(select_from 'bat --color=always --style=header,numbers -H {2} {1}' \
15 | 'awk "BEGIN{a=\"'"{2}"'\";gsub(\"'"'"'\", \"\", a)} NR==(a+0){print \"\033[1;31m\" \$0 \"\033[0m\"; next} {print}" {1}' \
16 | 'cat {1}')
17 |
18 | command=$(select_from 'rg -n --color=always' 'grep -Rn --color=always')
19 |
20 | fzf -d: \
21 | --ansi \
22 | --query="$1" \
23 | --phony \
24 | --bind="change:reload:$command {q}" \
25 | --bind="start:reload:$command {q}" \
26 | --bind='enter:execute:$EDITOR {1}' \
27 | --preview-window='+{2}-/2' \
28 | --preview="[[ -n {1} ]] && $preview"
29 |
--------------------------------------------------------------------------------
/ix:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -r esc=$'\033'
4 | declare -r c_reset="${esc}[0m"
5 | declare -r c_red="${esc}[31m"
6 | declare OPTIND
7 | declare -a opts=( -\# )
8 | declare id
9 |
10 | usage() {
11 | LESS=-FEXR less <<'HELP'
12 | ix [OPTIONS]
13 |
14 | -l list all pastes, uses fzf for interactive use
15 | -d [id] delete the paste at [id]
16 | -i [id] replaces the paste with stdin
17 | -h print this help
18 | HELP
19 | }
20 |
21 | err() {
22 | printf "${c_red}%s${c_reset}\n" "$@" >&2
23 | }
24 |
25 | die() {
26 | err "$@"
27 | exit 1
28 | }
29 |
30 | has() {
31 | local verbose=0
32 | if [[ $1 == '-v' ]]; then
33 | verbose=1
34 | shift
35 | fi
36 | for c; do c="${c%% *}"
37 | if ! command -v "$c" &> /dev/null; then
38 | (( verbose > 0 )) && err "$c not found"
39 | return 1
40 | fi
41 | done
42 | }
43 |
44 | select_from() {
45 | local cmd='command -v'
46 | for a; do
47 | case "$a" in
48 | -c) cmd="$2"; shift 2 ;;
49 | esac
50 | done
51 | for c; do
52 | if $cmd "${c%% *}" &> /dev/null; then
53 | echo "$c"
54 | return 0
55 | fi
56 | done
57 | return 1
58 | }
59 |
60 | has_account() {
61 | [[ -r ~/.netrc ]] && grep -qF 'ix.io' ~/.netrc
62 | }
63 |
64 | create_account() {
65 | echo "It seems you don't have a ~/.netrc with ix.io in it. Let's make one!"
66 | read -r -p 'enter a username: ' username
67 | read -rs -p 'enter a password (this will be hashed with sha256sum): ' password
68 | echo ''
69 | password=$(sha256sum <<< "$password")
70 | password="${password/% -}"
71 | printf "machine ix.io login %s password %s" "$username" "$password" >> ~/.netrc
72 | chmod 600 ~/.netrc
73 | if has_account; then
74 | echo 'success!'
75 | else
76 | die 'could not create account!'
77 | fi
78 | }
79 |
80 | get_user_name() {
81 | awk '"ix.io" == $2 { print $4 }' ~/.netrc
82 | }
83 |
84 | get_pastes() {
85 | curl -s "http://ix.io/user/$1" |
86 | grep -A1 -P '\' |
87 | awk -F'--' '
88 | BEGIN {FS="\[r\]<\/a>/, "\t", $2); printf "http://ix.io" $2 }
90 | /@/{sub(/^\s+/, "", $0); print}
91 | '
92 | }
93 |
94 | list_pastes() {
95 | local highlighter
96 | highlighter=$(select_from 'bat --color always --style numbers,header,snip' 'highlight -q --force -O ansi' pygmentize cat)
97 | url=$(get_pastes "$(get_user_name)" | fzf \
98 | --inline-info --cycle \
99 | --header='Ctrl-E = edit; Ctrl-V = view; Ctrl-D = delete' \
100 | --preview="curl -s '{1}' | ${highlighter}" \
101 | --bind 'space:jump' \
102 | --bind 'q:abort' \
103 | --bind "Ctrl-V:execute:less -R < <(curl -s '{1}' ${highlighter:+ | $highlighter}) > /dev/tty" \
104 | --bind 'Ctrl-E:execute:p={1}; edit=$(curl -s "$p" | vipe); ix -i "${p##*/}" <<< "$edit"' \
105 | --expect='Ctrl-D')
106 | if [[ -n "$url" ]]; then
107 | mapfile -t res <<< "$url"
108 | if [[ "${res[0]}" = 'Ctrl-D' ]]; then
109 | id="${res[1]}"
110 | id="${id#*ix.io/}"
111 | id="${id%%$'\t'*}"
112 | ix -d "$id"
113 | list_pastes
114 | exit
115 | fi
116 | fi
117 | }
118 |
119 | has -v curl || die
120 |
121 | has_account || create_account
122 |
123 | [[ -e ~/.netrc ]] && opts+=( '-n' )
124 |
125 | while getopts ":hld:i:n:" x; do
126 | case "$x" in
127 | h) usage; exit ;;
128 | d) curl -s "${opts[@]}" -X DELETE "$OPTARG"; exit ;;
129 | l)
130 | if [[ -e ~/.netrc ]]; then
131 | url=$(list_pastes)
132 | [[ -n "$url" ]] && cut -f1 <<< "$url" | tee | xclip
133 | else
134 | die 'no netrc found'
135 | fi
136 | exit ;;
137 | i) opts+=( -X PUT ); id="$OPTARG" ;;
138 | n) opts+=( -F "read:1=$OPTARG" ) ;;
139 | esac
140 | done
141 | shift $(( OPTIND - 1 ))
142 |
143 | if [[ -t 0 ]]; then
144 | if [[ -n "$1" ]]; then
145 | filename="$1"
146 | shift
147 | response=$(curl "${opts[@]}" -F f:1=@"$filename" "$@" "ix.io/$id")
148 | clipboard=$(select_from 'xclip -r ' 'xsel')
149 | if [[ -n "$clipboard" ]]; then
150 | tee /dev/tty <<< "$response" | $clipboard
151 | else
152 | echo "$response"
153 | fi
154 | exit
155 | fi
156 | echo "^C to cancel, ^D to send."
157 | fi
158 |
159 | curl "${opts[@]}" -F f:1='<-' "$@" "ix.io/$id"
160 |
--------------------------------------------------------------------------------
/js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -A aliases
4 | declare -A helptext
5 |
6 | err() { printf '%s\n' "$@" >&2; return 1; }
7 |
8 | die() {
9 | (( $# > 0 )) && err "$@"
10 | exit 1
11 | }
12 |
13 | select_from() {
14 | local cmd='command -v'
15 | for a; do
16 | case "$a" in
17 | -c) cmd="$2"; shift 2 ;;
18 | esac
19 | done
20 | for c; do
21 | if $cmd "${c%% *}" &> /dev/null; then
22 | echo "$c"
23 | return 0
24 | fi
25 | done
26 | return 1
27 | }
28 |
29 | has() {
30 | local v c
31 | if [[ $1 = '-v' ]]; then
32 | v=1
33 | shift
34 | fi
35 | for c; do c="${c%% *}"
36 | if ! command -v "$c" &> /dev/null; then
37 | (( v > 0 )) && err "$c not found"
38 | return 1
39 | fi
40 | done
41 | }
42 | export -f has
43 |
44 | aliases[s]=search
45 | helptext['search']="search and install packages"
46 | subcmd_search() {
47 | local init
48 | if [[ -n $1 ]]; then init=$(npm --json search "$*" | pretty_npm_search); fi
49 | # SHELL is needed to use exported functions if default shell is not bash
50 | SHELL=$(which bash) fzf \
51 | --inline-info \
52 | --query="$*" \
53 | --phony \
54 | --multi \
55 | --preview-window=hidden \
56 | --header='enter to install, C-d saves as devDependency, C-v to pick versions' \
57 | --bind='?:toggle-preview' \
58 | --bind='change:reload:npm --json search {q} | pretty_npm_search' \
59 | --bind='ctrl-v:execute:subcmd_ls-versions {1} <> /dev/tty' \
60 | --bind="enter:execute:subcmd_install {+1} <> /dev/tty" \
61 | --bind="ctrl-d:execute:subcmd_install -D {+1} <> /dev/tty" \
62 | --preview="npm view {1}" \
63 | <<< "$init"
64 | }
65 |
66 | aliases[lsv]='ls-versions'
67 | helptext['ls-versions']='list and install versions'
68 | subcmd_ls-versions() {
69 | local package="$1"
70 | fzf --tac --preview="npm view ${package}@{1}" \
71 | --header="choose version for $package | C-d saves as devDependency" \
72 | --bind="enter:execute:subcmd_install '${package}@{1}' <> /dev/tty" \
73 | --bind="ctrl-d:execute:subcmd_install -D '${package}@{1}' <> /dev/tty" \
74 | < <(npm --json view "$package" | jq -r '.versions[]') # label with .dist-tags?)
75 | }
76 | export -f subcmd_ls-versions
77 |
78 | aliases[un]=uninstall
79 | helptext[uninstall]='uninstall packages'
80 | subcmd_uninstall() {
81 | local rm
82 | mapfile -t rm < <(
83 | jq -r '{dependencies, devDependencies}[] | keys[]' package.json |
84 | fzf -m --query="$*")
85 | (( ${#rm} > 0 )) || return
86 | $(select_from 'yarn remove' 'npm uninstall') "${rm[@]}"
87 | }
88 |
89 | aliases[i]=install
90 | helptext[install]='install packages'
91 | subcmd_install() {
92 | if [[ -e yarn.lock ]] && has yarn; then
93 | yarn add "$@"
94 | else
95 | npm i -S "$@"
96 | fi
97 | }
98 | export -f subcmd_install
99 |
100 | helptext[init]='guided project setup'
101 | subcmd_init() {
102 | # shellcheck disable=2091
103 | $(select_from 'git-flow init -d' 'git init') > /dev/null
104 | npm init -y > /dev/null
105 | [[ -e .gitignore ]] || curl -sL https://raw.githubusercontent.com/toptal/gitignore/master/templates/Node.gitignore > .gitignore
106 | # install typescript? eslint? prettier? husky + lint-staged?
107 | # react? vue? bundlers etc
108 | }
109 |
110 | helptext[lint]='setup or use eslint'
111 | subcmd_lint() { # TODO
112 | # should check if typescript, react, babel is installed, use relevant plugins
113 | if [[ $(jq '.devDependencies.eslint' package.json) = null ]]; then
114 | npx eslint --init
115 | fi
116 | npx eslint --ignore-path=.gitignore "$@"
117 | }
118 |
119 | aliases[fmt]=format
120 | helptext[format]='setup or use prettier'
121 | subcmd_format() { # TODO
122 | if [[ $(jq '.devDependencies.prettier' package.json) = null ]]; then
123 | subcmd_install -D prettier # eslint-{config,plugin}-prettier
124 | fi
125 | npx prettier --ignore-path .gitignore --write "$@"
126 | }
127 |
128 | aliases[-h]=help
129 | helptext[help]='show this help '
130 | subcmd_help() {
131 | LESS=-FEXR less <<-HELP
132 | js [subcmd] [options]
133 |
134 | $(for c in "${subcmds_avail[@]}"; do
135 | printf " %s\n %s\n" "$c" "${helptext[$c]}"
136 | done)
137 | HELP
138 | }
139 |
140 | pretty_npm_search() { jq -r '.[] | "\(.name) \(.version)\t\(.description[0:80])\t\(.author.name // .publisher.username)\t\((.keywords // []) | join(" "))"' | column -t -s $'\t'; }
141 | export -f pretty_npm_search
142 |
143 | has -v fzf jq npm || die
144 |
145 | mapfile -t subcmds_avail < <(compgen -A function | awk '/^subcmd_/ { sub(/^subcmd_/, "", $0); print }')
146 |
147 | if (( $# < 1 )); then
148 | err 'missing command'
149 | subcmd_help
150 | exit 1
151 | elif has "subcmd_$1"; then
152 | subcmd="subcmd_$1"
153 | shift
154 | "$subcmd" "$@"
155 | elif [[ -v aliases[$1] ]]; then
156 | subcmd=subcmd_${aliases[$1]}
157 | shift
158 | "$subcmd" "$@"
159 | else
160 | err 'unknown command'
161 | subcmd_help
162 | exit 1
163 | fi
164 |
--------------------------------------------------------------------------------
/pkgrm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare by_size
4 |
5 | has() {
6 | local verbose=0
7 | if [[ $1 = '-v' ]]; then
8 | verbose=1
9 | shift
10 | fi
11 | for c; do c="${c%% *}"
12 | if ! command -v "$c" &> /dev/null; then
13 | (( "$verbose" > 0 )) && err "$c not found"
14 | return 1
15 | fi
16 | done
17 | }
18 |
19 | err() {
20 | printf "\e[31m%s\e[0m\n" "$*" >&2
21 | }
22 |
23 | die() {
24 | (( $# > 0 )) && err "$*"
25 | exit 1
26 | }
27 |
28 | select_from() {
29 | local o c cmd OPTARG OPTIND
30 | cmd='command -v'
31 | while getopts 'c:' o; do
32 | case "$o" in
33 | c) cmd="$OPTARG" ;;
34 | esac
35 | done
36 | shift "$((OPTIND-1))"
37 | for c; do
38 | if $cmd "${c%% *}" &> /dev/null; then
39 | echo "$c"
40 | return 0
41 | fi
42 | done
43 | return 1
44 | }
45 |
46 | has -v fzf expac || die
47 |
48 | fzf() {
49 | command fzf -e --multi --no-hscroll --inline-info --cycle --bind='Ctrl-a:toggle-all' "$@"
50 | }
51 |
52 | case $1 in
53 | -s|--size) by_size=1; shift;
54 | esac
55 |
56 | if (( $# > 0 )); then
57 | sudo pacman -Rcusn "$@"
58 | exit
59 | fi
60 |
61 | preview=$(select_from pacaur pacman)
62 |
63 | if (( by_size )); then
64 | mapfile -t pkgs < <(expac -H M '%m\t%n' | sort -hr | fzf +s --preview="$preview --color=always -Si {3}" -q '!^lib ' | cut -f2)
65 | else
66 | mapfile -t pkgs < <(expac '%n' | fzf +s --preview="$preview --color=always -Si {1}" -q '!^lib ' | cut -d' ' -f1)
67 | fi
68 |
69 | (( ${#pkgs[@]} > 0 )) && sudo pacman -Rcusn "${pkgs[@]}"
70 |
--------------------------------------------------------------------------------
/pkgsearch:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -r esc=$'\033'
4 | declare -r c_reset="${esc}[0m"
5 | declare -r c_red="${esc}[31m"
6 | declare -r c_green="${esc}[32m"
7 | declare -r c_blue="${esc}[34m"
8 | declare distro
9 | declare preview_pos='right:hidden'
10 |
11 | usage() {
12 | LESS=-FEXR less <&2
23 | }
24 |
25 | die() {
26 | exit 1
27 | }
28 |
29 | has() {
30 | local verbose=0
31 | if [[ $1 = '-v' ]]; then
32 | verbose=1
33 | shift
34 | fi
35 | for c; do c="${c%% *}"
36 | if ! command -v "$c" &> /dev/null; then
37 | (( "$verbose" > 0 )) && err "$c not found"
38 | return 1
39 | fi
40 | done
41 | }
42 |
43 | select_from() {
44 | local cmd='command -v'
45 | for a; do
46 | case "$a" in
47 | -c)
48 | cmd="$2"
49 | shift 2
50 | ;;
51 | esac
52 | done
53 | for c; do
54 | if $cmd "${c%% *}" &> /dev/null; then
55 | echo "$c"
56 | return 0
57 | fi
58 | done
59 | return 1
60 | }
61 |
62 | fzf() {
63 | command fzf -e +s --multi --cycle --ansi \
64 | --bind='Ctrl-X:toggle-preview' \
65 | --no-hscroll --inline-info \
66 | --header='tab to select multiple packages, Ctrl-X for more info on a package' "$@"
67 | }
68 |
69 | install() {
70 | local pkgs count
71 | mapfile -t pkgs
72 | (( ${#pkgs} > 0 )) || exit
73 | count="${#pkgs[@]} package"
74 | (( ${#pkgs[@]} > 1 )) && count+='s'
75 | printf "installing %s: %s\n" "$count" "${pkgs[*]}"
76 | $1 "${pkgs[@]}" < /dev/tty
77 | }
78 |
79 | debian() {
80 | fzf --preview='apt-cache show {1}' \
81 | --query="$1" \
82 | < <(apt-cache search '.*' | sort |
83 | sed -u -r "s|^([^ ]+)|${c_green}\1${c_reset}|") |
84 | cut -d' ' -f1 |
85 | install "sudo $(select_from 'apt' 'aptitude' 'apt-get') install"
86 | }
87 |
88 | arch() {
89 | local search packages
90 | search='pacman'
91 | [[ -n "$1" ]] && search=$(select_from 'yay' 'pacaur' 'trizen' 'yaourt' 'packer' 'apacman' 'pacman')
92 | packages=$(fzf --preview="$search -Si {2}" \
93 | < <( $search -Ss "$1" |
94 | gawk '{
95 | getline descr;
96 | sub(/ */,"", descr);
97 | repo = blue "[" gensub(/\/.*/, "", 1) "]" reset;
98 | name = green gensub(/.*\//, "", 1, $1) reset;
99 | info = gensub(/[^ ]* /, "", 1);
100 | print repo, name, info, descr;
101 | }' blue="$c_blue" green="$c_green" reset="$c_reset"
102 | ) | cut -d' ' -f2)
103 | [[ "$search" = "pacman" ]] && search="sudo pacman"
104 | install "$search -S" <<< "$packages"
105 | }
106 |
107 | void() {
108 | local package_list packagename='{ sub(/-[^\-]*$/, "", $2); print $2 }'
109 | package_list=$(xbps-query -Rs '' | sort)
110 | fzf --preview="p=\$(awk \"$packagename\" <<< {}); xbps-query -Rx \$p" \
111 | --query="$1" <<< "$package_list" |
112 | awk "$packagename" |
113 | install 'xbps-install -S'
114 | }
115 |
116 | fedora() {
117 | fzf --query="$*" --preview='p={}; p="${p%% *}"; dnf -q info "${p%.*}"' \
118 | < <(dnf -qC repoquery --qf "${c_green}%{name} ${c_reset} - %{summary}" \*) |
119 | awk '{ package=$1; sub(/\.\S+/, "", package); print package }' |
120 | install 'sudo dnf install'
121 | }
122 |
123 | while true; do
124 | case "$1" in
125 | -h|--help) usage; exit ;;
126 | -p|--preview) preview_pos="$2"; shift 2 ;;
127 | *) break
128 | esac
129 | done
130 |
131 | has -v fzf gawk || die
132 |
133 | request="$*"
134 |
135 | if [[ -r /etc/os-release ]]; then
136 | distro=$(awk -F'=' '"NAME" == $1 { gsub("\"", "", $2); print tolower($2); }' /etc/os-release)
137 | distro="${distro%% *}"
138 | fi
139 |
140 | case "$distro" in
141 | debian|ubuntu) debian "$request" ;;
142 | arch) arch "$request" ;;
143 | void) void "$request" ;;
144 | fedora) fedora "$request" ;;
145 | *) die 'unknown distro :(' ;;
146 | esac
147 |
148 | # TODO: homebrew: brew desc -s
149 | # sample output: https://pastebin.com/raw/3frRf6C7
150 |
--------------------------------------------------------------------------------
/pkgup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | has() {
4 | local verbose=0
5 | if [[ $1 = '-v' ]]; then
6 | verbose=1
7 | shift
8 | fi
9 | for c; do c="${c%% *}"
10 | if ! command -v "$c" &> /dev/null; then
11 | (( "$verbose" > 0 )) && err "$c not found"
12 | return 1
13 | fi
14 | done
15 | }
16 |
17 | err() {
18 | printf "\e[31m%s\e[0m\n" "$*" >&2
19 | }
20 |
21 | die() {
22 | (( $# > 0 )) && err "$*"
23 | exit 1
24 | }
25 |
26 | select_from() {
27 | local cmd='command -v'
28 | for a; do
29 | case "$a" in
30 | -c)
31 | cmd="$2"
32 | shift 2
33 | ;;
34 | esac
35 | done
36 | for c; do
37 | if $cmd "${c%% *}" &> /dev/null; then
38 | echo "$c"
39 | return 0
40 | fi
41 | done
42 | return 1
43 | }
44 |
45 | has -v fzf || die
46 |
47 | helper=$(select_from pacaur trizen packer apacman pacman)
48 |
49 | mapfile -t pkgs < <(
50 | $helper -Qu --color=always |
51 | fzf --ansi -e -m --inline-info --cycle --reverse --bind='Ctrl-A:toggle-all' |
52 | awk '{print $3}'
53 | )
54 |
55 | count="${#pkgs[@]} package"
56 | (( ${#pkgs[@]} > 1 )) && count+='s'
57 | printf "upgrading %s: %s\n" "$count" "${pkgs[*]}"
58 |
59 | (( ${#pkgs[@]} > 0 )) && $helper -S "${pkgs[@]}"
60 |
--------------------------------------------------------------------------------
/sshget:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | declare -r esc=$'\033'
4 | declare -r c_reset="${esc}[0m"
5 | declare -r c_red="${esc}[31m"
6 |
7 | declare -r fifo='/tmp/sshget.fifo'
8 | declare -A domains=()
9 | declare -A paths=()
10 | declare -a files=()
11 |
12 | err() {
13 | printf "${c_red}%s${c_reset}\n" "$*" >&2
14 | }
15 |
16 | die() {
17 | exit 1
18 | }
19 |
20 | usage() {
21 | LESS=-FEXR less <<'HELP'
22 | sshget
23 | HELP
24 | }
25 |
26 | has() {
27 | local verbose=0
28 | if [[ $1 = '-v' ]]; then
29 | verbose=1
30 | shift
31 | fi
32 | for c; do c="${c%% *}"
33 | if ! command -v "$c" &> /dev/null; then
34 | (( verbose > 0 )) && err "$c not found"
35 | return 1
36 | fi
37 | done
38 | }
39 |
40 | has -v fzf rsync || die
41 |
42 | cleanup() {
43 | [[ -e "$fifo" ]] && rm "$fifo"
44 | }
45 | trap cleanup SIGHUP SIGINT SIGTERM
46 |
47 | mkfifo "$fifo"
48 |
49 | if (( $# < 1 )); then
50 | usage
51 | die
52 | fi
53 |
54 | for a; do
55 | host="${a%:*}"
56 | path="${a##*:}"
57 | domains+=( ["$a"]="$host" )
58 | paths+=( ["$a"]="$path" )
59 | shift
60 | done
61 |
62 | for s in "${!domains[@]}"; do
63 | ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
64 | done
65 |
66 | mapfile -t files < <(fzf -e --inline-info +s --multi --cycle --bind='Ctrl-A:toggle-all,`:jump' < "$fifo")
67 |
68 | if (( ${#files[@]} )); then
69 | rsync --protect-args -auvzP -e ssh "${files[@]}" .
70 | fi
71 |
72 | cleanup
73 |
--------------------------------------------------------------------------------
/wifi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | has() {
4 | local verbose=false
5 | if [[ $1 == '-v' ]]; then
6 | verbose=true
7 | shift
8 | fi
9 | for c in "$@"; do c="${c%% *}"
10 | if ! command -v "$c" &> /dev/null; then
11 | [[ "$verbose" == true ]] && err "$c not found"
12 | return 1
13 | fi
14 | done
15 | }
16 |
17 | err() {
18 | printf '\e[31m%s\e[0m\n' "$*" >&2
19 | }
20 |
21 | die() {
22 | (( $# > 0 )) && err "$*"
23 | exit 1
24 | }
25 |
26 | has -v nmcli fzf || die
27 |
28 | nmcli -f 'bssid,signal,bars,freq,ssid' --color yes device wifi |
29 | fzf \
30 | --with-nth=2.. \
31 | --ansi \
32 | --height=40% \
33 | --reverse \
34 | --cycle \
35 | --inline-info \
36 | --header-lines=1 \
37 | --bind="enter:execute:nmcli -a device wifi connect {1}"
38 |
--------------------------------------------------------------------------------