├── LICENSE ├── Makefile ├── README.org ├── fmz ├── fmz.desktop └── vid ├── 2021-04-03-tiny.gif └── 2021-04-03.mp4 /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX = /usr/local 2 | BIN_PREFIX = $(DESTDIR)$(PREFIX)/bin 3 | APP_PREFIX = $(DESTDIR)$(PREFIX)/share/applications/ 4 | 5 | install: 6 | mkdir -p $(BIN_PREFIX) $(APP_PREFIX) 7 | cp -f fmz $(BIN_PREFIX) 8 | cp -f fmz.desktop $(APP_PREFIX) 9 | update-desktop-database 10 | 11 | uninstall: 12 | rm -f $(BIN_PREFIX)/fmz 13 | rm -f $(APP_PREFIX)/fmz.desktop 14 | 15 | .PHONY: install uninstall 16 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * FMZ 2 | File manager in a fuzzy finder. 3 | 4 | [[./vid/2021-04-03-tiny.gif]] 5 | [[./vid/fmz-2021-04-03_05.16.10.mp4]] 6 | 7 | ** Dependencies 8 | core utils and [[https://github.com/junegunn/fzf][fzf]]. 9 | 10 | ** Features 11 | - Pure POSIX 12 | - Does not re-implement what's already in core utils 13 | - Easy configuration 14 | - Sane defaults 15 | - Fuzzy 16 | - Scriptable 17 | - Device management 18 | - Shell integration with cd on exit 19 | - Auto archive extraction 20 | - XDG trash 21 | - Check below for optional features 22 | 23 | ** Optional dependencies/features 24 | Having one of those is not a must, they only unlock new superpowers. 25 | 26 | | Dependency | Superpower | 27 | |--------------------+----------------------------------| 28 | | [[https://github.com/Naheel-Azawy/stpv][stpv]] | better previews with images | 29 | | [[https://github.com/Naheel-Azawy/cp-p][cp-p]] | show progress of cp and mv | 30 | | [[https://github.com/cybernoid/archivemount][archivemount]] ([[https://aur.archlinux.org/packages/archivemount/][AUR]]) | browse archives seamlessly | 31 | | xclip | copy file names to X clipboard | 32 | | [[https://github.com/mwh/dragon][dragon]] | drag and drop | 33 | | [[https://github.com/sharkdp/fd][fd]] | better find | 34 | | perl-file-mimeinfo | XDG open with | 35 | | udisks2 | mount and unmount devices | 36 | | [[https://github.com/phatina/simple-mtpfs/][simple-mtpfs]] ([[https://aur.archlinux.org/packages/simple-mtpfs/][AUR]]) | mount and unmount MTP devices | 37 | | gio | mount and unmount gvfs devices | 38 | | dunst | actions with mount notifications | 39 | | vidir (moreutils) | bulk rename in a directory | 40 | 41 | ** Installation 42 | #+begin_src shell-script 43 | make install 44 | #+end_src 45 | 46 | ** Shell integration 47 | - sh 48 | #+begin_src shell-script 49 | fmz() { 50 | tmp=$(mktemp) 51 | command fmz --cd "$tmp" "$@" 52 | res=$(tail -n 1 "$tmp") 53 | if [ -d "$res" ] && [ "$res" != "$PWD" ]; then 54 | echo cd "$res" 55 | cd "$res" || return 1 56 | fi 57 | rm "$tmp" 58 | } 59 | #+end_src 60 | 61 | - fish 62 | #+begin_src shell-script 63 | function fmz 64 | set tmp (mktemp) 65 | command fmz --cd $tmp $argv 66 | set res (tail -n 1 $tmp) 67 | if test -d "$res" && test "$res" != "$PWD" 68 | echo cd $res 69 | cd $res || return 1 70 | end 71 | rm $tmp 72 | end 73 | #+end_src 74 | 75 | ** Default bindings 76 | In general, [[https://en.wikipedia.org/wiki/IBM_Common_User_Access][CUA]]-like bindings where used, M-x for menu, and F1 to show all bindings. 77 | 78 | ** Configuration 79 | Config file is just a shell script that gets sourced in fmz. So be sure not to have the setuid bit set on fmz. 80 | Key symbols are as defined by fzf (check ~man fzf~). 81 | You can bind fzf actions, functions (using ~fun~), or quick functions that does not need ~f~ and ~fx~ (using ~funq~). 82 | Example config file (~/.config/fmzrc.sh): 83 | 84 | #+begin_src shell-script 85 | # basic bindings 86 | bind alt-w fun copy 87 | bind ctrl-w fun move 88 | bind ctrl-y funq paste 89 | bind ctrl-c abort 90 | 91 | # add a function to menu and bind it 92 | add_fun myless 'Less a file' 93 | bind ctrl-p fun myless 94 | myless() { 95 | tput rmcup 96 | less "$f" 97 | } 98 | 99 | # bookmarks 100 | bookmark ~/Documents 101 | bookmark ~/Pictures 102 | bookmark ~/Videos 103 | 104 | # other variables 105 | OPENER=xdg-open 106 | TERMINAL=st 107 | #+end_src 108 | 109 | ** Mount monitor 110 | #+begin_src shell-script 111 | fmz --mount-monitor 112 | #+end_src 113 | 114 | If ~dunstify~ exists, the notification action will mount the drive and open fmz in a terminal window. 115 | ~notify-send~ can be used instead but clicking won't do anything. 116 | The default bind for unmounting the current directory is ctrl-u. 117 | 118 | ** Why? 119 | I tried many other file managers like [[https://en.wikipedia.org/wiki/Midnight_Commander][mc]], [[https://github.com/ranger/ranger][ranger]], [[https://github.com/gokcehan/lf][lf]], [[https://github.com/jarun/nnn][nnn]], [[https://github.com/dylanaraps/fff][fff]], and several others that I forgot. 120 | From the GUI world, it worth mentioning nautilus, nemo, thunar, and pantheon's files. 121 | They all are cool in some way, but still not as good as I wanted. 122 | If you're here, probably there's no need to talk about GUI. 123 | Out of all the terminal file managers, lf has been my choice for a pretty long time and I do believe that it is the best out of the ones I just mentioned. 124 | However, with time, I started realizing lf problems. Here are some of what I recall: 125 | - A bit of unnecessary bloat. 126 | lf is relatively so minimal. But, in my opinion, there are some unnecessary parts like the builtin copy implementation and the config parser. 127 | - Too much configuration 128 | lf is almost unusable out of the box. Minimalism is good of course, but having some sane defaults can be done without being bloated too. 129 | - I use fzf anyway... 130 | Even inside lf, I used to have a key binding to fzf to find and jump to wherever I want. In practice, I found myself opening fzf almost every time I use lf. 131 | I'm not trying to say lf is bad. It is amazing. It just wasn't enough for me. 132 | 133 | ** License 134 | GPL3 135 | -------------------------------------------------------------------------------- /fmz: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (C) 2021-present naheel-azawy 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # ==== constants ==== 19 | 20 | NAME='fmz' 21 | MENU='fzf' 22 | FZF_MIN_VERSION=38000 23 | fzf_version= 24 | 25 | # tmp directory 26 | if [ -n "$TMPDIR" ]; then 27 | SYSTMP_DIR="$TMPDIR" 28 | else 29 | SYSTMP_DIR=/tmp 30 | fi 31 | if ! [ -d "$SYSTMP_DIR" ] || ! [ -w "$SYSTMP_DIR" ]; then 32 | SYSTMP_DIR=~/.cache/fmz 33 | mkdir -p "$SYSTMP_DIR" 34 | fi 35 | export TMPDIR="$SYSTMP_DIR" 36 | 37 | # consts 38 | SELF=$(realpath "$0") 39 | ID=$$ 40 | CFG_DIR=${XDG_CONFIG_HOME:-"$HOME/.config"} 41 | CFG_FILE="$CFG_DIR/${NAME}rc.sh" 42 | TRASH_MAIN=${XDG_DATA_HOME:-"$HOME/.local/share"}/Trash 43 | OP_FILE="$SYSTMP_DIR/$NAME-op" 44 | HIDDEN_FILE="$SYSTMP_DIR/$NAME-hidden" 45 | SORT_FILE="$SYSTMP_DIR/$NAME-sort" 46 | RECENT_FILE="$SYSTMP_DIR/$NAME-recent" 47 | TMP_DIR="$SYSTMP_DIR/$NAME-tmp-$ID" 48 | TMP_FILE="$TMP_DIR/tmp" 49 | LAST_FILE="$TMP_DIR/last-" 50 | PENDING_FILE="$TMP_DIR/pnd" 51 | EMPTY='/EMPTY/' 52 | ESC=$(printf '\033') 53 | 54 | # for fzf preview 55 | PV_SHELL=bash 56 | 57 | # not really sure if this is a good place 58 | # suggestions are welcomed 59 | MOUNTS_DIR="$HOME/.local/media" 60 | 61 | MOUNTED='▮MNT' 62 | UNMOUNTED='▯MNT' 63 | RECENT='←REC' 64 | 65 | # ==== global parameters ==== 66 | 67 | CD= 68 | W= ; H= 69 | PV_W= ; PV_H= ; PV_X= ; PV_Y= ; 70 | PV_WIN= ; USE_STPV= 71 | selection= 72 | 73 | # ==== config ==== 74 | 75 | quick_goto= 76 | show_up=1 77 | bindings="" 78 | bindings_help="" 79 | bookmarks="$HOME" 80 | funs="" 81 | 82 | # ==== config helpers ==== 83 | 84 | add_fun() { 85 | funs="$funs$1 $2 86 | " 87 | } 88 | 89 | is_invalid_file() { 90 | [ -z "$1" ] || # empty 91 | ! { [ -e "$1" ] || [ -L "$1" ]; } || # file does not exists and not dead link 92 | [ "$1" = '..' ] || [ "$1" = "$EMPTY" ] # reserved 93 | } 94 | 95 | run_fun() { 96 | case "$MENU" in 97 | fzf) 98 | fx=$(while read -r f; do 99 | is_invalid_file "$f" && continue 100 | realpath -s -- "$f" 101 | done < "$2") 102 | f=$(echo "$fx" | head -n1) ;; 103 | esac 104 | id=$ID 105 | FMZ_SHELL=$ID 106 | export FMZ_SHELL id fx f 107 | eval "$1" 108 | } 109 | 110 | force_res_bind() { 111 | # in the latest versions of fzf, when echoing in execute(), 112 | # it will echo to the stdout and will not be caught by $() 113 | if [ "$fzf_version" -ge 59000 ]; then 114 | # I don't see the reason of this breaking change in the 115 | # changelog of fzf, but it is what it is... 116 | echo "execute(echo $1 > '$PENDING_FILE')+abort" 117 | else 118 | echo "abort+execute(echo $1 > '$PENDING_FILE')" 119 | fi 120 | } 121 | 122 | check_forced_res() { 123 | # must always be called after res=$(menu ...) 124 | # if $PENDING_FILE is used 125 | res="$1" 126 | pending_res=$(cat "$PENDING_FILE") 127 | if [ -n "$pending_res" ]; then 128 | echo "$pending_res" 129 | echo > "$PENDING_FILE" 130 | else 131 | echo "$res" 132 | fi 133 | } 134 | 135 | bind() { 136 | key="$1" 137 | cmd="$2" 138 | 139 | case "$cmd" in 140 | fun|funq) 141 | fun="$3" 142 | doc= 143 | case "$MENU" in 144 | fzf) 145 | cmd="execute(cp {+f} $TMP_FILE)" 146 | cmd="$cmd+"$(force_res_bind "'\$ run_fun $fun $TMP_FILE'") ;; 147 | esac ;; 148 | *) 149 | fun='nop' 150 | doc="$3" ;; 151 | esac 152 | 153 | case "$MENU" in 154 | fzf) 155 | [ -n "$bindings" ] && bindings="$bindings," 156 | bindings="$bindings$key:$cmd" ;; 157 | esac 158 | bindings_help="$bindings_help$key $fun $doc 159 | " 160 | } 161 | 162 | bookmark() { 163 | [ -d "$1" ] && { 164 | bookmarks="$bookmarks:$1" 165 | } 166 | } 167 | 168 | show_help() { 169 | { 170 | echo 'Keyboard bindings' 171 | echo '=================' 172 | echo "$bindings_help" | while read -r key fun doc; do 173 | [ "$key" ] || continue 174 | [ "$fun" != 'nop' ] && 175 | doc=$(echo "$funs" | grep "^$fun " | cut -d ' ' -f2-) 176 | printf '%-20s: %s\n' "$key" "$doc" 177 | done 178 | echo 179 | 180 | echo 'Functions' 181 | echo '=========' 182 | echo "$funs" | while read -r fun doc; do 183 | [ "$fun" ] || continue 184 | printf '%-20s: %s\n' "$fun" "$doc" 185 | done 186 | } | less --clear-screen 187 | } 188 | 189 | # ==== utils ==== 190 | 191 | info() { 192 | printf '\033[1;34mINFO:\033[0m ' 193 | echo "$@" 194 | } 195 | 196 | ask() { 197 | printf '\033[1m\033[33mQUESTION:\033[0m %s ' "$1" 198 | } 199 | 200 | err() { 201 | { 202 | printf '\033[1m\033[31mERROR:\033[0m ' 203 | echo "$@" 204 | } >&2 205 | } 206 | 207 | run_show() { 208 | printf '\033[1;32m>>>\033[0m %s\n' "$*" >&2 209 | } 210 | 211 | run() { 212 | run_show "$@" 213 | "$@" 214 | } 215 | 216 | exists() { 217 | command -v "$1" >/dev/null 218 | } 219 | 220 | remove_ansi() { 221 | sed 's/\x1b\[[0-9;]*m//g' 222 | } 223 | 224 | remove_ansi_reset() { 225 | start_bytes=$(echo "$1" | head -n1 | head -c 4) 226 | if [ "$start_bytes" = "${ESC}[0m" ]; then 227 | echo "$1" | head -n1 | tail -c +5 228 | else 229 | echo "$1" 230 | fi 231 | } 232 | 233 | relativify() { 234 | here=$(realpath .) 235 | sed "s:^$here:.:" 236 | } 237 | 238 | version_to_int() { 239 | v=$(cut -d' ' -f1) 240 | v1=$(echo "$v" | cut -d. -f1) 241 | v2=$(echo "$v" | cut -d. -f2) 242 | v3=$(echo "$v" | cut -d. -f3) 243 | echo $((v3 + v2 * 1000 + v1 * 1000000)) 244 | } 245 | 246 | human() { 247 | # https://unix.stackexchange.com/questions/44040/a-standard-tool-to-convert-a-byte-count-into-human-kib-mib-etc-like-du-ls1 248 | echo "$1" | awk 'function human(x) { 249 | s="KiB MiB GiB TiB EiB PiB YiB ZiB" 250 | while (x >= 1024 && length(s) > 1) { 251 | x /= 1024 252 | s = substr(s, 5) 253 | } 254 | s = substr(s, 1, 4) 255 | xf = (s == " B ") ? "%d" : "%.2f" 256 | return sprintf(xf"%s", x, s) 257 | } {print human($1)}' 258 | } 259 | 260 | wait_user() { 261 | echo 'Press enter to continue...' 262 | read -r _ 263 | } 264 | 265 | # ==== trash ==== 266 | 267 | trashes_list() { 268 | if [ -d "$TRASH_MAIN" ]; then echo "$TRASH_MAIN"; fi 269 | uid=$(id -u) 270 | findmnt -nlo target | while read -r d; do 271 | for t in "$d/.Trash-$uid" "$d/.Trash"; do 272 | if [ -d "$t" ]; then echo "$t"; fi 273 | done 274 | done 275 | } 276 | 277 | trash_check() { 278 | [ -d "$1" ] && [ -d "$1/info" ] && [ -d "$1/files" ] && 279 | return 0 280 | mkdir -p -- "$1/info" "$1/files" 281 | chmod 700 "$1" 282 | } 283 | 284 | trash_find_for() { 285 | trash_check "$TRASH_MAIN" 286 | main_target=$(findmnt -no target -T "$TRASH_MAIN") 287 | target=$(findmnt -no target -T "$1") 288 | [ -n "$target" ] || # because the above fails on dead links 289 | target=$(findmnt -no target -T "$(dirname "$1")") 290 | 291 | if [ "$main_target" = "$target" ]; then 292 | trash_check "$TRASH_MAIN" 293 | echo "$TRASH_MAIN" 294 | return 295 | fi 296 | 297 | uid=$(id -u) 298 | t="$target/.Trash-$uid" 299 | trash_check "$t" 300 | echo "$t" 301 | } 302 | 303 | trash_list() { 304 | trashes_list | while read -r trash; do 305 | find "$trash/info" -type f -name '*.trashinfo' | while read -r info; do 306 | # FIXME: this is too slow, use awk or something after the loops 307 | n=$(basename "$info" | sed -r 's/\.trashinfo$//') 308 | d=$(sed -rn 's/DeletionDate=(.+)/\1/p' "$info") 309 | echo "$d $n @ $trash" 310 | done 311 | done | sort --reverse | column -s '@' -o '@:' -t 312 | } 313 | 314 | trash_line_to_trash() { 315 | echo "$1" | sed -rn 's/.+@: (.+)/\1/p' 316 | } 317 | 318 | trash_line_to_name() { 319 | echo "$1" | sed -rn 's/.+:[0-9]{2} (.+) +@: (.+)/\1/; s/[[:space:]]*$//p' 320 | } 321 | 322 | trash_restore() { 323 | n=$(trash_line_to_name "$1") 324 | trash=$(trash_line_to_trash "$1") 325 | info="$trash/info/${n}.trashinfo" 326 | file="$trash/files/${n}" 327 | [ -n "$n" ] || [ -n "$trash" ] || { 328 | err "Invalid trash file '$1'" 329 | return 1 330 | } 331 | [ -e "$file" ] || { 332 | err "Trash file not found '$file'" 333 | return 1 334 | } 335 | p=$(sed -rn 's/Path=(.+)/\1/p' -- "$info") 336 | 337 | # check if exists 338 | n=$(basename "$p") 339 | d=$(dirname "$p") 340 | num=2 341 | while [ -e "$p" ]; do 342 | n_new=$(echo "$n" | sed -rn "s/(.+)\.(.+)/\1.$num.\2/p") 343 | [ -n "$n_new" ] || n_new="$n.$num" 344 | p="$d/$n_new" 345 | num=$((num + 1)) 346 | done 347 | [ -n "$n_new" ] && n="$n_new" 348 | 349 | run mv -- "$file" "$p" && 350 | run rm -- "$info" 351 | } 352 | 353 | trash_delete() { 354 | n=$(trash_line_to_name "$1") 355 | trash=$(trash_line_to_trash "$1") 356 | info="$trash/info/${n}.trashinfo" 357 | file="$trash/files/${n}" 358 | [ -n "$n" ] || [ -n "$trash" ] || { 359 | err "Invalid trash file '$1'" 360 | return 1 361 | } 362 | [ -e "$file" ] || { 363 | err "Trash file not found '$file'" 364 | return 1 365 | } 366 | p=$(sed -rn 's/Path=(.+)/\1/p' "$info") 367 | 368 | run rm -rf -- "$file" && 369 | run rm -- "$info" 370 | } 371 | 372 | trash_move() { 373 | [ -e "$1" ] || [ -L "$1" ] || { 374 | err "No such file of directory '$1'" 375 | return 1 376 | } 377 | p=$(realpath -s -- "$1") 378 | d=$(date '+%Y-%m-%dT%H:%M:%S') 379 | trash=$(trash_find_for "$p") 380 | n=$(basename "$p") 381 | file="$trash/files/${n}" 382 | 383 | # check if exists 384 | num=2 385 | while [ -e "$file" ] || [ -L "$file" ]; do 386 | n_new=$(echo "$n" | sed -rn "s/(.+)\.(.+)/\1.$num.\2/p") 387 | [ -n "$n_new" ] || n_new="$n.$num" 388 | file="$trash/files/$n_new" 389 | num=$((num + 1)) 390 | done 391 | [ -n "$n_new" ] && n="$n_new" 392 | info="$trash/info/${n}.trashinfo" 393 | 394 | run mv -- "$p" "$file" && { 395 | echo '[Trash Info]' 396 | echo "Path=$p" 397 | echo "DeletionDate=$d" 398 | } > "$info" 399 | } 400 | 401 | trash_du() { 402 | trashes=$(trashes_list) 403 | [ -n "$trashes" ] || { 404 | echo 'Trash is empty' 405 | return 406 | } 407 | echo 'Calculating trash disk usage...' 408 | res=$(echo "$trashes" | xargs du -s 2>/dev/null) 409 | echo "$res" | while read -r s d; do 410 | printf '%15s\t %s\n' "$(human "$s")" "$d" 411 | done 412 | sum=$(echo "$res" | cut -f1 | 413 | awk 'BEGIN {ans=0} {ans+=$1} END {print ans}') 414 | printf 'Total trash disk usage: ' 415 | human "$sum" 416 | } 417 | 418 | trash_empty() { 419 | trashes=$(trashes_list) 420 | [ -n "$trashes" ] || { 421 | echo 'Trash is empty' 422 | return 423 | } 424 | echo "$trashes" | xargs rm -rf -- 425 | } 426 | 427 | trash_preview() { 428 | case "$1" in 429 | "$EMPTY") 430 | return ;; 431 | 'Trash disk usage'|'Empty trash') 432 | echo 'Trash direcrories:' 433 | trashes_list 434 | return ;; 435 | esac 436 | n=$(trash_line_to_name "$1") 437 | trash=$(trash_line_to_trash "$1") 438 | info="$trash/info/${n}.trashinfo" 439 | file="$trash/files/${n}" 440 | stat -- "$file" 441 | echo 442 | cat -- "$info" 443 | } 444 | 445 | trash_menu() { 446 | if [ "$USE_STPV" ]; then 447 | stpvimg --clear "$id" 448 | fi 449 | 450 | [ "$TMUX" ] && { 451 | tmux set automatic-rename off 452 | tmux rename-window "Trash" 453 | } 454 | 455 | res=$({ 456 | echo 'Trash disk usage' 457 | echo 'Empty trash' 458 | l=$(trash_list) 459 | if [ -n "$l" ]; then 460 | echo "$l" 461 | else 462 | echo "$EMPTY" 463 | fi 464 | } | menu_trash) 465 | 466 | [ -n "$res" ] || return 1 467 | 468 | case "$res" in 469 | 'Trash disk usage') 470 | reset_terminal 471 | trash_du 472 | wait_user 473 | trash_menu ;; 474 | 475 | 'Empty trash') 476 | ans=$({ 477 | echo 'Cancel' 478 | echo 'Yes' 479 | } | menu_interface --prompt "Empty trash? ") 480 | [ "$ans" = Yes ] && { 481 | reset_terminal 482 | trash_empty 483 | wait_user 484 | } 485 | trash_menu ;; 486 | 487 | "$EMPTY") 488 | trash_menu ;; 489 | 490 | *) 491 | n=$(trash_line_to_name "$res") 492 | trash=$(trash_line_to_trash "$res") 493 | file="$trash/files/${n}" 494 | ans=$({ 495 | echo 'Restore' 496 | echo 'Delete permanently' 497 | } | menu_interface \ 498 | --prompt "> " \ 499 | --header "$res" \ 500 | --preview-window "$PV_WIN" \ 501 | --preview "$(pv_cmd "$file")") 502 | case "$ans" in 503 | 'Restore') 504 | reset_terminal 505 | trash_restore "$res" 506 | wait_user ;; 507 | 'Delete permanently') 508 | ans=$({ 509 | echo 'Cancel' 510 | echo 'Yes' 511 | } | menu_interface \ 512 | --header "$res" \ 513 | --prompt "Delete permanently? ") 514 | [ "$ans" = Yes ] && { 515 | reset_terminal 516 | trash_delete "$res" 517 | wait_user 518 | } ;; 519 | esac 520 | trash_menu 521 | esac 522 | 523 | [ "$TMUX" ] && tmux set automatic-rename on 524 | } 525 | 526 | # ==== archive utils ==== 527 | 528 | isarchive() { 529 | case "$1" in 530 | *.tar|*.tar.bz|*.tar.bz2|*.tbz|*.tbz2|*.tar.gz|*.tgz|*.tar.xz|*.txz|*.zip|*.apk|*.jar|*.rar|*.iso|*.7z) 531 | return 0;; 532 | *) return 1;; 533 | esac 534 | } 535 | 536 | archive_getmnt() { 537 | md5=$(echo "$1" | md5sum - | cut -d ' ' -f 1) 538 | echo "$SYSTMP_DIR/archivemount-wrapper/$md5" 539 | } 540 | 541 | archive_getln() { 542 | echo "$1-archive" 543 | } 544 | 545 | # 0: mounted 546 | # 1: not mounted 547 | # 2: error, cleanup required 548 | archive_ismounted() { 549 | q= && [ "$1" = '-q' ] && q=1 && shift 550 | p=$(realpath "$1") 551 | mntpath=$(archive_getmnt "$p") 552 | linkpath=$(archive_getln "$p") 553 | if [ -e "$mntpath" ]; then 554 | if [ -d "$mntpath" ]; then 555 | if mountpoint -q "$mntpath"; then 556 | if [ -L "$linkpath" ]; then 557 | return 0 558 | else 559 | return 2 # all good but not linked 560 | fi 561 | elif [ ! "$(ls -A "$mntpath")" ]; then 562 | [ "$q" ] || echo "Error: '$mntpath' is not empty" 563 | return 2 564 | fi 565 | else 566 | [ "$q" ] || echo "Error: '$mntpath' is not a directory" 567 | return 2 568 | fi 569 | else 570 | if [ -L "$linkpath" ]; then 571 | [ "$q" ] || echo "Error: '$p' is not mounted with dead link" 572 | return 2 573 | else 574 | [ "$q" ] || echo "'$p' is not mounted" 575 | return 1 576 | fi 577 | fi 578 | } 579 | 580 | archive_umount() { 581 | q= && [ "$1" = '-q' ] && q=1 && shift 582 | p=$(realpath "$1") 583 | if [ "$q" ]; then 584 | archive_ismounted -q "$p" 585 | else 586 | archive_ismounted "$p" 587 | fi 588 | case $? in 589 | 0|2) # mounted or needs cleanup 590 | mntpath=$(archive_getmnt "$p") 591 | linkpath=$(archive_getln "$p") 592 | mountpoint -q "$mntpath" && 593 | fusermount -u "$mntpath" 594 | [ -d "$mntpath" ] && 595 | rmdir "$mntpath" 596 | [ -L "$linkpath" ] && 597 | rm "$linkpath" 598 | rm -f "${mntpath}-origin" 599 | ;; 600 | *) return $?;; 601 | esac 602 | } 603 | 604 | archive_mount() { 605 | p=$(realpath "$1") 606 | d=$(dirname "$p") 607 | mntpath=$(archive_getmnt "$p") 608 | linkpath=$(archive_getln "$p") 609 | s='' && [ ! -w "$d" ] && s='sudo' 610 | 611 | isarchive "$p" || { 612 | echo "'$p' is not archive" 613 | return 1 614 | } 615 | 616 | archive_umount -q "$p" 617 | 618 | mkdir -p "$mntpath" && 619 | archivemount "$p" "$mntpath" && 620 | $s ln -s "$mntpath" "$linkpath" && 621 | echo "$p" > "${mntpath}-origin" 622 | 623 | echo "$linkpath" 624 | } 625 | 626 | archive_umountall() { 627 | for d in "$SYSTMP_DIR"/archivemount-wrapper/*-origin; do 628 | p=$(cat "$d") 629 | if [ "$p" ]; then 630 | echo "unmounting '$p'..." 631 | archive_umount "$p" 632 | fi 633 | done 634 | } 635 | 636 | archive_extract() { 637 | echo "$fx" | while read -r file; do 638 | s='' && [ ! -w . ] && s='sudo' 639 | 640 | case "$file" in 641 | *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) x_cmd='tar xjvf' ;; 642 | *.tar.gz|*.tgz) x_cmd='tar xzvf' ;; 643 | *.tar.xz|*.txz) x_cmd='tar xJvf' ;; 644 | *.tar.zst) x_cmd='tar -I unzstd -xvf' ;; 645 | *.tar) x_cmd='tar xf' ;; 646 | *.zip|*.jar|*.apk|*.ftf) x_cmd='unzip' ;; 647 | *.7z|*.rar|*.iso) x_cmd='7z x' ;; 648 | *) x_cmd= ;; 649 | esac 650 | 651 | if [ -z "$x_cmd" ]; then 652 | echo "Error: unknown archive format" 653 | return 1 654 | fi 655 | 656 | out="$file-extracted" 657 | here= 658 | if [ ! "$here" ]; then 659 | $s mkdir -p "$out" && cd -- "$out" || return 1 660 | fi 661 | # shellcheck disable=SC2086 662 | $s $x_cmd "$file" 663 | done 664 | lastz=$(echo "$fx" | tail -n 1) 665 | selection_set_selected "$lastz-extracted" 666 | } 667 | 668 | mktar() { 669 | s='' && [ ! -w . ] && s='sudo' 670 | n="$1" 671 | shift 672 | run $s tar czf "$n".tar.gz "$@" 673 | } 674 | 675 | mkzip() { 676 | s='' && [ ! -w . ] && s='sudo' 677 | n="$1" 678 | shift 679 | run $s zip -r "$n".zip "$@" 680 | } 681 | 682 | mk7z() { 683 | s='' && [ ! -w . ] && s='sudo' 684 | n="$1" 685 | shift 686 | run $s 7z a "$n".7z "$@" 687 | } 688 | 689 | # ==== devices utils ==== 690 | 691 | is_mounted() { 692 | check=$(echo "$@" | cut -d ' ' -f1) 693 | [ "$check" = "$MOUNTED" ] 694 | } 695 | 696 | # blocks 697 | 698 | blocks_ls() { 699 | blocks=$(lsblk -rpo 'name,type,mountpoint' | tac | 700 | sed 's/\\x20/ /g') 701 | echo "$blocks" | while read -r name type mp; do 702 | case "$type" in 703 | part|lvm) 704 | if [ -e "$mp" ]; then 705 | fsavail=$(lsblk -no fsavail "$name" | xargs) 706 | fssize=$(lsblk -no fssize "$name" | xargs) 707 | echo "$MOUNTED#$name#$mp#($fsavail/$fssize)" 708 | elif [ ! "$mp" ]; then 709 | label=$(lsblk -no label "$name") 710 | size=$(lsblk -no size "$name" | xargs) 711 | echo "$UNMOUNTED#$name#$label($size)" 712 | fi 713 | esac 714 | done 715 | } 716 | 717 | blocks_mount() { 718 | is_mounted "$@" && return 1 719 | dev=$(echo "$@" | awk '{print $2}') 720 | run udisksctl mount -b "$dev" 2>&1 721 | } 722 | 723 | blocks_unmount() { 724 | is_mounted "$@" || return 1 725 | dev=$(echo "$@" | awk '{print $2}') 726 | run udisksctl unmount -b "$dev" 2>&1 727 | } 728 | 729 | blocks_mountpoint() { 730 | dev=$(echo "$@" | awk '{print $2}') 731 | mp=$(lsblk -no mountpoint "$dev") 732 | [ -e "$mp" ] && echo "$mp" 733 | } 734 | 735 | # mtp 736 | 737 | mtp_ls() { 738 | exists simple-mtpfs || return 0 739 | mounted=$(command ls -1 "$MOUNTS_DIR") 740 | [ "$mounted" ] && echo "$mounted" | while read -r d; do 741 | num=$(echo "$d" | cut -d : -f1) 742 | if mountpoint -q "$MOUNTS_DIR/$d"; then 743 | echo "$MOUNTED#MTP/$num#$MOUNTS_DIR/$d" 744 | else 745 | rmdir "$MOUNTS_DIR/$d" 746 | fi 747 | done 748 | mounted=$(command ls -1 "$MOUNTS_DIR") 749 | if [ "$mounted" ]; then 750 | simple-mtpfs -l | grep -v "$mounted" 751 | else 752 | simple-mtpfs -l 753 | fi 2>/dev/null | while read -r d; do 754 | num=$(echo "$d" | cut -d : -f1) 755 | echo "$UNMOUNTED#MTP/$num#$d" 756 | done 757 | } 758 | 759 | mtp_mount() { 760 | is_mounted "$@" && return 1 761 | dev=$(echo "$@" | awk '{$1=$2="";print $0}' | xargs) 762 | num=$(echo "$dev" | cut -d : -f1) 763 | mkdir -p "$MOUNTS_DIR/$dev" 764 | if run simple-mtpfs --device "$num" "$MOUNTS_DIR/$dev" 2>&1; then 765 | echo "Mounted $dev at $MOUNTS_DIR/$dev" 766 | else 767 | echo "Failed mounting $dev" 768 | fi 769 | } 770 | 771 | mtp_unmount() { 772 | is_mounted "$@" || return 1 773 | mp=$(echo "$@" | awk '{$1=$2="";print $0}' | xargs) 774 | { 775 | run fusermount -u "$mp" && 776 | run rmdir "$mp" && 777 | echo "Unmounted $mp" 778 | } 2>&1 779 | } 780 | 781 | mtp_mountpoint() { 782 | mp=$(echo "$@" | awk '{$1=$2="";print $0}' | xargs) 783 | [ -d "$mp" ] && echo "$mp" 784 | } 785 | 786 | # gvfs 787 | 788 | gvfs_ls() { 789 | exists gio || return 0 790 | mounts=$(find /run/user/"$(id -u)"/gvfs/ -maxdepth 1 -mindepth 1 \ 791 | -type d -exec basename '{}' \;) 792 | [ -z "$mounts" ] && return 0 793 | echo "$mounts" | while read -r line; do 794 | echo "$MOUNTED#GVFS#$line" 795 | done 796 | } 797 | 798 | gvfs_mount() { 799 | echo 'Mount from the CLI using gio mount' 800 | return 1 801 | } 802 | 803 | gvfs_unmount() { 804 | is_mounted "$@" || return 1 805 | dir=$(gvfs_mountpoint "$@") 806 | run gio mount -u "$dir" 2>&1 807 | } 808 | 809 | gvfs_mountpoint() { 810 | dir=$(echo "$@" | awk '{print $3}') 811 | mp=/run/user/"$(id -u)"/gvfs/"$dir" 812 | [ -e "$mp" ] && echo "$mp" 813 | } 814 | 815 | # fuse others 816 | 817 | fuse_ls() { 818 | fss='encfs|sshfs' 819 | mount | sed -rn "s/(.+) on (.+) type fuse\.($fss) .+/$MOUNTED#FUSE.\3:\1#\2/p" 820 | } 821 | 822 | fuse_mount() { 823 | err 'Cannot mount fuse here' 824 | } 825 | 826 | fuse_unmount() { 827 | is_mounted "$@" || return 1 828 | dev=$(echo "$@" | awk '{print $3}') 829 | run fusermount -u "$dev" 2>&1 830 | } 831 | 832 | fuse_mountpoint() { 833 | mp=$(echo "$@" | awk '{print $3}') 834 | [ -e "$mp" ] && echo "$mp" 835 | } 836 | 837 | # TODO: add ifuse interface 838 | 839 | # all 840 | 841 | devs_ls() { 842 | { 843 | mtp_ls 844 | gvfs_ls 845 | fuse_ls 846 | blocks_ls 847 | } | column -t -s'#' 848 | } 849 | 850 | devs_mount() { 851 | dev=$(echo "$@" | awk '{print $2}') 852 | case "$dev" in 853 | /dev/*) blocks_mount "$@" ;; 854 | MTP*) mtp_mount "$@" ;; 855 | GVFS*) gvfs_mount "$@" ;; 856 | FUSE.*) fuse_mount "$@" ;; 857 | *) return 1 ;; 858 | esac 859 | } 860 | 861 | devs_unmount() { 862 | dev=$(echo "$@" | awk '{print $2}') 863 | case "$dev" in 864 | /dev/*) blocks_unmount "$@" ;; 865 | MTP*) mtp_unmount "$@" ;; 866 | GVFS*) gvfs_unmount "$@" ;; 867 | FUSE.*) fuse_unmount "$@" ;; 868 | *) return 1 ;; 869 | esac 870 | } 871 | 872 | devs_mountpoint() { 873 | dev=$(echo "$@" | awk '{print $2}') 874 | case "$dev" in 875 | /dev/*) blocks_mountpoint "$@" ;; 876 | MTP*) mtp_mountpoint "$@" ;; 877 | GVFS*) gvfs_mountpoint "$@" ;; 878 | FUSE.*) fuse_mountpoint "$@" ;; 879 | *) return 1 ;; 880 | esac 881 | } 882 | 883 | # sync 884 | 885 | dirt() { 886 | sed -En 's/Dirty:\s+(.+) kB/\1/p' /proc/meminfo 887 | } 888 | 889 | sync_progress() { 890 | init=$(dirt) 891 | 892 | if [ "$init" -lt 1024 ]; then 893 | sync 894 | return 895 | fi 896 | 897 | syncing="$TMP_DIR/sync-prog" 898 | touch "$syncing" 899 | { 900 | sync 901 | rm "$syncing" 902 | } & 903 | 904 | while [ -e "$syncing" ]; do 905 | now=$(dirt) 906 | per=$(( (init - now) * 100 / init )) 907 | # echo "$per $now $init" 908 | printf '%.2f%%\r' "$per" 909 | sleep .5 910 | done 911 | echo 912 | } 913 | 914 | # others 915 | 916 | unmount_cwd_if_mounted() { 917 | cwd="$PWD" 918 | dev=$(findmnt -T . -no source) 919 | cd ||: 920 | reset_terminal 921 | 922 | if [ "$dev" = 'gvfsd-fuse' ]; then 923 | gio mount -u "$cwd" 924 | else 925 | udisksctl unmount --no-user-interaction -b "$dev" 926 | fi 2>&1 || cd "$cwd" ||: 927 | } 928 | 929 | mount_monitor() { 930 | # TODO: add mtp and others 931 | reg='s@UDEV .+ add\s+(/devices/.+)(/block)(.+)/(.+) \(block\)@\4@p' 932 | udevadm monitor | sed -rnu "$reg" | while read -r dev; do 933 | part=$(lsblk -no type "/dev/$dev") 934 | if [ "$part" = 'part' ]; then 935 | size=$(lsblk -no size "/dev/$dev" | xargs) 936 | label=$(lsblk -no label "/dev/$dev" | xargs) 937 | [ -n "$label" ] && label="- $label " 938 | msg="Connected $dev $label($size)" 939 | echo "$msg" 940 | 941 | { 942 | if exists dunstify; then 943 | res=$(dunstify -A 'mount,MOUNT' "$msg") 944 | if [ "$res" = mount ]; then 945 | mp=$(udisksctl mount -b "/dev/$dev" | 946 | sed -rn 's/Mounted .+ at (.+)/\1/p') 947 | "$SELF" "$mp" >/dev/null 2>/dev/null 948 | fi 949 | elif exists notify-send; then 950 | notify-send "$msg" 951 | fi 952 | } & 953 | fi 954 | done 955 | } 956 | 957 | # ==== menu interface ==== 958 | 959 | menu_base() { 960 | case "$MENU" in 961 | fzf) 962 | SHELL="$PV_SHELL" fzf \ 963 | --ansi \ 964 | --layout=reverse \ 965 | --no-clear \ 966 | --pointer=' ' \ 967 | --marker='❱' \ 968 | --scroll-off=5 \ 969 | --scrollbar='▐' \ 970 | --separator='' \ 971 | --ellipsis='…' \ 972 | --bind change:first \ 973 | --color='marker:#ffffff' \ 974 | --color='fg+:reverse' \ 975 | --color='bg+:-1' \ 976 | --color='hl:reverse' \ 977 | --color='hl+:reverse' \ 978 | --color='gutter:-1' \ 979 | --info=default \ 980 | "$@" ;; 981 | esac 982 | } 983 | 984 | menu_base_refreshable() { 985 | case "$MENU" in 986 | fzf) 987 | # https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0460 988 | if [ -n "$cmd_refresh" ] && 989 | [ "$fzf_version" -ge 46000 ]; then 990 | menu_base --bind "resize:$cmd_refresh" "$@" 991 | else 992 | menu_base "$@" 993 | fi ;; 994 | esac 995 | } 996 | 997 | reset_terminal() { 998 | case "$MENU" in 999 | fzf) tput rmcup ;; 1000 | esac 1001 | } 1002 | 1003 | # dmenu replacement 1004 | menu_interface() { 1005 | case "$MENU" in 1006 | fzf) 1007 | menu_base \ 1008 | --print-query \ 1009 | --info=hidden \ 1010 | "$@" | tail -n1 ;; 1011 | esac 1012 | } 1013 | 1014 | menu() { 1015 | res=$(echo "$funs" | 1016 | grep . | 1017 | grep -v '^menu ' | 1018 | cut -d ' ' -f2- | 1019 | menu_interface \ 1020 | --prompt "> " \ 1021 | --header "Menu: $f") 1022 | fun=$(echo "$funs" | grep " $res\$" | cut -d ' ' -f1) 1023 | eval "$fun" 1024 | } 1025 | 1026 | menu_search() { 1027 | case "$MENU" in 1028 | fzf) 1029 | menu_base \ 1030 | --preview-window="$PV_WIN" \ 1031 | --preview="$(pv_cmd)" \ 1032 | --layout=reverse \ 1033 | --info=inline ;; 1034 | esac 1035 | } 1036 | 1037 | menu_goto() { 1038 | pv='echo Press ctrl-u to unmount devices if any' 1039 | case "$MENU" in 1040 | fzf) 1041 | b='ctrl-u:'$(force_res_bind "'UNMOUNT' {}") 1042 | menu_interface \ 1043 | --bind="$b" \ 1044 | --preview="$pv" \ 1045 | --preview-window='bottom:1%' \ 1046 | --prompt='Go to> ' ;; 1047 | esac 1048 | } 1049 | 1050 | menu_trash() { 1051 | case "$MENU" in 1052 | fzf) 1053 | menu_base \ 1054 | --preview-window "$PV_WIN" \ 1055 | --preview "'$SELF' --eval trash_preview {}" \ 1056 | --layout reverse \ 1057 | --header "Trash" \ 1058 | --info inline ;; 1059 | esac 1060 | } 1061 | 1062 | menu_main_list_real() { 1063 | case "$MENU" in 1064 | fzf) 1065 | menu_base_refreshable \ 1066 | --multi \ 1067 | --preview-window "$PV_WIN" \ 1068 | --preview "$(pv_cmd)" \ 1069 | --layout reverse \ 1070 | --bind "$bindings" \ 1071 | --header "$(header)" \ 1072 | --query "$query" \ 1073 | --info inline \ 1074 | --print-query \ 1075 | "$@" | tail -n1 ;; 1076 | esac 1077 | } 1078 | 1079 | menu_main_list() { 1080 | if [ -f "$selection" ]; then 1081 | pos=$(cat "$selection") 1082 | pos=$((pos + 1)) 1083 | elif [ -n "$show_up" ]; then 1084 | pos=2 1085 | else 1086 | pos=1 1087 | fi 1088 | menu_main_list_real \ 1089 | --sync \ 1090 | --bind "focus:execute-silent(echo {n} > $selection)" \ 1091 | --bind "start:pos($pos)" 1092 | } 1093 | 1094 | # ==== operations ==== 1095 | 1096 | search() { 1097 | res=$(if exists fd; then 1098 | fd --color=always -L -H -t f 1099 | else 1100 | find . -type f 1101 | fi | menu_search) 1102 | d=$(dirname "$res") 1103 | query=$(basename "$res") 1104 | cd -- "$d" || return 1 1105 | } 1106 | 1107 | open_with_pick() { 1108 | echo | 1109 | mimeopen --ask "$1" 2>/dev/null | 1110 | sed -En 's/\s*(.+\)\s+.+)/\1/p' | 1111 | menu_interface | 1112 | sed -En 's/(.+)\).+/\1/p' 1113 | } 1114 | 1115 | open_with() { 1116 | n=$(open_with_pick "$f") 1117 | [ "$n" ] && echo "$n" | 1118 | mimeopen --ask "$f" >/dev/null 2>/dev/null & 1119 | } 1120 | 1121 | open_with_def() { 1122 | n=$(open_with_pick "$f") 1123 | [ "$n" ] && echo "$n" | 1124 | mimeopen --ask-default "$f" >/dev/null 2>/dev/null & 1125 | } 1126 | 1127 | open_with_editor() { 1128 | tput rmcup 1129 | "$EDITOR" "$f" 1130 | } 1131 | 1132 | copy() { 1133 | [ -n "$fx" ] || return 1134 | exists xclip && 1135 | printf '%s' "$fx" | xclip -i -selection clipboard 1136 | { 1137 | echo "copy" 1138 | echo "$fx" 1139 | } > "$OP_FILE" 1140 | } 1141 | 1142 | move() { 1143 | [ -n "$fx" ] || return 1144 | exists xclip && 1145 | printf '%s' "$fx" | xclip -i -selection clipboard 1146 | { 1147 | echo "move" 1148 | echo "$fx" 1149 | } > "$OP_FILE" 1150 | } 1151 | 1152 | paste() { 1153 | [ -f "$OP_FILE" ] || return 1154 | load=$(cat "$OP_FILE") 1155 | mode=$(echo "$load" | sed -n '1p') 1156 | list=$(echo "$load" | sed '1d') 1157 | [ -n "$list" ] || return 1158 | 1159 | if exists cp-p; then 1160 | srcf=$(mktemp) 1161 | echo "$list" > "$srcf" 1162 | reset_terminal 1163 | case "$mode" in 1164 | copy) 1165 | cp-p --backup=numbered -a -F "$srcf" . ;; 1166 | move) 1167 | mv-p --backup=numbered -F "$srcf" . ;; 1168 | esac 1169 | rm -f "$srcf" 1170 | else 1171 | echo "$list" | while read -r file; do 1172 | case "$mode" in 1173 | copy) cp -ra -- "$file" .;; 1174 | move) mv -- "$file" .;; 1175 | esac 1176 | done 1177 | fi 1178 | lastf=$(echo "$list" | tail -n 1) 1179 | selection_set_selected "$lastf" 1180 | } 1181 | 1182 | paste_symlink() { 1183 | [ -f "$OP_FILE" ] || return 1184 | load=$(cat "$OP_FILE") 1185 | mode=$(echo "$load" | sed -n '1p') 1186 | list=$(echo "$load" | sed '1d') 1187 | 1188 | if [ "$mode" = copy ]; then 1189 | echo "$list" | while read -r file; do 1190 | file=$(realpath --relative-to . "$file") 1191 | ln -s "$file" . 1192 | done 1193 | rm -f "$OP_FILE" 1194 | lastf=$(echo "$list" | tail -n 1) 1195 | selection_set_selected "$lastf" 1196 | fi 1197 | } 1198 | 1199 | delete() { 1200 | count=$(echo "$fx" | wc -l) 1201 | if [ "$count" -gt 1 ]; then 1202 | prompt='Delete multiple files?' 1203 | else 1204 | prompt="Delete $f?" 1205 | fi 1206 | ans=$({ 1207 | echo 'Trash' 1208 | echo 'Delete permanently' 1209 | echo 'Cancel' 1210 | } | menu_interface --prompt "$prompt> ") 1211 | 1212 | echo "$fx" | while read -r file; do 1213 | case "$ans" in 1214 | Trash) 1215 | selection_up 1216 | trash_move "$file" ;; 1217 | Delete*) 1218 | selection_up 1219 | file=$(basename "$file") 1220 | run rm -r -- "$file" ;; 1221 | esac 1222 | done 1223 | } 1224 | 1225 | rename() { 1226 | count=$(echo "$fx" | wc -l) 1227 | 1228 | if [ "$count" = 1 ]; then 1229 | f=$(basename -- "$f") 1230 | name=$(echo | menu_interface \ 1231 | --query "$f" \ 1232 | --prompt "Rename> ") 1233 | [ "$name" ] && { 1234 | if [ -e "$name" ]; then 1235 | echo "$name already exists" 1236 | elif [ "$name" ] && [ "$name" != "$f" ]; then 1237 | mv -- "$f" "$name" 1238 | selection_set_selected "$name" 1239 | fi 1240 | } 1241 | else 1242 | rename_all "$fx" 1243 | fi 1244 | } 1245 | 1246 | rename_all() { 1247 | vidir 1248 | } 1249 | 1250 | chmod_op() { 1251 | tput rmcup 1252 | m=$({ 1253 | echo +x 1254 | echo -x 1255 | echo 644 1256 | echo 755 1257 | } | menu_interface --prompt 'chmod> ') 1258 | [ -n "$m" ] || return 1259 | echo "$fx" | while read -r file; do 1260 | chmod "$m" "$file" 1261 | done 1262 | } 1263 | 1264 | du_op() { 1265 | tput rmcup 1266 | du -sh "$f" 1267 | wait_user 1268 | } 1269 | 1270 | stat_op() { 1271 | tput rmcup 1272 | stat "$f" 1273 | wait_user 1274 | } 1275 | 1276 | mkfolder() { 1277 | name=$(echo | menu_interface --prompt 'New folder name> ') 1278 | if [ -e "$name" ]; then 1279 | echo "$name already exists" 1280 | elif [ "$name" ]; then 1281 | mkdir -p "$name" 1282 | cd -- "$name" || return 1 1283 | fi 1284 | } 1285 | 1286 | mkfile() { 1287 | name=$(echo | menu_interface --prompt 'New file name> ') 1288 | if [ -e "$name" ]; then 1289 | echo "$name already exists" 1290 | elif [ "$name" ]; then 1291 | touch "$name" 1292 | selection_set_selected "$name" 1293 | fi 1294 | } 1295 | 1296 | new() { 1297 | res=$(printf 'Folder\nFile' | menu_interface --prompt "New> ") 1298 | case "$res" in 1299 | 'Folder') mkfolder ;; 1300 | 'File') mkfile ;; 1301 | *) # if not specified, take a guess 1302 | name="$res" 1303 | if [ -e "$name" ]; then 1304 | echo "$name already exists" 1305 | return 1306 | fi 1307 | 1308 | if echo "$name" | grep -q '..*\...*'; then 1309 | # something with an extension, likely a file 1310 | touch "$name" 1311 | selection_set_selected "$name" 1312 | else 1313 | mkdir -p "$name" 1314 | cd -- "$name" || return 1 1315 | fi 1316 | esac 1317 | } 1318 | 1319 | mkarchive() { 1320 | types='zip tar 7z' 1321 | type=$({ 1322 | for t in $types; do 1323 | exists "$t" && echo "$t" 1324 | done 1325 | } | menu_interface --prompt "Archive type> ") 1326 | name=$(basename "$(realpath -- "$f")" | cut -d . -f1) 1327 | name=$(echo | menu_interface --prompt 'Archive name> ' --query "$name") 1328 | reset_terminal 1329 | [ -z "$name" ] && { 1330 | info "No name provided for the $type, skipping" 1331 | return 1 1332 | } 1333 | printf '%s' "$fx" | relativify | 1334 | xargs -d '\n' "$SELF" --eval "mk$type" "$name" 1335 | } 1336 | 1337 | recent_push() { 1338 | realpath "$1" >> "$RECENT_FILE" 1339 | awk '!x[$0]++' < "$RECENT_FILE" | while read -r line; do 1340 | [ -f "$line" ] && echo "$line" 1341 | done | tail -n 10 > "$RECENT_DIR.min" 1342 | mv "$RECENT_DIR.min" "$RECENT_FILE" 1343 | } 1344 | 1345 | recent_list() { 1346 | [ -f "$RECENT_FILE" ] && tac "$RECENT_FILE" 1347 | } 1348 | 1349 | goto_items() { 1350 | echo "$bookmarks" | tr ':' '\n' 1351 | echo 'Trash' 1352 | devs_ls 1353 | rec=$(recent_list) && echo "$rec" | while read -r l; do 1354 | echo "$RECENT" "$l" 1355 | done 1356 | } 1357 | 1358 | goto_run() { 1359 | res="$1" 1360 | confirm= 1361 | reset_terminal 1362 | case "$res" in 1363 | "$RECENT"*) 1364 | res=$(echo "$res" | cut -d ' ' -f2-) 1365 | d=$(dirname "$res") 1366 | n=$(basename "$res") 1367 | cd "$d" && selection_set_selected "$n" ;; 1368 | "$MOUNTED"*) 1369 | res=$(devs_mountpoint "$res") ;; 1370 | "$UNMOUNTED"*) 1371 | echo 'Mounting...' 1372 | devs_mount "$res" && 1373 | res=$(devs_mountpoint "$res") 1374 | confirm=1 ;; 1375 | 'UNMOUNT'*) 1376 | echo 'Unmounting...' 1377 | mnt_here=$(findmnt -T . -no source) 1378 | mnt_there=$(echo "$res" | awk '{print $3}') 1379 | if [ "$mnt_here" = "$mnt_there" ]; then 1380 | cd ||: 1381 | fi 1382 | run sync_progress 1383 | line=$(echo "$res" | cut -d ' ' -f2-) 1384 | devs_unmount "$line" || { 1385 | mp=$(lsblk "$mnt_there" -no mountpoint) 1386 | err "Failed unmounting from $mp" 1387 | if exists lsof; then 1388 | run lsof "$mp" 1389 | pids=$(lsof "$mp" 2>/dev/null | 1390 | tail -n +2 | awk '{print $2}' | tr '\n' ' ') 1391 | ask 'Kill all of the above? [y/N]' 1392 | read -r ans 1393 | if [ "$ans" = y ]; then 1394 | # shellcheck disable=SC2086 1395 | run kill $pids 1396 | devs_unmount "$line" || 1397 | err "Failed unmounting again" 1398 | fi 1399 | fi 1400 | } 1401 | confirm=1 ;; 1402 | 'Trash') 1403 | trash_menu ;; 1404 | esac 1405 | 1406 | [ "$confirm" ] && wait_user 1407 | 1408 | [ -d "$res" ] || res="$PWD" 1409 | cd -- "$res" ||: 1410 | } 1411 | 1412 | goto() { 1413 | res=AGAIN 1414 | while [ "$res" = AGAIN ]; do 1415 | res=$({ 1416 | realpath . 1417 | goto_items 1418 | } | menu_goto) 1419 | res=$(check_forced_res "$res") 1420 | goto_run "$res" 1421 | done 1422 | } 1423 | 1424 | shell() { 1425 | reset_terminal 1426 | $SHELL 1427 | } 1428 | 1429 | tog_hidden() { 1430 | if [ -f "$HIDDEN_FILE" ]; then 1431 | rm "$HIDDEN_FILE" 1432 | else 1433 | touch "$HIDDEN_FILE" 1434 | fi 1435 | } 1436 | 1437 | dnd() { 1438 | if exists dragon; then 1439 | dragoncmd=dragon 1440 | elif exists dragon-drop; then 1441 | dragoncmd=dragon-drop 1442 | else 1443 | return 1 1444 | fi 1445 | echo "$fx" | xargs -d '\n' $dragoncmd -a -x & 1446 | } 1447 | 1448 | lssort() { 1449 | if [ "$1" ]; then 1450 | echo "$1" > "$SORT_FILE" 1451 | else 1452 | rm -f "$SORT_FILE" 1453 | fi 1454 | } 1455 | 1456 | sort_normally() { 1457 | lssort '' 1458 | } 1459 | 1460 | sort_by_time() { 1461 | lssort time 1462 | } 1463 | 1464 | sort_by_size() { 1465 | lssort size 1466 | } 1467 | 1468 | # ==== main ui ==== 1469 | 1470 | list() { 1471 | lsopts= 1472 | lsopts="$lsopts -1 -N -v" 1473 | lsopts="$lsopts --group-directories-first" 1474 | lsopts="$lsopts --color=always" 1475 | if [ -f "$HIDDEN_FILE" ]; then 1476 | lsopts="$lsopts -A" 1477 | fi 1478 | 1479 | sort= 1480 | if [ -d "$1" ] && [ -f "$1"/.sort-by ] 1481 | then sort=$(cat "$1"/.sort-by) 1482 | elif [ -f ./.sort-by ] 1483 | then sort=$(cat ./.sort-by) 1484 | elif [ -f "$SORT_FILE" ] 1485 | then sort=$(cat "$SORT_FILE") 1486 | fi 1487 | # make sure nothing nasty is in the sort file 1488 | sort_opts='none|size|time|version|extension|width' 1489 | sort=$(echo "$sort" | 1490 | sed -rn 's/^(reverse )?(name|'$sort_opts')$/\1\n\2/p') 1491 | sort_reverse=$(echo "$sort" | head -n1 | xargs) 1492 | sort=$(echo "$sort" | tail -n1 | xargs) 1493 | case "$sort" in 1494 | name) ;; # already sorted by name 1495 | none|size|time|version|extension|width) 1496 | lsopts="$lsopts --sort=$sort" ;; 1497 | esac 1498 | [ "$sort_reverse" = reverse ] && 1499 | lsopts="$lsopts --reverse" 1500 | 1501 | # shellcheck disable=SC2086 1502 | res=$(command ls $lsopts "$@") 1503 | if [ "$res" ]; then 1504 | echo "$res" 1505 | else 1506 | echo "$EMPTY" 1507 | fi 1508 | } 1509 | 1510 | header() { 1511 | exists git && { 1512 | git=$(git branch --show-current 2>/dev/null) 1513 | [ "$git" ] && git=" ($git)" 1514 | } 1515 | dev=$(findmnt -T . -no "source,avail,size,label" | 1516 | awk '$4 != "" {$4 = $4" "}; 1517 | {printf "%s%s (%s/%s)", $4, $1, $2, $3}') 1518 | max_cwd_len=$(tput cols) 1519 | if [ "$PV_WIN" = 'right:50%' ]; then 1520 | max_cwd_len=$((max_cwd_len / 4)) 1521 | else 1522 | max_cwd_len=$((max_cwd_len / 2)) 1523 | fi 1524 | cwd=$(pwd | sed "s@$HOME@~@") 1525 | cwd_len="${#cwd}" 1526 | [ "$cwd_len" -gt "$max_cwd_len" ] && { 1527 | cwd=$(echo "$cwd" | tail -c "$max_cwd_len") 1528 | cwd="...$cwd" 1529 | } 1530 | printf '\033[1m\033[34m%s\033[1m: \033[37m%s\033[1m\033[32m%s\033[0m\033[0m' \ 1531 | "$cwd" "$dev" "$git" 1532 | } 1533 | 1534 | preview() { 1535 | use_stpv="$1" 1536 | shift 1537 | f="$1" 1538 | id="$6" 1539 | if [ "$use_stpv" = 1 ]; then 1540 | stpvimg --clear "$id" 1541 | fi 1542 | if [ -d "$f" ]; then 1543 | list "$f" 1544 | elif [ "$use_stpv" = 1 ]; then 1545 | stpv "$@" 1546 | else 1547 | cat -- "$f" 2>/dev/null || 1548 | file -- "$f" 1549 | fi 1550 | } 1551 | 1552 | pv_cmd() { 1553 | if [ $# = 1 ]; then 1554 | target="'$1'" 1555 | else 1556 | target='{}' 1557 | fi 1558 | case "$MENU" in 1559 | fzf) 1560 | cmd="[ -e $target ]" 1561 | [ "$target" = '{}' ] && 1562 | cmd="$cmd && printf '(%d) ' \$(({n} + 1))" 1563 | cmd="$cmd && ls -lhd -- $target" 1564 | if [ "$PV_WIN" != 'down:1%' ]; then 1565 | cmd="$cmd && '$SELF' --eval preview" 1566 | cmd="$cmd '$USE_STPV' $target $PV_W $PV_H $PV_X $PV_Y $ID" 1567 | fi ;; 1568 | esac 1569 | echo "$cmd" 1570 | } 1571 | 1572 | update_term_size() { 1573 | W=$(tput cols) 1574 | H=$(tput lines) 1575 | 1576 | case "$MENU" in 1577 | fzf) 1578 | if [ "$W" -le 55 ] && [ "$H" -le 15 ]; then 1579 | PV_WIN='down:1%' 1580 | PV_X= ; PV_Y= ; PV_W= ; PV_H= 1581 | elif [ "$W" -gt $((H * 2 + 10)) ]; then 1582 | PV_WIN='right:50%' 1583 | PV_X=$((W / 2 + 3)) 1584 | PV_Y=3 1585 | PV_W=$((((W - 1) / 2) - 4)) 1586 | PV_H=$((H - 3)) 1587 | else 1588 | PV_WIN='down:50%' 1589 | PV_X=2 1590 | PV_Y=$((H / 2 + 3)) 1591 | PV_W=$((W - 3)) 1592 | PV_H=$((((H - 1) / 2) - 2)) 1593 | fi ;; 1594 | esac 1595 | } 1596 | 1597 | selection_file() { 1598 | sum=$(realpath -- "$1" | cksum | cut -d ' ' -f1) 1599 | echo "${LAST_FILE}${sum}" 1600 | } 1601 | 1602 | selection_set_selected() { 1603 | doingit || return 0 1604 | file=$(basename "$1") 1605 | selection=$(selection_file .) 1606 | n=$(list | remove_ansi | 1607 | grep -x -m1 -n "$file" | 1608 | cut -d: -f1) 1609 | [ -n "$n" ] || return 1610 | # plus one if show_up; n-1+1=n 1611 | [ -n "$show_up" ] || n=$((n - 1)) 1612 | echo "$n" > "$selection" 1613 | } 1614 | 1615 | selection_up() { 1616 | # moves the selection up 1617 | selection=$(selection_file .) 1618 | if [ -f "$selection" ]; then 1619 | n=$(cat "$selection") 1620 | n=$((n - 1)) 1621 | if [ "$n" -ge 0 ]; then 1622 | echo "$n" > "$selection" 1623 | fi 1624 | fi 1625 | } 1626 | 1627 | doingit() { 1628 | [ -f "$PENDING_FILE" ] 1629 | } 1630 | 1631 | doit() { 1632 | touch "$PENDING_FILE" 1633 | chmod 600 "$PENDING_FILE" 1634 | 1635 | while :; do 1636 | selection=$(selection_file .) 1637 | 1638 | [ "$TMUX" ] && { 1639 | title=$(basename "$(realpath .)") 1640 | tmux set automatic-rename off 1641 | tmux rename-window "$title" 1642 | } 1643 | 1644 | res=$({ 1645 | [ -n "$show_up" ] && echo .. 1646 | list 1647 | [ -z "$quick_goto" ] || { 1648 | echo '======' 1649 | goto_items 1650 | } 1651 | } | menu_main_list) 1652 | res=$(check_forced_res "$res") 1653 | 1654 | [ "$USE_STPV" ] && 1655 | stpvimg --clear $ID 1656 | 1657 | if [ -e "$res" ]; then 1658 | query= 1659 | if [ -f "$res" ]; then 1660 | if exists archivemount && isarchive "$res"; then 1661 | archive_mnt=$(archive_mount "$res") 1662 | [ -L "$archive_mnt" ] && { 1663 | cd -- "$archive_mnt" || return 1 1664 | } 1665 | else 1666 | [ "$TMUX" ] && tmux set automatic-rename on 1667 | if [ "$OPENER" ]; then 1668 | "$OPENER" "$res" 1669 | elif exists open; then 1670 | open "$res" 1671 | elif exists xdg-open; then 1672 | xdg-open "$res" 1673 | else 1674 | less -c "$res" 1675 | fi 2>/dev/null 1676 | 1677 | recent_push "$res" 1678 | fi 1679 | 1680 | elif [ -d "$res" ]; then 1681 | if [ "$res" = '..' ]; then 1682 | case "$MENU" in 1683 | fzf) 1684 | this=$(basename "$PWD") 1685 | (cd .. && selection_set_selected "$this") ;; 1686 | esac 1687 | fi 1688 | 1689 | cd -- "$res" ||: 1690 | 1691 | for mnt in "$PWD/"*-archive; do 1692 | [ -L "$mnt" ] && { 1693 | arc=$(echo "$mnt" | 1694 | sed -En 's/(.+)\-archive/\1/p') 1695 | archive_umount "$arc" 1696 | } 1697 | done 1698 | fi 1699 | 1700 | elif echo "$res" | grep -q '^\$'; then 1701 | # because the menu messes with stdin and out 1702 | # so, we can exit with a command to be executed 1703 | cmd=$(echo "$res" | sed 's/^\$ *//') 1704 | eval "$cmd" 1705 | 1706 | elif echo "$res" | grep -q '^>'; then 1707 | # same as above, but show everything 1708 | cmd=$(echo "$res" | sed 's/^> *//') 1709 | reset_terminal 1710 | run_show "$cmd" 1711 | eval "$cmd" 1712 | wait_user 1713 | 1714 | elif [ -z "$res" ]; then 1715 | break 1716 | 1717 | else 1718 | goto_run "$res" 1719 | fi 1720 | 1721 | update_term_size 1722 | stty "$stty_origin" # not really usefull 1723 | done 1724 | 1725 | reset_terminal 1726 | 1727 | [ "$USE_STPV" ] && 1728 | stpvimg --end $ID 1729 | 1730 | rm -rf "$TMP_DIR" 1731 | 1732 | [ "$TMUX" ] && tmux set automatic-rename on 1733 | 1734 | if [ -f "$CD" ]; then 1735 | pwd > "$CD" 1736 | else 1737 | pwd 1738 | fi 1739 | } 1740 | 1741 | # ==== main ==== 1742 | 1743 | conf_init() { 1744 | # default config 1745 | 1746 | case "$MENU" in 1747 | fzf) 1748 | cmd_accept='accept' 1749 | cmd_parent=$(force_res_bind ..) 1750 | cmd_sel_up='toggle+up' 1751 | cmd_sel_down='toggle+down' 1752 | cmd_sel_all='select-all' 1753 | cmd_sel_clear='clear-selection' 1754 | cmd_pv_up='preview-up' 1755 | cmd_pv_down='preview-down' 1756 | cmd_refresh=$(force_res_bind .) ;; 1757 | esac 1758 | 1759 | exists mimeopen && { 1760 | add_fun open_with 'Open with' 1761 | add_fun open_with_def 'Set default' 1762 | } 1763 | [ -n "$EDITOR" ] && exists "$EDITOR" && 1764 | add_fun open_with_editor 'Edit text file' 1765 | 1766 | add_fun new 'New file or folder' 1767 | add_fun copy 'Copy' 1768 | add_fun move 'Move' 1769 | add_fun paste 'Paste' 1770 | add_fun paste_symlink 'Paste symbolic link' 1771 | add_fun delete 'Delete' 1772 | add_fun rename 'Rename' 1773 | exists vidir && add_fun rename_all 'Rename all' 1774 | add_fun chmod_op 'Chmod' 1775 | add_fun du_op 'Disk usage' 1776 | add_fun stat_op 'File status' 1777 | add_fun sort_normally 'Sort normally' 1778 | add_fun sort_by_time 'Sort by time' 1779 | add_fun sort_by_size 'Sort by size' 1780 | add_fun search 'Search for files here' 1781 | add_fun tog_hidden 'Show/hide hidden files' 1782 | add_fun goto 'Go to' 1783 | add_fun archive_extract 'Extract archive' 1784 | add_fun mkarchive 'Create archive' 1785 | add_fun shell 'Start a shell here' 1786 | add_fun show_help 'Show help screen' 1787 | add_fun menu 'Open menu' 1788 | 1789 | bind enter "$cmd_accept" 'Open selected item' 1790 | bind right "$cmd_accept" 'Open selected item' 1791 | bind left "$cmd_parent" 'Go to parent directory' 1792 | bind home "first" 'Jump to first element' 1793 | bind end "last" 'Jump to last element' 1794 | bind shift-up "$cmd_sel_up" 'Mark and move selection up' 1795 | bind shift-down "$cmd_sel_down" 'Mark and move selection down' 1796 | bind ctrl-a "$cmd_sel_all" 'Select all' 1797 | bind ctrl-g "$cmd_sel_clear" 'Clear selection' 1798 | bind alt-up "$cmd_pv_up" 'Scroll preview up' 1799 | bind alt-down "$cmd_pv_down" 'Scroll preview down' 1800 | bind f5 "$cmd_refresh" 'Refresh' 1801 | bind alt-x fun menu 1802 | bind ctrl-n funq new 1803 | bind ctrl-c fun copy 1804 | bind ctrl-x fun move 1805 | bind ctrl-v funq paste 1806 | bind f2 fun rename 1807 | bind del fun delete 1808 | bind ctrl-f funq search 1809 | bind ctrl-l funq goto 1810 | bind ctrl-h funq tog_hidden 1811 | bind ctrl-s fun shell 1812 | bind ctrl-u funq unmount_cwd_if_mounted 1813 | bind ctrl-q "abort" 'Quit' 1814 | bind esc "abort" 'Quit' 1815 | bind f1 funq show_help 1816 | 1817 | exists dragon || exists dragon-drop && { 1818 | add_fun dnd 'Drag and drop' 1819 | bind ctrl-d fun dnd 1820 | } 1821 | 1822 | bookmark ~/Documents 1823 | bookmark ~/Pictures 1824 | bookmark ~/Videos 1825 | bookmark ~/Music 1826 | bookmark ~/Downloads 1827 | bookmark ~/Projects 1828 | 1829 | # load config 1830 | 1831 | mkdir -p "$CFG_DIR" 1832 | [ -f "$CFG_FILE" ] && . "$CFG_FILE" 1833 | } 1834 | 1835 | main() { 1836 | exists dash && PV_SHELL=dash 1837 | case "$MENU" in 1838 | fzf) 1839 | fzf_version=$(fzf --version | version_to_int) 1840 | if [ "$fzf_version" -lt $FZF_MIN_VERSION ]; then 1841 | echo "fzf version $fzf_version is old," \ 1842 | "fzf $FZF_MIN_VERSION is required" 1843 | return 1 1844 | fi ;; 1845 | *) 1846 | echo "Menu '$MENU' is not supported" >&2 1847 | return 1 ;; 1848 | esac 1849 | 1850 | mkdir -p "$MOUNTS_DIR" 1851 | conf_init 1852 | 1853 | case "$1" in 1854 | --cd) 1855 | CD="$2" 1856 | shift 2 1857 | esac 1858 | 1859 | case "$1" in 1860 | --eval) shift; "$@" ;; 1861 | --mount-monitor) mount_monitor ;; 1862 | *) 1863 | query= 1864 | if [ -d "$1" ]; then 1865 | d="$1" 1866 | cd -- "$d" || return 1 1867 | elif [ -f "$1" ]; then 1868 | d=$(dirname "$1") 1869 | query=$(basename "$1") 1870 | cd -- "$d" || return 1 1871 | fi 1872 | [ ! -t 1 ] && { 1873 | if [ -d "$d" ]; then 1874 | cd ||: 1875 | fi 1876 | exec "$TERMINAL" -e env TERM=screen-256color "$SELF" "$@" 1877 | } 1878 | 1879 | [ "$FMZ_SHELL" ] && { 1880 | echo "Already in a shell inside of $NAME." 1881 | echo "To force nested instances, clear FMZ_SHELL." 1882 | return 1 1883 | } 1884 | 1885 | exists stpv && USE_STPV=1 1886 | update_term_size 1887 | [ -n "$USE_STPV" ] && { 1888 | (cd && stpvimg --listen $ID 2>/dev/null) & 1889 | } 1890 | 1891 | mkdir -p "$TMP_DIR" 1892 | stty_origin=$(stty -g) 1893 | archive_mnt= 1894 | res=. 1895 | doit "$@" 1896 | esac 1897 | } 1898 | 1899 | main "$@" 1900 | -------------------------------------------------------------------------------- /fmz.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Name=fmz 4 | Comment=Fuzzy file manager 5 | Icon=utilities-terminal 6 | Terminal=true 7 | Exec=fmz %F 8 | Categories=ConsoleOnly;System;FileTools;FileManager 9 | MimeType=inode/directory; 10 | -------------------------------------------------------------------------------- /vid/2021-04-03-tiny.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Naheel-Azawy/fmz/286eb18f18a34cefccc06f7d5a3bdbaf6643b40e/vid/2021-04-03-tiny.gif -------------------------------------------------------------------------------- /vid/2021-04-03.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Naheel-Azawy/fmz/286eb18f18a34cefccc06f7d5a3bdbaf6643b40e/vid/2021-04-03.mp4 --------------------------------------------------------------------------------