diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 9cecc1d4..00000000 --- a/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - {one line to give the program's name and a brief idea of what it does.} - Copyright (C) {year} {name of author} - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - {project} Copyright (C) {year} {fullname} - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/README.md b/README.md index 6dd82e2b..423592b1 100644 --- a/README.md +++ b/README.md @@ -1,79 +1,2 @@ -
-
- logo.png -
-

- -**Gnu-linux-shell-scripting** is a foundation for shell scripting in GNU/Linux. - -It is made up of the following four types of solutions: - -1. Scripts -2. Functions scripts -3. One-liners -4. Aliases - -# Categories - -Here is a list of all the categories with a few examples in each: - -## Application management - -* [Generic RDBMS utility functions for a MySQL database](functions_scripts/application_management/database/mysqldbutils) -* [Check if a PostgreSQL database exists.](one-liners/application_management/database/postgresql-database.one-liners) - -## File management - -* [Rename all files matching a name recursively.](scripts/file_management/file_name_manipulation/renmrecr) -* [Get the size in megabytes of one or more files and/or directories.](one-liners/file_management-output_only/file_information/file-property-information-retrieval.one-liners) - -## System management - -* [List all processes owned by the current user.](aliases/system_management-output_only/process_information/process-general-information-retrieval.aliases) -* [Print the target architecture of the current operating system.](one-liners/system_management-output_only/operating_system_information/operating-system-property-information-retrieval.one-liners) - -## Hardware management - -* [Check if the primary wireless local area network device interface is soft blocked.](scripts/hardware_management-output_only/device_information/iswlanblocked) -* [Get the vendor name of the CPU.](one-liners/hardware_management-output_only/cpu_information/cpu-property-information-retrieval.one-liners) - -## Shell management - -* [Execute a command in the background.](scripts/shell_management-modules/process_management/execinbg) -* [Remove the last N entries from the bash history.](scripts/shell_management/history_management/remvlastnentriesfrombashhist) - -## X11 management - -* [Get the ID of the active window.](scripts/x11_management-output_only/window_property_information/getactvwindid) -* [Get the class of a window by ID.](scripts/x11_management-output_only/window_property_information/getwindclassbyid) - -## Mobile device management - -* [Watch the X and Y screen tap positions of an Android device.](scripts/mobile_device_management-android/hardware_management/watchandroiddevscreentappos) -* [Mount and unmount an MTP device.](scripts/mobile_device_management-generic/mounting/mntmtp) - -## Scripting - -* [Bash array utilities](functions_scripts/scripting/bash/arrayutils.bash) -* [Bash date and time utilities](functions_scripts/scripting/bash/dateandtimeutils.bash) - -## Text manipulation - -* [Replace all occurrences of a string recursively.](scripts/text_manipulation/matching/replrecr) - -## Text processing - -* [Count the number of characters in a string.](aliases/text_processing/numeric_processing/basic-numberic-processing.aliases) - -## Number processing - -* [Convert a hexidecimal number to decimal.](aliases/number_processing/conversion/base-conversion.aliases) - -# Packaged solutions - -**Gnu-linux-shell-scripting** has an [extension repository](https://github.com/computingfoundation/gnu-linux-shell-scripting.packaged-solutions) for solutions consisting of more than one file. - -# Code style guidelines - -All the solutions in this repository follow [this](https://github.com/computingfoundation/gnu-linux-shell-scripting/wiki) standard guideline. +A branch for helper scripts diff --git a/aliases/README.md b/aliases/README.md deleted file mode 100644 index 72d5c07c..00000000 --- a/aliases/README.md +++ /dev/null @@ -1,32 +0,0 @@ - -# Aliases - -This directory contains aliases and frequently used short functions. - -## View all - -To view all the solutions in this directory, change to it and run the following: - -```bash -git show-ref --verify -q refs/heads/helper_scripts || \ -git branch --track helper_scripts origin/helper_scripts; \ -bash <(git show helper_scripts:cf-gpc-view-aliases.sh) -``` - -## Usage - -Add the following code in your .bashrc file to source all the aliases and short functions in your bash runtime environment: - -```bash -for compFndtGnuLinuxShellUseAliasesFile in $(find "/aliases" \ - -type f -name '*.aliases*'); do - source "${compFndtGnuLinuxShellUseAliasesFile}" -done -``` - -## Notes - -* Aliases do not support file names with spaces. -* Some aliases use environment variables (e.g. ${EDITOR}) which must be defined if not already or replaced if possible. -* Some aliases require a common dependency (e.g. gcc) which will be specified in the description. - diff --git a/aliases/file_management-output_only/README.md b/aliases/file_management-output_only/README.md deleted file mode 100644 index c160fb45..00000000 --- a/aliases/file_management-output_only/README.md +++ /dev/null @@ -1,16 +0,0 @@ - -# File management - output only - -## Directory information - -* [Directory context information retrieval aliases](directory_information/directory-context-information-retrieval.aliases) - -## File finding - -* [Name matching file finding aliases](file_finding/name-matching-file-finding.aliases) -* [Text occurrence matching file finding aliases](file_finding/text-occurrence-matching-file-finding.aliases) - -## File permission information - -* [Recursive file permission information retrieval aliases](file_permission_information/recursive-file-permission-information-retrieval.aliases) - diff --git a/aliases/file_management-output_only/directory_information/directory-context-information-retrieval.aliases b/aliases/file_management-output_only/directory_information/directory-context-information-retrieval.aliases deleted file mode 100644 index 5d6fe6ae..00000000 --- a/aliases/file_management-output_only/directory_information/directory-context-information-retrieval.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# directory-context-information-retrieval.aliases -# -# Description: -# Directory context information retrieval aliases -# - -alias numfiles='echo "$(ls -1 | wc -l)"' # numfiles: Print the number of non-hidden files and directories in the current directory. - diff --git a/aliases/file_management-output_only/file_finding/name-matching-file-finding.aliases b/aliases/file_management-output_only/file_finding/name-matching-file-finding.aliases deleted file mode 100644 index d9b1f9ce..00000000 --- a/aliases/file_management-output_only/file_finding/name-matching-file-finding.aliases +++ /dev/null @@ -1,23 +0,0 @@ -# -# File: -# name-matching-file-finding.aliases -# -# Description: -# Name matching file finding aliases -# - -# [MULTI-FILE OUTPUT] - -ff() { find . -type f -name "*${1}*"; } # ff: Recursively find all files matching a name name; $1: file name. -fd() { find . -type d -name "*${1}*"; } # fd: Recursively find all directories matching a name name; $1: directory name. - -# [SINGLE-FILE OUTPUT] - -fff() { find . -type f -name "*${1}*" -print -quit; } # fff: Recursively find the first file matching a name; $1: file name. -fdf() { find . -type d -name "*${1}*" -print -quit; } # fdf: Recursively find the first directory matching a name; $1: directory name. -fffa() { find "$PWD" -type f -name "*${1}*" -print -quit; } # fffa: Recursively find the first file matching a name and return its absolute path; $1: file name. -fdfa() { find "$PWD" -type d -name "*${1}*" -print -quit; } # fdfa: Recursively find the first directory matching a name and return its absolute path; $1: directory name. - -ffd() { echo "$(find . -type f -name "*${1}*" -exec sh -c 'echo "${1%/*}"; \ - kill "$PPID"' sh {} \;)" ;} # ffd: Recursively find the first file matching a name and return its parent directory; $1: file name. - diff --git a/aliases/file_management-output_only/file_finding/text-occurrence-matching-file-finding.aliases b/aliases/file_management-output_only/file_finding/text-occurrence-matching-file-finding.aliases deleted file mode 100644 index ef62e677..00000000 --- a/aliases/file_management-output_only/file_finding/text-occurrence-matching-file-finding.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# text-occurrence-matching-file-finding.aliases -# -# Description: -# Text occurrence matching file finding aliases -# - -ffgr() { /usr/bin/grep -l -R "${1}" .; } # ffgr: Recursively find all files containing the given text; $1: text to search. - diff --git a/aliases/file_management-output_only/file_permission_information/recursive-file-permission-information-retrieval.aliases b/aliases/file_management-output_only/file_permission_information/recursive-file-permission-information-retrieval.aliases deleted file mode 100644 index 07742d3e..00000000 --- a/aliases/file_management-output_only/file_permission_information/recursive-file-permission-information-retrieval.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# recursive-file-permission-information-retrieval.aliases -# -# Description: -# Recursive file permission information retrieval aliases -# - -alias ll='command ls -FGlAhp' # ll: List the permissions and owner of each file in the current directory. - diff --git a/aliases/file_management/README.md b/aliases/file_management/README.md deleted file mode 100644 index 4311d70c..00000000 --- a/aliases/file_management/README.md +++ /dev/null @@ -1,8 +0,0 @@ - -# File management - -## File permission altering - -* [Single permission change aliases](file_permission_altering/single-permission-change.aliases) -* [Multiple permission change aliases](file_permission_altering/multiple-permission-change.aliases) - diff --git a/aliases/file_management/file_permission_altering/multiple-permission-change.aliases b/aliases/file_management/file_permission_altering/multiple-permission-change.aliases deleted file mode 100644 index e44b0d2f..00000000 --- a/aliases/file_management/file_permission_altering/multiple-permission-change.aliases +++ /dev/null @@ -1,11 +0,0 @@ -# -# File: -# multiple-permission-change.aliases -# -# Description: -# Multiple permission change aliases -# - -alias permusergroupreadwrite='chmod ug+rw' # permusergroupreadwrite: Give the user and group read and write permissions to a file. -alias permusergroupreadwritexec='chmod ug+rwx' # permusergroupreadwriteexec: Give the user and group read, write and execute permissions to a file. - diff --git a/aliases/file_management/file_permission_altering/single-permission-change.aliases b/aliases/file_management/file_permission_altering/single-permission-change.aliases deleted file mode 100644 index 5ec12aef..00000000 --- a/aliases/file_management/file_permission_altering/single-permission-change.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# single-permission-change.aliases -# -# Description: -# Single permission change aliases -# - -alias permreadonly='chmod a-w' # permreadonly: Change the permisson status of a file to read-only. - diff --git a/aliases/hardware_management-output_only/README.md b/aliases/hardware_management-output_only/README.md deleted file mode 100644 index d0801e27..00000000 --- a/aliases/hardware_management-output_only/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Hardware management - output only - -## Power supply - -* [Power supply status information retrieval aliases](power_supply/power-supply-status-information-retrieval.aliases) - diff --git a/aliases/hardware_management-output_only/power_supply/power-supply-status-information-retrieval.aliases b/aliases/hardware_management-output_only/power_supply/power-supply-status-information-retrieval.aliases deleted file mode 100644 index efec8198..00000000 --- a/aliases/hardware_management-output_only/power_supply/power-supply-status-information-retrieval.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# power-supply-status-information-retrieval.aliases -# -# Description: -# Power supply status information retrieval aliases -# - -alias batthrs='upower -i /org/freedesktop/UPower/devices/DisplayDevice | sed -n 12,12p | awk "{print $4}"' # batthrs: Get the number of remaining hours of battery life. - diff --git a/aliases/hardware_management/README.md b/aliases/hardware_management/README.md deleted file mode 100644 index b06b5820..00000000 --- a/aliases/hardware_management/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Hardware management - -## Monitor - -* [Monitor power management aliases](monitor/monitor-power-management.aliases) - diff --git a/aliases/hardware_management/monitor/monitor-power-management.aliases b/aliases/hardware_management/monitor/monitor-power-management.aliases deleted file mode 100644 index 26f5e227..00000000 --- a/aliases/hardware_management/monitor/monitor-power-management.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# monitor-power-management.aliases -# -# Description: -# Monitor power management aliases -# - -alias suspendmonitor='sleep .7; xset dpms force off' # suspendmonitor: Suspend the monitor. - diff --git a/aliases/mobile_device_management-android/README.md b/aliases/mobile_device_management-android/README.md deleted file mode 100644 index c03e4296..00000000 --- a/aliases/mobile_device_management-android/README.md +++ /dev/null @@ -1,8 +0,0 @@ - -# Mobile device management - Android - -## Network management - -* [Android internet network management aliases](network_management/internet-network-management.aliases) -* [Android local network network management aliases](network_management/local-network-network-management.aliases) - diff --git a/aliases/mobile_device_management-android/SOURCES.txt b/aliases/mobile_device_management-android/SOURCES.txt deleted file mode 100644 index dbf22238..00000000 --- a/aliases/mobile_device_management-android/SOURCES.txt +++ /dev/null @@ -1,11 +0,0 @@ - -Sources for Mobile device management - Android aliases - -network_management/internet-network-management.aliases: - - androidcellip: http://stackoverflow.com/a/3623727 - -network_management/local-network-network-management.aliases: - - androidwlanip: http://stackoverflow.com/a/3623727 - diff --git a/aliases/mobile_device_management-android/application_management/application-information-retrieval.aliases b/aliases/mobile_device_management-android/application_management/application-information-retrieval.aliases deleted file mode 100644 index cfa5ea89..00000000 --- a/aliases/mobile_device_management-android/application_management/application-information-retrieval.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# application-information-retrieval.aliases -# -# Description: -# Application information retrieval aliases -# - -alias androidforgapplpackname="adb -d shell dumpsys window windows | grep mCurrentFocus | cut -d'/' -f1 | rev | cut -d' ' -f1 | rev" # androidforgapplpackname: Get the package name of the foreground application - diff --git a/aliases/mobile_device_management-android/network_management/internet-network-management.aliases b/aliases/mobile_device_management-android/network_management/internet-network-management.aliases deleted file mode 100644 index e62a1a01..00000000 --- a/aliases/mobile_device_management-android/network_management/internet-network-management.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# internet-network-management.aliases -# -# Description: -# Android internet network management aliases -# - -alias androidcellip="adb shell ip -f inet addr show rmnet0|sed -n '2{p;q}'|tr -s ' '|awk -F'[/ ]' '{print \$3}'" # androidcellip: Get the cell network IP address of an Android device. - diff --git a/aliases/mobile_device_management-android/network_management/local-network-network-management.aliases b/aliases/mobile_device_management-android/network_management/local-network-network-management.aliases deleted file mode 100644 index 0b52ff65..00000000 --- a/aliases/mobile_device_management-android/network_management/local-network-network-management.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# local-network-network-management.aliases -# -# Description: -# Android local network network management aliases -# - -alias androidwlanip="adb shell ip -f inet addr show wlan0|sed -n '2{p;q}'|tr -s ' '|awk -F'[/ ]' '{print \$3}'" # androidwlanip: Get the WLAN IP address of an Android device (if not working, replace "wlan0" with "eth0" or "tiwlan0"). - diff --git a/aliases/network_management-output_only/README.md b/aliases/network_management-output_only/README.md deleted file mode 100644 index e5124931..00000000 --- a/aliases/network_management-output_only/README.md +++ /dev/null @@ -1,16 +0,0 @@ - -# Network management - output only - -## Internet information - -* [Internet IP information retrieval aliases](internet_information/internet-ip-information-retrieval.aliases) - -## SSH information - -* [SSH tunnel information retrieval aliases](ssh_information/ssh-tunnel-information-retrieval.aliases) -* [SSH TCP information retrieval aliases](ssh_information/ssh-tcp-information-retrieval.aliases) - -## TCP and UDP information - -* [TCP and UDP port information retrieval aliases](tcp_and_udp_information/tcp-and-udp-port-information-retrieval.aliases) - diff --git a/aliases/network_management-output_only/internet_information/internet-ip-information-retrieval.aliases b/aliases/network_management-output_only/internet_information/internet-ip-information-retrieval.aliases deleted file mode 100644 index 8e30bd7f..00000000 --- a/aliases/network_management-output_only/internet_information/internet-ip-information-retrieval.aliases +++ /dev/null @@ -1,11 +0,0 @@ -# -# File: -# internet-ip-information-retrieval.aliases -# -# Description: -# Internet IP information retrieval aliases -# - -alias myip='curl ipecho.net/plain; echo' # myip: Get the public IPv4 address. -alias myiploc='curl ipinfo.io' # myiploc: Get the public IPv4 address with location information. - diff --git a/aliases/network_management-output_only/ssh_information/ssh-tcp-information-retrieval.aliases b/aliases/network_management-output_only/ssh_information/ssh-tcp-information-retrieval.aliases deleted file mode 100644 index bf711abd..00000000 --- a/aliases/network_management-output_only/ssh_information/ssh-tcp-information-retrieval.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# ssh-tcp-information-retrieval.aliases -# -# Description: -# SSH TCP information retrieval aliases -# - -alias sshlistports='ss -tnlp' # sshlistports: List the ports listening for a SSH connection. - diff --git a/aliases/network_management-output_only/ssh_information/ssh-tunnel-information-retrieval.aliases b/aliases/network_management-output_only/ssh_information/ssh-tunnel-information-retrieval.aliases deleted file mode 100644 index b39729b1..00000000 --- a/aliases/network_management-output_only/ssh_information/ssh-tunnel-information-retrieval.aliases +++ /dev/null @@ -1,11 +0,0 @@ -# -# File: -# ssh-tunnel-information-retrieval.aliases -# -# Description: -# SSH tunnel information retrieval aliases -# - -alias sshtunn='sudo lsof -i -n | egrep \' # sshtunn: List all tunnels created by the SSH daemon. -alias sshconntunn='sudo lsof -i -n | egrep \' # sshconntunn: List all tunnels connected to the SSH daemon. - diff --git a/aliases/network_management-output_only/tcp_and_udp_information/tcp-and-udp-port-information-retrieval.aliases b/aliases/network_management-output_only/tcp_and_udp_information/tcp-and-udp-port-information-retrieval.aliases deleted file mode 100644 index 3abd36f0..00000000 --- a/aliases/network_management-output_only/tcp_and_udp_information/tcp-and-udp-port-information-retrieval.aliases +++ /dev/null @@ -1,12 +0,0 @@ -# -# File: -# tcp-and-udp-port-information-retrieval.aliases -# -# Description: -# TCP and UDP port information retrieval aliases -# - -alias openports='sudo ss -antu' # openports: List all open TCP and UDP ports. -alias openportspids='sudo lsof -i -P' # openportspids: List all open ports with their PIDs. -alias listnports='sudo ss -lntu' # listnports: List all listening ports. - diff --git a/aliases/network_management/README.md b/aliases/network_management/README.md deleted file mode 100644 index aed0371f..00000000 --- a/aliases/network_management/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Network management - -## Internet - -* [Internet DNS management aliases](internet/internet-dns-management.aliases) - diff --git a/aliases/network_management/internet/internet-dns-management.aliases b/aliases/network_management/internet/internet-dns-management.aliases deleted file mode 100644 index 9c39b8cb..00000000 --- a/aliases/network_management/internet/internet-dns-management.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# internet-dns-management.aliases -# -# Description: -# Internet DNS management aliases -# - -alias flushdns='dscacheutil -flushcache' # flushdns: Flush the DNS Cache. - diff --git a/aliases/number_processing/README.md b/aliases/number_processing/README.md deleted file mode 100644 index 063c47ff..00000000 --- a/aliases/number_processing/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Number processing - -## Conversion - -* [Base conversion aliases](conversion/base-conversion.aliases) - diff --git a/aliases/number_processing/conversion/base-conversion.aliases b/aliases/number_processing/conversion/base-conversion.aliases deleted file mode 100644 index 10581704..00000000 --- a/aliases/number_processing/conversion/base-conversion.aliases +++ /dev/null @@ -1,11 +0,0 @@ -# -# File: -# base-conversion.aliases -# -# Description: -# Base conversion aliases -# - -hextodec() { local hexFrmtd="${1#*'0x'}"; echo "$((16#"${hexFrmtd}"))"; } # hextodec: Convert a hexidecimal number to decimal. -dectohex() { printf '%#010x\n' "${1}"; } # dectohex: Convert a decimal number to hexidecimal. - diff --git a/aliases/system_management-output_only/README.md b/aliases/system_management-output_only/README.md deleted file mode 100644 index 6cb9fa16..00000000 --- a/aliases/system_management-output_only/README.md +++ /dev/null @@ -1,8 +0,0 @@ - -# System management - output only - -## Process information - -* [Process general information retrieval aliases](process_information/process-general-information-retrieval.aliases) -* [Process search information retrieval aliases](process_information/process-search-information-retrieval.aliases) - diff --git a/aliases/system_management-output_only/process_information/process-general-information-retrieval.aliases b/aliases/system_management-output_only/process_information/process-general-information-retrieval.aliases deleted file mode 100644 index afc101c3..00000000 --- a/aliases/system_management-output_only/process_information/process-general-information-retrieval.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# process-general-information-retrieval.aliases -# -# Description: -# Process general information retrieval aliases -# - -owndprocs() { ps -u "${USER}" -o pid; } # owndprocs: List all processes owned by the current user. - diff --git a/aliases/system_management-output_only/process_information/process-search-information-retrieval.aliases b/aliases/system_management-output_only/process_information/process-search-information-retrieval.aliases deleted file mode 100644 index 4d878f3e..00000000 --- a/aliases/system_management-output_only/process_information/process-search-information-retrieval.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# process-search-information-retrieval.aliases -# -# Description: -# Process search information retrieval aliases -# - -getprocidbyname() { lsof -t -c "${@}" 2>/dev/null; } # getprocidbyname: Get the ID of a process by name; $1: process name (e.g. "/d$/" to get PIDs for processes ending in "d"). - diff --git a/aliases/text_processing/README.md b/aliases/text_processing/README.md deleted file mode 100644 index 0b8015bc..00000000 --- a/aliases/text_processing/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Text processing - -## Numeric processing - -* [Basic numberic processing aliases](numeric_processing/basic-numberic-processing.aliases) - diff --git a/aliases/text_processing/numeric_processing/basic-numberic-processing.aliases b/aliases/text_processing/numeric_processing/basic-numberic-processing.aliases deleted file mode 100644 index fd8db6fa..00000000 --- a/aliases/text_processing/numeric_processing/basic-numberic-processing.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# basic-numberic-processing.aliases -# -# Description: -# Basic numberic processing aliases -# - -countchars() { echo "${@}" | wc -c; } # countchars: Count the number of characters in a string. - diff --git a/aliases/x11_management-output_only/README.md b/aliases/x11_management-output_only/README.md deleted file mode 100644 index 82e564f6..00000000 --- a/aliases/x11_management-output_only/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# X11 management - output only - -## Event monitoring - -* [Input event monitoring](event_monitoring/input-event-monitoring.aliases) - diff --git a/aliases/x11_management-output_only/event_monitoring/input-event-monitoring.aliases b/aliases/x11_management-output_only/event_monitoring/input-event-monitoring.aliases deleted file mode 100644 index 551a644c..00000000 --- a/aliases/x11_management-output_only/event_monitoring/input-event-monitoring.aliases +++ /dev/null @@ -1,10 +0,0 @@ -# -# File: -# input-event-monitoring.aliases -# -# Description: -# Input event monitoring aliases -# - -alias watchmousepos='watch -t -n 0.0001 xdotool getmouselocation' # watchmousepos: Watch and print the current mouse position. - diff --git a/cf-gpc-view-aliases.sh b/cf-gpc-view-aliases.sh new file mode 100755 index 00000000..92ce7654 --- /dev/null +++ b/cf-gpc-view-aliases.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# File: +# cf-glsu-view-aliases.sh +# +# Description: +# View all aliases and short functions in +# computingfoundation/gnu-linux-shell-scripting. +# +# Usage note: +# Cd to directory "aliases" and run. +# + +if [ "$(echo "$PWD" | sed 's/.*\///')" != 'aliases' ]; then + echo 'cf-glsu-view-aliases.sh: not in directory "aliases"' + exit 1 +fi + +for filePath in $(find . -type f -name '*.aliases*'); do + basePath="$(echo "${filePath}" | awk -F\/ '{print $(NF-2)}')" + + if [ "${basePath}" != "${prevBasePath}" ]; then + echo '============================================' + echo -e " ${basePath}/" + echo -e '============================================\n' + fi + prevBasePath="${basePath}" + + fileBasePath="$(echo "${filePath}" | awk -F\/ '{print $(NF-1),$(NF)}' | sed \ + 's/ /\//')" + echo -e "----- ${fileBasePath}" + tail -n +8 "${filePath}" +done + diff --git a/cf-gpc-view-functions-scripts.sh b/cf-gpc-view-functions-scripts.sh new file mode 100755 index 00000000..62f45c55 --- /dev/null +++ b/cf-gpc-view-functions-scripts.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# File: +# cf-glsu-view-functions-scripts.sh +# +# Description: +# View all functions scripts in computingfoundation/gnu-linux-shell-scripting. +# +# Usage note: +# Cd to directory "functions_scripts" and run. +# + +if [ "$(echo "$PWD" | sed 's/.*\///')" != 'functions_scripts' ]; then + echo 'cf-glsu-view-functions-scripts.sh: not in directory "functions_scripts"' + exit 1 +fi + +for filePath in $(find . -type f ! -name '*.*' -o -name '*.bash'); do + basePath="$(echo "${filePath}" | awk -F\/ '{print $(NF-2)}')" + + if [ "${basePath}" != "${prevBasePath}" ]; then + echo '============================================' + echo -e " ${basePath}/" + echo -e '============================================\n' + fi + prevBasePath="${basePath}" + + fileBasePath="$(echo "${filePath}" | awk -F\/ '{print $(NF-1),$(NF)}' | \ + sed 's/ /\//')" + scriptDescription="$(cat "${filePath}" | \ + awk '/^(#[ ]Description)/ {for(i=1; i<=3; i++) {getline; print}; exit}' \ + | awk '{$1=""; print substr($0,2)}' | grep -Ev '^$|[:]')" + echo -e "----- ${fileBasePath}:\n${scriptDescription}\n" +done + diff --git a/cf-gpc-view-one-liners.sh b/cf-gpc-view-one-liners.sh new file mode 100755 index 00000000..4319c0d7 --- /dev/null +++ b/cf-gpc-view-one-liners.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# +# File: +# cf-glsu-view-one-liners.sh +# +# Description: +# View all one-liners in computingfoundation/gnu-linux-shell-scripting. +# +# Usage note: +# Cd to directory "one-liners" and run. +# + +if [ "$(echo "$PWD" | sed 's/.*\///')" != 'one-liners' ]; then + echo 'cf-glsu-view-one-liners.sh: not in directory "one-liners"' + exit 1 +fi + +for filePath in $(find . -type f -name '*.one-liners*'); do + basePath="$(echo "${filePath}" | awk -F\/ '{print $(NF-2)}')" + + if [ "${basePath}" != "${prevBasePath}" ]; then + echo '============================================' + echo -e " ${basePath}/" + echo -e '============================================\n' + fi + prevBasePath="${basePath}" + + fileBasePath="$(echo "${filePath}" | awk -F\/ '{print $(NF-1),$(NF)}' | sed \ + 's/ /\//')" + echo -e "----- ${fileBasePath}" + tail -n +8 "${filePath}" +done + diff --git a/cf-gpc-view-scripts.sh b/cf-gpc-view-scripts.sh new file mode 100755 index 00000000..06dab92e --- /dev/null +++ b/cf-gpc-view-scripts.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# File: +# cf-glsu-view-scripts.sh +# +# Description: +# View all scripts in computingfoundation/gnu-linux-shell-scripting. +# +# Usage note: +# Cd to directory "scripts" and run. +# + +if [ "$(echo "$PWD" | sed 's/.*\///')" != 'scripts' ]; then + echo 'cf-glsu-view-scripts.sh: not in directory "scripts"' + exit 1 +fi + +for filePath in $(find . -type f ! -name '*.*'); do + basePath="$(echo "${filePath}" | awk -F\/ '{print $(NF-2)}')" + + if [ "${basePath}" != "${prevBasePath}" ]; then + echo '============================================' + echo -e " ${basePath}/" + echo -e '============================================\n' + fi + prevBasePath="${basePath}" + + fileBasePath="$(echo "${filePath}" | awk -F\/ '{print $(NF-1),$(NF)}' | \ + sed 's/ /\//')" + scriptDescription="$(cat "${filePath}" | \ + awk '/^(#[ ]Description)/ {for(i=1; i<=3; i++) {getline; print}; exit}' \ + | awk '{$1=""; print substr($0,2)}' | grep -Ev '^$|[:]')" + echo -e "----- ${fileBasePath}:\n${scriptDescription}\n" +done + diff --git a/functions_scripts/README.md b/functions_scripts/README.md deleted file mode 100644 index 0732faba..00000000 --- a/functions_scripts/README.md +++ /dev/null @@ -1,17 +0,0 @@ - -# Functions scripts - -This directory contains functions scripts. - -Functions scripts are scripts consisting of small individual related functions. - -## View all - -To view all the solutions in this directory, change to it and run the following: - -```bash -git show-ref --verify -q refs/heads/helper_scripts || \ -git branch --track helper_scripts origin/helper_scripts; \ -bash <(git show helper_scripts:cf-gpc-view-functions-scripts.sh) -``` - diff --git a/functions_scripts/application_management/README.md b/functions_scripts/application_management/README.md deleted file mode 100644 index 062c01a0..00000000 --- a/functions_scripts/application_management/README.md +++ /dev/null @@ -1,8 +0,0 @@ - -# Application management - -## Database - -* [mongodbutils](database/mongodbutils): Generic MongoDB utility functions -* [mysqldbutils](database/mysqldbutils): Generic RDBMS utility functions for a MySQL database - diff --git a/functions_scripts/application_management/database/mongodbutils b/functions_scripts/application_management/database/mongodbutils deleted file mode 100755 index b0052e5f..00000000 --- a/functions_scripts/application_management/database/mongodbutils +++ /dev/null @@ -1,170 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# mongodbutils -# -# Description: -# Generic MongoDB utility functions -# -# Usage: -# mongodbutils [action_arguments] -# -# Options: -# -u The name of the database user -# -p The password of the database user -# - -if [ "$#" -lt 2 ]; then - echo -e 'mongodbutils: invalid number of arguments; database name\n and'\ - 'action required' 1>&2 - exit 1 -fi - -while getopts u:p: OPT; do - case "${OPT}" in - u) MONGO_AUTH_OPTS="-u ${OPTARG}" - ;; - p) MONGO_AUTH_OPTS+=" -p ${OPTARG}" - ;; - esac -done -shift $((OPTIND - 1)) - -readonly DB_NAME="${1}" -readonly ACTION="${2}" -shift 2 - -case "${ACTION}" in - # Action: - # import-collection - # Description: - # Import data to a collection from a JSON file. - # Usage: - # ... import-collection [collection_name] - # [collection_name]: name of collection to import; default is - # JSON file name - # Note: - # If needing to import multiple MongoDB documents in a single JSON array, - # append option "--jsonArray" to the end of the mongoimport command. - 'import-collection') - [ "$#" -eq 0 ] && \ - echo "mongodbutils: no directory specified" 1>&2 && \ - exit 1 - [ ! -f "${1}" ] && \ - echo "mongodbutils: cannot import: file \"${1}\" does not exist" && \ - exit 1 - - if [ "$#" -ge 2 ]; then - opts+="--collection ${2}" - fi - mongoimport --db "${DB_NAME}" ${MONGO_AUTH_OPTS} --file "${1}" ${opts} - ;; - - # Action: - # export-collection - # Description: - # Export data from a collection to a JSON file. - # Usage: - # ... export-collection [directory] - # : name of the collection to export - # [directory]: directory to output JSON file to; default - # is current - 'export-collection') - if [ "$#" -ge 1 ]; then - collName="${1}" - opts+="--collection ${collName}" - - if [ "$#" -ge 2 ]; then - opts+=" --out ${2}/${collName}.json" - else - opts+=" --out ${collName}.json" - fi - fi - mongoexport --db "${DB_NAME}" ${MONGO_AUTH_OPTS} ${opts} --jsonArray - ;; - - # Action: - # drop-collection - # Description: - # Drop a collection - # Usage: - # ... drop-collection - # : the name of the collection to drop - 'drop-collection') - [ "$#" -eq 0 ] && \ - echo "mongodbutils: no collection specified" 1>&2 && \ - exit 1 - mongo "${DB_NAME}" --eval "db.${1}.drop()" - ;; - - # Action: - # drop-database - # Description: - # Drop the database. - # Usage: - # ... drop-database - 'drop-database') - mongo "${DB_NAME}" --eval 'db.dropDatabase()' - ;; - - # Action: - # drop-all-databases - # Description: - # Drop all databases. - # Usage: - # ... drop-all-databases - 'drop-all-databases') - /usr/bin/mongo <<-EOF - db.getMongo().getDBNames().forEach(function(database) { - if (database != 'local' && database != 'admin') { - db = db.getMongo().getDB(database); - db.dropDatabase(); - print('dropped database ' + db.getName()); - } - }) - EOF - ;; - - # Action: - # dump - # Description: - # Dump the database to BSON files. - # Usage: - # ... dump [collection_name] [directory] - # [collection_name]: name of collection to dump; if no name is - # specified, all collections will be dumped - # [directory]: directory to output BSON files to; default - # is current - 'dump') - if [ "$#" -ge 1 ]; then - opts+="--collection ${1}" - if [ "$#" -ge 2 ]; then - opts=" --out ${2}" - fi - fi - mongodump --db "${DB_NAME}" ${MONGO_AUTH_OPTS} ${opts} - ;; - - # Action: - # restore - # Description: - # Restore data from one or more BSON files. - # Usage: - # ... restore - 'restore') - [ -z "${1}" ] && \ - echo "mongodbutils: no directory specified" 1>&2 && \ - exit 1 - [ ! -d "${1}" ] && \ - echo "mongodbutils: directory \"${1}\" does not exist" 1>&2 && \ - exit 1 - mongorestore ${MONGO_AUTH_OPTS} "${1}" - ;; - - *) - echo "mongodbutils: unknown action \"${ACTION}\"" 1>&2 - exit 1 - ;; - -esac - diff --git a/functions_scripts/application_management/database/mysqldbutils b/functions_scripts/application_management/database/mysqldbutils deleted file mode 100755 index 077098be..00000000 --- a/functions_scripts/application_management/database/mysqldbutils +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# mysqldbutils -# -# Description: -# Generic RDBMS utility functions for a MySQL database -# -# Usage: -# mysqldbutils -# - -if [ "$#" -lt 3 ]; then - echo -e 'mysqldbutils: invalid number of arguments; database user,\n'\ - ' database name and action required' 1>&2 - exit 1 -fi - -readonly DB_USER="${1}" -readonly DB_NAME="${2}" -readonly ACTION="${3}" -shift 3 - -case "${ACTION}" in - # Action: - # create_from_file - # Description: - # Create the database from an SQL file. - # Usage: - # ... create_from_file - 'create_from_file') - [ "$#" -eq 0 ] && \ - echo "mysqldbutils: no SQL file specified" 1>&2 && \ - exit 1 - [ ! -f "${1}" ] && \ - echo "mysqldbutils: file \"${1}\" not found" 1>&2 && \ - exit 1 - - mysql -u"${DB_USER}" -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME}" - if mysql -u"${DB_USER}" -e "use ${DB_NAME}" 2>/dev/null; then - bash "${0}" 'drop_all_tables' "${DB_USER}" "${DB_NAME}" - mysql -u"${DB_USER}" "${DB_NAME}" < "${1}" - else - echo "mysqldbutils: database \"${DB_NAME}\" not found" 1>&2 - fi - ;; - - # Action: - # drop_all_tables - # Description: - # Drop all tables in the database. - # Usage: - # ... drop_all_tables - 'drop_all_tables') - query=" - USE ${DB_NAME}; - SET FOREIGN_KEY_CHECKS = 0; - SET GROUP_CONCAT_MAX_LEN=32768; - SET @tables = NULL; - SELECT GROUP_CONCAT('\`', table_name, '\`') INTO @tables - FROM information_schema.tables - WHERE table_schema = (SELECT DATABASE()); - SELECT IFNULL(@tables,'dummy') INTO @tables; - - SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables); - PREPARE stmt FROM @tables; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - SET FOREIGN_KEY_CHECKS = 1; - " - mysql -u"${DB_USER}" -e "${query}" - ;; - - # Action: - # clear_all_tables - # Description: - # Clear all tables in the database. - # Usage: - # ... clear_all_tables - 'clear_all_tables') - mysqldump -d -u"${DB_USER}" --add-drop-table "${DB_NAME}" > \ - ./db_export_tmp.sql - mysql -u"${DB_USER}" "${DB_NAME}" < ./db_export_tmp.sql - rm ./db_export_tmp.sql - ;; - - # Action: - # export - # Description: - # Export the database. - # Usage: - # ... export - 'export') - mysqldump -u"${DB_USER}" "${DB_NAME}" > ./db_"${DB_NAME}"_export.sql - ;; - - *) - echo "mysqldbutils: unknown action \"${ACTION}\"" 1>&2 - ;; - -esac - diff --git a/functions_scripts/scripting/README.md b/functions_scripts/scripting/README.md deleted file mode 100644 index b7d6e4cc..00000000 --- a/functions_scripts/scripting/README.md +++ /dev/null @@ -1,17 +0,0 @@ - -# Scripting - -## Bash - -* [arrayutils.bash](bash/arrayutils.bash): Bash array utilities -* [coreutils.bash](bash/coreutils.bash): Bash core utilities -* [dateandtimeutils.bash](bash/dateandtimeutils.bash): Bash date and time utilities -* [fileanddirectoryutils.bash](bash/fileanddirectoryutils.bash): Bash file and directory utilities -* [httputils.bash](bash/httputils.bash): Bash http utilities -* [numberutils.bash](bash/numberutils.bash): Bash number utilities -* [stringutils.bash](bash/stringutils.bash): Bash string utilities - -### Usage Notes - -* Utility functions accept array arguments by reference. *(Therefore, arrays must be passed by name rather than value [e.g. an array X would be passed as "X" rather than "${X[@]}"]).* - diff --git a/functions_scripts/scripting/bash/arrayutils.bash b/functions_scripts/scripting/bash/arrayutils.bash deleted file mode 100644 index 627c1b23..00000000 --- a/functions_scripts/scripting/bash/arrayutils.bash +++ /dev/null @@ -1,268 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# arrayutils.bash -# -# Description: -# Bash array utilities -# - -# ============================================ -# Validation -# ============================================ - -# Usage: -# arrayContainsValue -arrayContainsValue() { - local arr="${2}[@]" - arr=("${!arr}") - for arrVal in "${arr[@]}"; do [ "${1}" = "${arrVal}" ] && \ - return 0; done - return 1 -} - -# Usage: -# arrayContainsKey -arrayContainsKey() { - local arr="${2}[@]" - arr=("${!arr}") - for arrKey in "${!arr[@]}"; do [ "${1}" = "${arrKey}" ] && \ - return 0; done - return 1 -} - -# Check if a value matches an array regex value. -# Usage: -# arrayContainsValueByRegex -arrayContainsValueByRegex() { - local arr="${2}[@]" - arr=("${!arr}") - for arrVal in "${arr[@]}"; do [[ "${arrVal}" =~ ${1} ]] && \ - return 0; done - return 1 -} - -# Check if array contains a value that is a prefix for the given value. -# Usage: -# arrayContainsPrefixForValue -arrayContainsPrefixForValue() { - local arr="${2}[@]" - arr=("${!arr}") - for arrVal in "${arr[@]}"; do [[ "${1}" = "${arrVal}"* ]] && \ - return 0; done - return 1 -} - -# ============================================ -# Getters -# ============================================ - -# Get a value from an array -# Usage: -# getArrayValue -getArrayValue() { - local arr="${2}[@]" - arr=("${!arr}") - for arrVal in "${arr[@]}"; do [ "${arrVal}" = "${1}" ] && \ - echo "${arrVal}" && break; done -} - -# Get the position of an array element matching a value. -# Usage: -# getPositionOfArrayElement -getPositionOfArrayElement() { - local arr="${2}[@]" - arr=("${!arr}") - for indx in ${!arr[@]}; do [ "${arr[${indx}]}" = "${1}" ] && \ - echo "${indx}" && break; done -} - -# Get the first value in the array that contains the given string. -# Usage: -# getFirstArrayValueContainingString -getFirstArrayValueContainingString() { - local arr="${2}[@]" - arr=("${!arr}") - for arrVal in "${arr[@]}"; do [[ "${1}" = *"${arrVal}"* ]] && \ - echo "${arrVal}" && break; done -} - -# ============================================ -# Manipulation -# ============================================ - -# Usage: -# removeElementFromArray -removeElementFromArray() { - local arr="${2}[@]" - arr=("${!arr}") - local indx=0 - for arrVal in "${arr[@]}"; do - [ "${arrVal}" = "${1}" ] && \ - arr=("${arr[@]:0:${indx}} ${arr[@]:$((${indx} + 1))}") && \ - break - ((indx++)) - done - echo "${arr[@]}" -} - -# Usage: -# removeDuplicatesFromArray -removeDuplicatesFromArray() { - local arr="${1}[@]" - arr=("${!arr}") - local retArr - for arrVal in "${arr[@]}"; do - local has=0 - for retArrVal in "${retArr[@]}"; do - [ "${retArrVal}" = "${arrVal}" ] && has=1 && break; done - [ ${has} -eq 0 ] && retArr+=("${arrVal}") - done - echo "${retArr[@]}" -} - -# ============================================ -# Sets -# ============================================ - -# Get the intersection of two arrays. -# Example: -# A=(1 3 9 2 7); B=(2 5 3 7 5) -# getIntersection A B # returns "3 2 7" -getIntersection() { - local arr1="${1}[@]" - local arr2="${2}[@]" - arr1=(${!arr1}) - arr2=(${!arr2}) - local retArr - for arr1Val in "${arr1[@]}"; do - for arr2Val in "${arr2[@]}"; do - if [ "${arr2Val}" = "${arr1Val}" ]; then - local has=0 - for retArrVal in "${retArr[@]}"; do - [ "${retArrVal}" = "${arr1Val}" ] && has=1 && break; done - [ ${has} -eq 0 ] && retArr+=("${arr1Val}") - fi - done - done - echo "${retArr[@]}" -} - -# Get the union of two arrays. -# Example: -# A=(5 7 1 1 4); B=(3 1 4 1 9) -# getUnion A B # returns "5 7 1 4 3 9" -getUnion() { - local arr1="${1}[@]" - local arr2="${2}[@]" - arr1=(${!arr1}) - arr2=(${!arr2}) - local retArr - for arr1Val in "${arr1[@]}"; do - local has=0 - for retArrVal in "${retArr[@]}"; do - [ "${retArrVal}" = "${arr1Val}" ] && has=1 && break; done - [ ${has} -eq 0 ] && retArr+=("${arr1Val}") - done - for arr2Val in "${arr2[@]}"; do - local has=0 - for retArrVal in "${retArr[@]}"; do - [ "${retArrVal}" = "${arr2Val}" ] && has=1 && break; done - [ ${has} -eq 0 ] && retArr+=("${arr2Val}") - done - echo "${retArr[@]}" -} - -# Get the union of two arrays (2). -# Example: -# A=(5 7 1 1 4); B=(3 1 4 1 9) -# getUnion2 A B # returns "5 7 3 1 4 9" -getUnion2() { - local arr1="${1}[@]" - local arr2="${2}[@]" - arr1=(${!arr1}) - arr2=(${!arr2}) - local unionArr - local i=0 j=0 - while [[ ${i} -lt ${#arr1[@]} && ${j} -lt ${#arr2[@]} ]]; do - if [[ "${arr1[${i}]}" > "${arr2[${j}]}" ]]; then - unionArr+=("${arr1[$((i++))]}") - elif [[ "${arr1[${i}]}" < "${arr2[${j}]}" ]]; then - unionArr+=("${arr2[$((j++))]}") - else - unionArr+=("${arr1[$((i++))]}") - ((j++)) - fi - done - while [ ${i} -lt ${#arr1[@]} ]; do unionArr+=("${arr1[$((i++))]}"); done - while [ ${j} -lt ${#arr2[@]} ]; do unionArr+=("${arr2[$((j++))]}"); done - local unionNoDuplctsArr - for unionArrVal in "${unionArr[@]}"; do - local has=0 - for unionNoDuplctsArrVal in "${unionNoDuplctsArr[@]}"; do - [ "${unionNoDuplctsArrVal}" = "${unionArrVal}" ] && has=1 && break - done - [ ${has} -eq 0 ] && unionNoDuplctsArr+=("${unionArrVal}") - done - echo "${unionNoDuplctsArr[@]}" -} - -# Get the difference between array 1 and array 2 (i.e. elements in array 1 -# that are not in array 2). -# Example: -# A=(3 6 2 1 5 1 1); B=(2 4 6) -# getDifference A B # returns "3 1 5" -getDifference() { - local arr1="${1}[@]" - local arr2="${2}[@]" - arr1=(${!arr1}) - arr2=(${!arr2}) - local retArr - for arr1Val in "${arr1[@]}"; do - local has=0 - for retArrVal in "${retArr[@]}"; do - [ "${retArrVal}" = "${arr1Val}" ] && has=1 && break; done - [ ${has} -eq 0 ] && for arr2Val in "${arr2[@]}"; do - [ "${arr2Val}" = "${arr1Val}" ] && has=1 && break; done - [ ${has} -eq 0 ] && retArr+=("${arr1Val}") - done - echo "${retArr[@]}" -} - -# ============================================ -# Parsing -# ============================================ - -# Join the elements of an array by a delimiter. -# Usage: -# joinArrayBy -joinArrayBy() { - local delim="${1}" - local arr="${2}[@]" - arr=("${!arr}") - joined="$(printf "%s" "${arr[@]/#/$delim}")" - echo "${joined#${delim}}" -} - -# ============================================ -# Other -# ============================================ - -# Create pairs between array 1 and array 2. -# Example: -# A=(0 12); B=(4 5) -# createPairs A B # returns "0:4 0:5 12:4 12:5" -createPairs() { - local arr1="${1}[@]" - local arr2="${2}[@]" - arr1=(${!arr1}) - arr2=(${!arr2}) - local retArr - for arr1Val in ${arr1[@]}; do - for arr2Val in ${arr2[@]}; do - local retArr+=("${arr1Val}:${arr2Val}") - done - done - echo "${retArr[@]}" -} - diff --git a/functions_scripts/scripting/bash/coreutils.bash b/functions_scripts/scripting/bash/coreutils.bash deleted file mode 100644 index a65008a8..00000000 --- a/functions_scripts/scripting/bash/coreutils.bash +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# coreutils.bash -# -# Description: -# Bash core utilities -# - -# ============================================ -# Options and arguments -# ============================================ - -# Extract all options and their arguments from a command. -# Usage: -# extractOptions -# Note: -# Option arguments are extracted for all options except the last. -extractOptions() { - local arr=(${@}) - if [[ "${arr[0]}" = '-'* ]]; then - local opts="${arr[0]} " - for ((x=1; x<=${#arr[@]}; x++)); do - if [[ "${arr[@]:x:1}" = '-'* ]]; then opts+="${arr[@]:x:1} " - elif [[ "${arr[@]:((x+1)):1}" = '-'* ]]; then opts+="${arr[@]:x:1} " - else break - fi - done - fi - echo "${opts}" -} - diff --git a/functions_scripts/scripting/bash/dateandtimeutils.bash b/functions_scripts/scripting/bash/dateandtimeutils.bash deleted file mode 100644 index c8f75fcb..00000000 --- a/functions_scripts/scripting/bash/dateandtimeutils.bash +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# dateandtimeutils.bash -# -# Description: -# Bash date and time utilities -# - -# ============================================ -# Conversion -# ============================================ - -# Convert seconds to milliseconds with decimal precision. -# Usage: -# secondsToMillisecondsDecimal -secondsToMillisecondsDecimal() { - printf '%.4f' "$(bc <<< "${1}*1000")" -} - -# Convert seconds to milliseconds. -# Usage: -# secondsToMilliseconds -# Notes: -# The number is rounded to the nearest tenths place using half toward zero -# rounding mode. -secondsToMilliseconds() { - printf '%.0f' "$(secondsToMillisecondsDecimal "${1}")" -} - -# Convert seconds to microseconds with decimal precision. -# Usage: -# secondsToMicrosecondsDecimal -secondsToMicrosecondsDecimal() { - printf '%.4f' "$(bc <<< "${1}*1000000")" -} - -# Convert seconds to microseconds. -# Usage: -# secondsToMicroseconds -# Notes: -# The number is rounded to the nearest tenths place using half toward zero -# rounding mode. -secondsToMicroseconds() { - printf '%.0f' "$(secondsToMicrosecondsDecimal "${1}")" -} - diff --git a/functions_scripts/scripting/bash/fileanddirectoryutils.bash b/functions_scripts/scripting/bash/fileanddirectoryutils.bash deleted file mode 100644 index aff1b2c6..00000000 --- a/functions_scripts/scripting/bash/fileanddirectoryutils.bash +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# fileanddirectoryutils.bash -# -# Description: -# Bash file and directory utilities -# - -# ============================================ -# Extraction -# ============================================ - -# Extract a the extension from a file name using a best guess method: get all -# text after the last or second to last dot if it exists. -# Usage: -# extractFileExtension -extractFileExtension() { - if [[ "${1}" = *'.'* ]]; then - local fileName="${1%.*}" ext="${1##*.}" - [[ "${fileName}" = *'.'* ]] && ext="${fileName##*.}.${ext}" - echo "${ext}" - fi -} - -# ============================================ -# Other -# ============================================ - -# Return the next number incremented file name. -# Examples: -# # if "mbg.txt" already exists -# getIncrementedFileName mbg.txt # returns mbg2.txt -# # if "mbg.txt", "./mbg5.txt" and "./mbg17.txt" already exist -# getIncrementedFileName mbg.txt # returns mbg18.txt -# Usage: -# getIncrementedFileName [directory_to_search_in] -# [directory_to_search_in]: default is current -# Options: -# -d use directories instead of files -getIncrementedFileName() { - local OPT OPTIND - getopts :d OPT - shift $((OPTIND-1)) - local FIND_TYPE='f' - if [ "${OPT}" = 'd' ]; then - FIND_TYPE='d' - fi - local fileName="${1}" - [ "$#" -ge 2 ] && local DIR="${2}" || local DIR='.' - local FILE_EXT="$(extractFileExtension "${fileName}")" - [ -n "${FILE_EXT}" ] && FILE_EXT=".${FILE_EXT}" - local FILE_BASE_NAME="${1%${FILE_EXT}*}" - - local foundFiles=($(find "${DIR}" -maxdepth 1 -type "${FIND_TYPE}" \ - -regextype posix-awk -regex ".*/${FILE_BASE_NAME}[0-9]*${FILE_EXT}")) - if [ "${#foundFiles[@]}" -gt 0 ]; then - local fileNum=1 - for foundFile in "${foundFiles[@]}"; do - local foundFile="${foundFile##*/}" - local foundFileBaseName="${foundFile%${FILE_EXT}*}" - local foundFileNum="$(echo "${foundFileBaseName}" | sed -e \ - 's/[^0-9]//g')" - if [ -n "${foundFileNum}" ]; then - # If using directory names, DOS line endings must be removed for - # foundFileNum or arithmetic operations will result in a syntax error. - # Note: using "${foundFileNum//$'\r'/}" and other operations do not - # work. - [[ "${foundFileNum}" =~ [0-9]* ]] && foundFileNum="${BASH_REMATCH[0]}" - if [ "${foundFileNum}" -gt "${fileNum}" ]; then - fileNum="${foundFileNum}" - fi - fi - done - fileName="${FILE_BASE_NAME}-$((fileNum + 1))${FILE_EXT}" - fi - echo "${fileName}" -} - diff --git a/functions_scripts/scripting/bash/httputils.bash b/functions_scripts/scripting/bash/httputils.bash deleted file mode 100644 index f422ed2b..00000000 --- a/functions_scripts/scripting/bash/httputils.bash +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# httputils.bash -# -# Description: -# Bash HTTP utilities -# - -# Note: This regex only ensures URL safe characters. -URL_REGEX='[-A-Za-z0-9+&@#\/%?=~_|!:,.;]*[-A-Za-z0-9+&@#\/%=~_|]' - -PROTOCOLS_REGEX='https?|ftp|file' - -# ============================================ -# Validation -# ============================================ - -# Check if a string is a valid URL. -# Usage: -# isUrl -# Options: -# -p check that the string contains one of the protocols in -# PROTOCOLS_REGEX; if not used, the string is validated only with -# URL_REGEX. -isUrl() { - local OPT OPTIND - getopts :p OPT - shift $((OPTIND-1)) - [ "${OPT}" = 'p' ] && local urlRegex="((${PROTOCOLS_REGEX})://)" - local urlRegex+="${URL_REGEX}$" - urlRegex="^${urlRegex}" - [[ "${1}" =~ ${urlRegex} ]] && return 0 || return 1 -} - -# Check if a string is a valid website URL. -# Usage: -# isWebsiteUrl -# Options: -# -p check that the string contains the "http[s]://" protocol prefix; if -# not used, it is only validated with URL_REGEX and checked to begin -# with "www." and contain a dot (and not at the beginning or end). -isWebsiteUrl() { - local OPT OPTIND - getopts :p OPT - shift $((OPTIND-1)) - [ "${OPT}" = 'p' ] && local urlRegex="(https?://)" - local urlRegex+="(www\.)" - urlRegex="^${urlRegex}" - # comment the following assignment statement to not check if the URL - # contains a dot - urlRegex+="[-A-Za-z0-9+&@#\/%?=~_|!:,;]+[.]" - urlRegex+="${URL_REGEX}$" - [[ "${1}" =~ ${urlRegex} ]] && return 0 || return 1 -} - diff --git a/functions_scripts/scripting/bash/numberutils.bash b/functions_scripts/scripting/bash/numberutils.bash deleted file mode 100644 index e73ddb51..00000000 --- a/functions_scripts/scripting/bash/numberutils.bash +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# numberutils.bash -# -# Description: -# Bash number utilities -# - -# ============================================ -# Validation -# ============================================ - -# Determine if a number is in range between and (inclusive). -# Usage: -# isNumberInRange -isNumberInRange() { - [ "$#" -ne 3 ] && return 1 - [[ "${1}" =~ ^[0-9]+$ && "${2}" =~ ^[0-9]+$ && "${3}" =~ ^[0-9]+$ ]] || \ - return 1 - [ "${2}" -gt "${3}" ] && return 1 - [[ "${1}" -lt "${2}" || "${1}" -gt "${3}" ]] && return 0 || return 1 -} - -# ============================================ -# Value generation -# ============================================ - -# Generate a random number between and (inclusive). -# Usage: -# generateRandomNumber -generateRandomNumber() { - [ "$#" -ne 2 ] && return 1 - [[ "${1}" =~ ^[0-9]+$ && "${2}" =~ ^[0-9]+$ ]] || return 1 - [ "${1}" -gt "${2}" ] && return 1 - printf '%s' $(( ( RANDOM % ( "${2}" - "${1}" + 1 ) + "${1}" ))) -} - -# Generate a random decimal between ".00" and ".99". -# Usage: -# generateRandomDecimal -function generateRandomDecimal { - [ "$#" -ne 2 ] && return 1 - [[ "${1}" =~ ^[0-9]+\.[0-9]+$ && "${2}" =~ ^[0-9]+\.[0-9]+$ ]] || return 1 - out=$(bc <<< "scale=2; $(printf '0.%02d' $(( $RANDOM % 100))) / 2") - if [ "${out}" = '0' ]; then out='.00'; fi - printf '%s' "${out}" -} - - - -# -------------------------------------------- -# REFERENCE -# -------------------------------------------- -# -# ============================================ -# Validation -# ============================================ -# -# # Determine if the given value is a number. -# # Usage: -# # isNumber -# isNumber() { -# [[ "${1}" =~ ^[0-9]+$ ]] && return 0 || return 1 -# } -# -# # Usage: -# # isNumberOrDecimal -# isNumberOrDecimal() { -# [[ "${1}" =~ ^[0-9]*(\.[0-9]+)?$ ]] && return 0 || return 1 -# } -# - diff --git a/functions_scripts/scripting/bash/stringutils.bash b/functions_scripts/scripting/bash/stringutils.bash deleted file mode 100644 index 43d01df3..00000000 --- a/functions_scripts/scripting/bash/stringutils.bash +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# stringutils.bash -# -# Description: -# Bash string utilities -# - -# ============================================ -# General -# ============================================ - -# Repeat the given text N number of times. -# Usage: -# repeatText -# Options: -# -m --max max repeat count -repeatText() { - if [[ "${1}" = '-m' || "${1}" = '--max' ]]; then - if [[ "${2}" =~ ^[0-9]+$ ]]; then - local RPT_COUNT_MAX="${2}" - shift 2 - else - echo "repeatText: value for option ${1} must be a number" - return 1 - fi - fi - if [ "$#" -eq 2 ]; then - if [[ "${2}" =~ ^[0-9]+$ && "${2}" -gt 0 ]]; then - local reptCount="${2}" - if [[ -n "${RPT_COUNT_MAX}" && "${RPT_COUNT_MAX}" -ge 0 ]]; then - [ "${reptCount}" -gt "${RPT_COUNT_MAX}" ] && \ - reptCount="${RPT_COUNT_MAX}" - fi - for i in $(seq 1 "${reptCount}"); do - local retText+="${1}" - done - fi - elif [ "$#" -eq 1 ]; then - retText="${1}" - fi - echo "${retText}" -} - -# Prepend the given prefix to all delimited substrings in the full string. -# Example: -# prependToSubstrings "semicolon;is;the;delimiter" ';' '&&' -# # returns "&&semicolon;&&is;&&the;&&delimiter" -# Usage: -# repeatText -prependToSubstrings() { - [ "$#" -ne 3 ] && echo "${1}" && return 1 - IFS="${2}"; for str in ${1}; do - local retText+="${3}${str}${2}"; done; unset IFS - [ ! "${1: -1}" = "${2}" ] && retText="${retText%${2}}" - echo "${retText}" -} - diff --git a/one-liners/README.md b/one-liners/README.md deleted file mode 100644 index dcf37da4..00000000 --- a/one-liners/README.md +++ /dev/null @@ -1,15 +0,0 @@ - -# One-liners - -This directory contains one-liners. - -## View all - -To view all the solutions in this directory, change to it and run the following: - -```bash -git show-ref --verify -q refs/heads/helper_scripts || \ -git branch --track helper_scripts origin/helper_scripts; \ -bash <(git show helper_scripts:cf-gpc-view-one-liners.sh) -``` - diff --git a/one-liners/application_management/README.md b/one-liners/application_management/README.md deleted file mode 100644 index c89c4296..00000000 --- a/one-liners/application_management/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Application management - -## Database - -* [PostgreSQL database one-liners](database/postgresql-database.one-liners) - diff --git a/one-liners/application_management/database/postgresql-database.one-liners b/one-liners/application_management/database/postgresql-database.one-liners deleted file mode 100644 index 55348233..00000000 --- a/one-liners/application_management/database/postgresql-database.one-liners +++ /dev/null @@ -1,11 +0,0 @@ -# -# File: -# postgresql-database.one-liners -# -# Description: -# PostgreSQL database one-liners -# - -# Check if a PostgreSQL database exists. -psql -lqt | cut -d \| -f 1 | grep -qw - diff --git a/one-liners/file_management-output_only/README.md b/one-liners/file_management-output_only/README.md deleted file mode 100644 index 49cfb1df..00000000 --- a/one-liners/file_management-output_only/README.md +++ /dev/null @@ -1,12 +0,0 @@ - -# File management - output only - -## File finding - -* [File finding with output manipulation one-liners](file_finding/file-finding-with-output-manipulation.one-liners) -* [Name specific file finding one-liners](file_finding/name-specific-file-finding.one-liners) - -## File information - -* [File property information retrieval one-liners](file_information/file-property-information-retrieval.one-liners) - diff --git a/one-liners/file_management-output_only/file_finding/file-finding-with-output-manipulation.one-liners b/one-liners/file_management-output_only/file_finding/file-finding-with-output-manipulation.one-liners deleted file mode 100644 index b6cde0ef..00000000 --- a/one-liners/file_management-output_only/file_finding/file-finding-with-output-manipulation.one-liners +++ /dev/null @@ -1,18 +0,0 @@ -# -# File: -# file-finding-with-output-manipulation.one-liners -# -# Description: -# File finding with output manipulation one-liners -# - -GENERAL OUTPUT MANIPULATION: - -# Recursively find all files and print their names without their paths. -find . -type f -printf '%f\n' - -COMMON SPECIAL OUTPUT MANIPULATION: - -# Recursively find all directories containing executables files and separate them by a colon. -find . -type f -executable -printf '%h\n'|sort|uniq|tr '\n' ':' - diff --git a/one-liners/file_management-output_only/file_finding/name-specific-file-finding.one-liners b/one-liners/file_management-output_only/file_finding/name-specific-file-finding.one-liners deleted file mode 100644 index d9c4283d..00000000 --- a/one-liners/file_management-output_only/file_finding/name-specific-file-finding.one-liners +++ /dev/null @@ -1,21 +0,0 @@ -# -# File: -# name-specific-file-finding.one-liners -# -# Description: -# Name specific file finding one-liners -# - -HIDDEN AND NON-HIDDEN FILES: - -# Recursively find all non-hidden files. -find . -type f ! -name '.*' - -# Recursively find all files not in a hidden directory. -find . -not -path '*/\.*' -type f - -CONTAINING/NOT CONTAINING STRING: - -# Recursively find all files without a dot (".") in their name. -find . -type f ! -name "*.*" - diff --git a/one-liners/file_management-output_only/file_information/file-property-information-retrieval.one-liners b/one-liners/file_management-output_only/file_information/file-property-information-retrieval.one-liners deleted file mode 100644 index 56f98717..00000000 --- a/one-liners/file_management-output_only/file_information/file-property-information-retrieval.one-liners +++ /dev/null @@ -1,11 +0,0 @@ -# -# File: -# file-property-information-retrieval.one-liners -# -# Description: -# File property information retrieval one-liners -# - -# Get the size in megabytes of one or more files and/or directories. -du -csm | tail -1 | awk '{ print $1 }' - diff --git a/one-liners/hardware_management-output_only/README.md b/one-liners/hardware_management-output_only/README.md deleted file mode 100644 index 9760d3d4..00000000 --- a/one-liners/hardware_management-output_only/README.md +++ /dev/null @@ -1,15 +0,0 @@ - -# Hardware management - output only - -## CPU information - -* [CPU property information retrieval one-liners](cpu_information/cpu-property-information-retrieval.one-liners) - -## Monitor information - -* [Monitor status information retrieval one-liners](monitor_information/monitor-status-information-retrieval.one-liners) - -## *Notes* - -* Hardware management one-liners are intended to be distribution-independent, however, some may not work for certain distributions. - diff --git a/one-liners/hardware_management-output_only/SOURCES.txt b/one-liners/hardware_management-output_only/SOURCES.txt deleted file mode 100644 index 0019116b..00000000 --- a/one-liners/hardware_management-output_only/SOURCES.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Sources for Hardware management - output only one-liners - -monitor_information/monitor-status-information-retrieval.one-liners: - - Get the maximum backlight level: - https://wiki.archlinux.org/index.php/backlight#ACPI - diff --git a/one-liners/hardware_management-output_only/cpu_information/cpu-property-information-retrieval.one-liners b/one-liners/hardware_management-output_only/cpu_information/cpu-property-information-retrieval.one-liners deleted file mode 100644 index f2fbd3f5..00000000 --- a/one-liners/hardware_management-output_only/cpu_information/cpu-property-information-retrieval.one-liners +++ /dev/null @@ -1,23 +0,0 @@ -# -# File: -# cpu-property-information-retrieval.one-liners -# -# Description: -# CPU property information retrieval one-liners -# - -# Get the vendor name of the CPU. -cat /proc/cpuinfo | grep vendor | uniq | awk '{print $3}' - -# Get the model name of the CPU. -cat /proc/cpuinfo | grep 'model name' | uniq | cut -d' ' -f3- - -# Get the architecture of the CPU. -lscpu | grep 'Architecture' | awk '{print $2}' - -# Get the subarchitecture of the CPU. -gcc -march=native -Q --help=target | grep march | awk '{print $2}' - -# Get the assembler name of the CPU. -gcc -march=native -Q --help=target | grep masm= | awk '{print $2}' | head -1 - diff --git a/one-liners/hardware_management-output_only/monitor_information/monitor-status-information-retrieval.one-liners b/one-liners/hardware_management-output_only/monitor_information/monitor-status-information-retrieval.one-liners deleted file mode 100644 index 371f4a78..00000000 --- a/one-liners/hardware_management-output_only/monitor_information/monitor-status-information-retrieval.one-liners +++ /dev/null @@ -1,13 +0,0 @@ -# -# File: -# monitor-status-information-retrieval.one-liners -# -# Description: -# Monitor status information retrieval one-liners -# - -# Get the maximum backlight level. -# Note: The interface to the ACPI kernel module for video (e.g. intel_backlight) can be found by running -# "ls /sys/class/backlight/". -cat /sys/class/backlight/intel_backlight/max_brightness - diff --git a/one-liners/hardware_management/README.md b/one-liners/hardware_management/README.md deleted file mode 100644 index 645c9060..00000000 --- a/one-liners/hardware_management/README.md +++ /dev/null @@ -1,11 +0,0 @@ - -# Hardware management - -## Monitor management - -* [Monitor status management one liners](monitor_management/monitor-status-management.one-liners) - -## *Notes* - -* Hardware management one-liners are intended to be distribution-independent, however, some may not work for certain distributions. - diff --git a/one-liners/hardware_management/SOURCES.txt b/one-liners/hardware_management/SOURCES.txt deleted file mode 100644 index be990696..00000000 --- a/one-liners/hardware_management/SOURCES.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Sources for Hardware management - main one-liners - -monitor_management/monitor-status-management.one-liners: - - Set the backlight level: - https://wiki.archlinux.org/index.php/backlight#ACPI - diff --git a/one-liners/hardware_management/monitor_management/monitor-status-management.one-liners b/one-liners/hardware_management/monitor_management/monitor-status-management.one-liners deleted file mode 100644 index bf53ded7..00000000 --- a/one-liners/hardware_management/monitor_management/monitor-status-management.one-liners +++ /dev/null @@ -1,13 +0,0 @@ -# -# File: -# monitor-status-management.one-liners -# -# Description: -# Monitor status management one liners -# - -# Set the backlight level. -# Note: The interface to the ACPI kernel module for video (e.g. intel_backlight) can be found by running -# "ls /sys/class/backlight/". -tee /sys/class/backlight/intel_backlight/brightness <<< - diff --git a/one-liners/system_management-output_only/README.md b/one-liners/system_management-output_only/README.md deleted file mode 100644 index 5a2f1b3d..00000000 --- a/one-liners/system_management-output_only/README.md +++ /dev/null @@ -1,11 +0,0 @@ - -# System management - output only - -## Device information - -* [Device property information retrieval one-liners](device_information/device-property-information-retrieval.one-liners) - -## Operating system information - -* [Operating system property information retrieval one-liners](operating_system_information/operating-system-property-information-retrieval.one-liners) - diff --git a/one-liners/system_management-output_only/device_information/device-property-information-retrieval.one-liners b/one-liners/system_management-output_only/device_information/device-property-information-retrieval.one-liners deleted file mode 100644 index 2516ab6d..00000000 --- a/one-liners/system_management-output_only/device_information/device-property-information-retrieval.one-liners +++ /dev/null @@ -1,12 +0,0 @@ -# -# File: -# device-property-information-retrieval.one-liners -# -# Description: -# Device property information retrieval one-liners -# - -# List the udev attributes for a device. -# Example device names: "/dev/sda1" and "/dev/bus/usb/" -udevadm info -a -p "$(udevadm info -q path -n '')" - diff --git a/one-liners/system_management-output_only/operating_system_information/operating-system-property-information-retrieval.one-liners b/one-liners/system_management-output_only/operating_system_information/operating-system-property-information-retrieval.one-liners deleted file mode 100644 index 36ca9ace..00000000 --- a/one-liners/system_management-output_only/operating_system_information/operating-system-property-information-retrieval.one-liners +++ /dev/null @@ -1,12 +0,0 @@ -# -# File: -# operating-system-property-information-retrieval.one-liners -# -# Description: -# Operating system property information retrieval one-liners -# - -# Print the target architecture of the current operating system. -# Dependencies: llvm -llc --version | grep Default | tr -s ' ' | cut -d ' ' -f4 - diff --git a/one-liners/system_management/README.md b/one-liners/system_management/README.md deleted file mode 100644 index 8ec4b1e1..00000000 --- a/one-liners/system_management/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# System management - -## Device management - -* [Device udev management one-liners](device_management/device-udev-management.one-liners) - diff --git a/one-liners/system_management/device_management/device-udev-management.one-liners b/one-liners/system_management/device_management/device-udev-management.one-liners deleted file mode 100644 index 206fee6b..00000000 --- a/one-liners/system_management/device_management/device-udev-management.one-liners +++ /dev/null @@ -1,25 +0,0 @@ -# -# File: -# device-udev-management.one-liners -# -# Description: -# Device udev management one-liners -# - -LOADING/RELOADING RULES: - -# Reload all udev rules. -# Note: This is not necessary after creating a new udev rule file as udev automatically detects file changes. -udevadm control --reload - -TESTING RULES: - -# Test a udev rule. -# Note: This shows the effects of all keys of a rule except RUN. To also see the effects of RUN, use "udevadm trigger" -# instead. This also removes old symlinks that have been changed. -udevadm test "$(udevadm info -q path -n /dev/bus/usb/)" 2>&1 - -# Force udev to trigger all rules. -# Note: This does not update smylinks or run the command assigned to key RUN. -udevadm trigger - diff --git a/scripts/README.md b/scripts/README.md deleted file mode 100644 index 12284004..00000000 --- a/scripts/README.md +++ /dev/null @@ -1,15 +0,0 @@ - -# Scripts - -This directory contains scripts. - -## View all - -To view all the solutions in this directory, change to it and run the following: - -```bash -git show-ref --verify -q refs/heads/helper_scripts || \ -git branch --track helper_scripts origin/helper_scripts; \ -bash <(git show helper_scripts:cf-gpc-view-scripts.sh) -``` - diff --git a/scripts/application_management-modules/README.md b/scripts/application_management-modules/README.md deleted file mode 100644 index 2add059b..00000000 --- a/scripts/application_management-modules/README.md +++ /dev/null @@ -1,8 +0,0 @@ - -# Application management - modules - -## Terminal - -* [execcmdinnewterm](terminal/execcmdinnewterm): Execute a command in a new terminal emulator. -* [execcmdinterm](terminal/execcmdinterm): Execute a command in a terminal emulator. - diff --git a/scripts/application_management-modules/terminal/execcmdinnewterm b/scripts/application_management-modules/terminal/execcmdinnewterm deleted file mode 100755 index bc30db33..00000000 --- a/scripts/application_management-modules/terminal/execcmdinnewterm +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# execcmdinnewterm -# -# Description: -# Execute a command in a new terminal emulator. -# -# Supplemental feature: -# This script returns the window ID of the new terminal emulator window. -# -# Usage: -# execcmdinnewterm [command] -# -# Dependencies: -# xterm (the terminal emulator program used) -# wmctrl (used to get the window ID of the new terminal emulator window) -# -# Notes: -# The terminal emulator will load the Bash shell after the command is -# finished. -# -# This solution can accept a Bash Here document as a command. -# - -# ============================================ -# Create the utilitiy functions -# ============================================ - -getWindIdByPid() { - while IFS= read line; do - if [[ "${line}" =~ (0x)([0-9a-z]+)([ ][- ][0-9]+[ ])([0-9]*) ]]; then - local winId="${BASH_REMATCH[1]}${BASH_REMATCH[2]}" - local pid="${BASH_REMATCH[4]}" - if [ "${pid}" -eq "${1}" ]; then - echo "${winId}" - break - fi - fi - done < <(wmctrl -lp) -} - -# ============================================ -# Launch the terminal emulator -# ============================================ - -nohup xterm -e bash -c "$(printf '%s\nexec bash' "${*}")" &>/dev/null & -# Note: "$(printf '%s\nexec bash' "${*}")" allows a bash Here document to be passed -# passed as a command. - -PID="$!" - -sleep .08 -WIND_ID="$(getWindIdByPid "${PID}")" - -# Check if stdout and stderr point to a terminal. If so, redirect them to -# /dev/null to prevent unnecessary output to the spawning terminal. Note: The -# window ID will still be obtainable in a subprocess. -if test -t 1; then - exec 1>/dev/null -fi -if test -t 2; then - exec 2>/dev/null -fi - -# echo the window ID so the caller can obtain it -echo "${WIND_ID}" - diff --git a/scripts/application_management-modules/terminal/execcmdinterm b/scripts/application_management-modules/terminal/execcmdinterm deleted file mode 100755 index 17f9c617..00000000 --- a/scripts/application_management-modules/terminal/execcmdinterm +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# execcmdinterm -# -# Description: -# Execute a command in a terminal emulator. -# -# Usage: -# execcmdinterm (--class | --title ) [options] -- -# -# -# Options: -# -c --class class of the terminal emulator (required if -# --title is not used) -# -t --title partial or full window title of the terminal -# emulator (required if --class is not used; will -# override --class if both are used) -# -# -r --refocus refocus previous window after running command -# -# Exit codes: -# 0: command executed -# 1: command not executed -# -# Dependencies: -# xautomation (if xdotool is preferred, follow the instructions at the bottom -# where xte is used. [Note: Running the command with xdotool is -# significantly slower as it sends each character individually]). -# -# Notes: -# This utility should be used with a keybinding or in a script. -# - -# ======= CONFIGURATIONS ============== - -# This is the delay time for running the xautomation events in the terminal -# emulator after it has been focused. With no delay time, the terminal emulator -# may focused too quickly, causing none or only a part of the events to succeed. -# (Note: This delay time is also applied before refocusing the previously -# focused window). -readonly XEVENTS_DELAY_TIME='.15' - -# ======= ! CONFIGURATIONS ============== - -OPTS="$(getopt -q -o c:,t:,r --long class:,title:,refocus -n 'execcmdinterm' \ - -- "${@}")" -if [ "$?" -ne 0 ]; then - # output errors as a desktop notification since this script is meant to be - # used with a keybinding and errors printed to stderr will not be seen. - notify-send 'execcmdinterm (err): unrecognized option' - exit 1 -fi -eval set -- "${OPTS}" - -while true; do - case "${1}" in - --class|-c) TERM_CLASS="${2}"; shift;; - --title|-t) TERM_TITLE="${2}"; shift;; - --refocus|-r) OPT_REFOCUS=true;; - --) shift; break;; - *) break;; - esac - shift -done - -if [ -z "${TERM_CLASS}" ] && [ -z "${TERM_TITLE}" ]; then - notify-send 'execcmdinterm (err): must use option --class or --title' - exit 1 -fi - -if [ "$#" -eq 0 ]; then - # print to the terminal for testing purposes - echo 'execcmdinterm: no execute command provided' 1>&2 - exit 1 -fi - -# ============================================ -# Utilitiy functions -# ============================================ - -getWindIdByName() { - local windIds=("$(wmctrl -l | awk -v srch="${1}" '{$2=$3=""; windName = \ - gensub(/([^ ]*)(.*)/, "\\2", "g", $0)} windName ~ srch {print $1}')") - [ $((${#windIds[@]})) -ge 1 ] && echo "${windIds[0]}" -} - -getFirstWindIdInClass() { - local classWindIds=($(wmctrl -lx | awk -v class="${1}" '$3 ~ class \ - {print $1}')) - [ $((${#classWindIds[@]})) -ge 1 ] && echo "${classWindIds[0]}" -} - -getActvWindId() { - echo "$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5 | rev | cut -c \ - 2- | rev | sed 's/^0x/0x0/')" -} - -# ============================================ -# Get the window ID of the terminal -# ============================================ - -if [ -n "${TERM_TITLE}" ]; then - termWindId="$(getWindIdByName ${TERM_TITLE})" -else - termWindId="$(getFirstWindIdInClass "${TERM_CLASS}")" -fi - -# ============================================ -# Execute the X events -# ============================================ - -if [ -n "${termWindId}" ]; then - [ "${OPT_REFOCUS}" = 'true' ] && currWindId="$(getActvWindId)" - - wmctrl -i -a "${termWindId}" - [ -n "${XEVENTS_DELAY_TIME}" ] && sleep "${XEVENTS_DELAY_TIME}" - - # To use xdotool, comment the xte code sections and uncomment the xdotool code - # sections. - - # --------- xte --------- - - # Note: Xte sometimes fails to completely paste a string with more than 249 - # characters. As a result, a string with more than 249 characters is pasted - # by every 249 character part. - argStr="${@}" - if [ "${#argStr}" -gt 249 ]; then - for ((i=0; i<=${#argStr}; i+=249)); do - xte "str ${argStr:${i}:249}" - done - xte 'key Return' - else - xte <<-EOF - str ${@} - usleep 14000 - key Return - EOF - fi - - # --------- xdotool --------- - - # xdotool type "${@}" - # # must run a separate xdotool command as "type" will type everything after - # # it; also a much higher sleep time is needed as xdotool types each - # # character (instead of pasting the string). - # xdotool sleep .5 key Return - - if [ "${OPT_REFOCUS}" = 'true' ]; then - [ -n "${XEVENTS_DELAY_TIME}" ] && sleep "${XEVENTS_DELAY_TIME}" - wmctrl -i -a "${currWindId}" - fi -fi - diff --git a/scripts/application_management/README.md b/scripts/application_management/README.md deleted file mode 100644 index d7b63222..00000000 --- a/scripts/application_management/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Application management - -## Terminal - -* [execlasttermcmd](terminal/execlasttermcmd): Execute the last command of a terminal emulator. - diff --git a/scripts/application_management/terminal/execlasttermcmd b/scripts/application_management/terminal/execlasttermcmd deleted file mode 100755 index 2b4ed81f..00000000 --- a/scripts/application_management/terminal/execlasttermcmd +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# execlasttermcmd -# -# Description: -# Execute the last command of a terminal emulator. -# -# Usage: -# execlasttermcmd (--class | --title ) [options] -- -# -# -# Options: -# -c --class class of the terminal emulator (required if -# --title is not used) -# -t --title partial or full window title of the terminal -# emulator (required if --class is not used; will -# override --class if both are used) -# -# -r --refocus refocus previous window after running command -# -# Exit codes: -# 0: command executed -# 1: command not executed -# -# Dependencies: -# xautomation (if xdotool is preferred, follow the instructions at the bottom -# where xte is used. [Note: Running the command with xdotool is -# significantly slower as it sends each character individually]). -# -# Notes: -# This utility should be used with a keybinding or in a script. -# -# If the last command in the terminal emulator is moved to but not executed, -# increase the usleep time in the xte command. -# - -# ======= CONFIGURATIONS ============== - -# This is the delay time for running the xautomation events in the terminal -# emulator after it has been focused. With no delay time, the terminal emulator -# may be focused too quickly, causing none or only a part of the events to run. -# (Note: This delay time is also applied before refocusing the previously -# focused window). -readonly XEVENTS_DELAY_TIME='.28' - -# ======= ! CONFIGURATIONS ============== - -OPTS="$(getopt -q -o c:,t:,r --long class:,title:,refocus -n 'execlasttermcmd' \ - -- "${@}")" -if [ "$?" -ne 0 ]; then - # output errors as a desktop notification since this script is meant to be - # used with a keybinding and errors printed to stderr will not be seen. - notify-send 'execlasttermcmd (err): unrecognized option' - exit 1 -fi -eval set -- "${OPTS}" - -while true; do - case "${1}" in - --class|-c) TERM_CLASS="${2}"; shift;; - --title|-t) TERM_TITLE="${2}"; shift;; - --refocus|-r) OPT_REFOCUS=true;; - --) shift; break;; - *) break;; - esac - shift -done - -if [ -z "${TERM_CLASS}" ] && [ -z "${TERM_TITLE}" ]; then - notify-send 'execlasttermcmd (err): must use option --class or --title' - exit 1 -fi - -# ============================================ -# Create utilitiy functions -# ============================================ - -getWindIdByName() { - local windIds=("$(wmctrl -l | awk -v srch="${1}" '{$2=$3=""; windName = \ - gensub(/([^ ]*)(.*)/, "\\2", "g", $0)} windName ~ srch {print $1}')") - [ $((${#windIds[@]})) -ge 1 ] && echo "${windIds[0]}" -} - -getFirstWindIdInClass() { - local classWindIds=($(wmctrl -lx | awk -v class="${1}" '$3 ~ class \ - {print $1}')) - [ $((${#classWindIds[@]})) -ge 1 ] && echo "${classWindIds[0]}" -} - -getActvWindId() { - echo "$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5 | rev | cut -c \ - 2- | rev | sed 's/^0x/0x0/')" -} - -secondsToMicrosecondsDecimal() { - printf '%.4f' "$(bc <<< "${1}*1000000")" -} - -secondsToMicroseconds() { - printf '%.0f' "$(secondsToMicrosecondsDecimal "${1}")" -} - -# ============================================ -# Get the window ID of the terminal -# ============================================ - -if [ -n "${TERM_TITLE}" ]; then - termWindId="$(getWindIdByName ${TERM_TITLE})" -else - termWindId="$(getFirstWindIdInClass "${TERM_CLASS}")" -fi - -# ============================================ -# Execute the X events -# ============================================ - -if [ -n "${termWindId}" ]; then - [ "${OPT_REFOCUS}" = 'true' ] && currWindId="$(getActvWindId)" - - wmctrl -i -a "${termWindId}" - - # To use xdotool, comment the xte and uncomment the xdotool section. - - # --------- xte --------- - - # The xevents delay time must be converted to microseconds because xte's - # "sleep" command does not accept decimal values. - micros="$(secondsToMicroseconds ${XEVENTS_DELAY_TIME})" - xte "usleep ${micros}" 'key Up' "usleep ${micros}" 'key Return' - - # --------- xdotool --------- - - # xdotool sleep "${XEVENTS_DELAY_TIME}" key Up sleep "${XEVENTS_DELAY_TIME}" \ - # key Return - - if [ "${OPT_REFOCUS}" = 'true' ]; then - [ -n "${XEVENTS_DELAY_TIME}" ] && sleep "${XEVENTS_DELAY_TIME}" - wmctrl -i -a "${currWindId}" - fi -fi - diff --git a/scripts/file_management-modules/README.md b/scripts/file_management-modules/README.md deleted file mode 100644 index 9fcfa39f..00000000 --- a/scripts/file_management-modules/README.md +++ /dev/null @@ -1,12 +0,0 @@ - -# File management - modules - -## File monitoring - -* [execonfilechange](file_monitoring/execonfilechange): Execute a command when a file has changed in the current directory. - -## File retrieval - -* [findfileforcmd](file_retrieval/findfileforcmd): Recursively find a file or directory for a command. -* [loctfileforcmd](file_retrieval/loctfileforcmd): Locate a file or directory for a command. - diff --git a/scripts/file_management-modules/file_monitoring/execonfilechange b/scripts/file_management-modules/file_monitoring/execonfilechange deleted file mode 100755 index 16963275..00000000 --- a/scripts/file_management-modules/file_monitoring/execonfilechange +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# execonfilechange -# -# Description: -# Execute a command when a file has changed in the current directory. -# -# Usage: -# execonfilechange -# -# Usage note: -# Run this script in the directory it is to monitor. -# -# Dependencies: -# inotify-tools -# - -readonly FORMAT="$(echo -e "\033[1;33m%w%f\033[0m written")" - -while inotifywait -qre close_write --format "${FORMAT}" .; do - # This section will run once a file has changed in the current directory. - ${@} - echo '[+] execonfilechange: command executed' -done - diff --git a/scripts/file_management-modules/file_retrieval/findfileforcmd b/scripts/file_management-modules/file_retrieval/findfileforcmd deleted file mode 100755 index bbea5186..00000000 --- a/scripts/file_management-modules/file_retrieval/findfileforcmd +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# findfileforcmd -# -# Description: -# Recursively find a file or directory for a command. -# -# Examples: -# # Recursively find a file with a name containing "stat" for command "vim". -# findfileforcmd {vim} stat -# -# # Recursively find a directory with a name containing "docume" for command -# # "thunar". -# findfileforcmd {thunar} --d docume -# -# # same as previous, except return the third occurrence -# findfileforcmd {thunar} --d --3 docume -# -# Usage: -# findfileforcmd {} [options] -# [directory] -# -# [directory]: directory to search in; default is current. -# -# Options: -# --d return a directory instead of a file -# --<1-9> return the specified occurrence -# --a return all occurrences -# --p print the returned files or directories only -# -# Exit codes: -# 0: file or directory found -# 1: error occurred or file or directory not found -# -# Notes: -# The options for this utility use double dashes to avoid overriding the -# options for the command in the brackets. -# - -# ======= CONFIGURATIONS ============== - -# Set this variable to "true" to support file names with spaces. If true and -# all occurrences are returned using option --a, only the last occurrence -# will be used by most execute command. -readonly SUPPORT_FILE_NAMES_WITH_SPACES='false' - -# ======= ! CONFIGURATIONS ============== - -# ============================================ -# Get the execute command -# ============================================ - -# Note: The following could be done using command "set", however, command "set" -# removes all arguments containing "?". - -for ((x=1; x<="$#"; x++)); do - arg="${@:x:1}" - - if [ -z "${arg##*'}'*}" ]; then - EXECUTE_COMMAND="${@:1:x}" - shift "${x}" - fi -done - -if [ -z "${EXECUTE_COMMAND}" ]; then - echo -e 'findfileforcmd: invalid arguments:\nexecute command not specified' \ - 1>&2 - exit 1 -fi - -EXECUTE_COMMAND="${EXECUTE_COMMAND#{}" -EXECUTE_COMMAND="${EXECUTE_COMMAND%\}}" - -# ============================================ -# Process prerequisites -# ============================================ - -if [ "$#" -eq 0 ]; then - echo 'findfileforcmd: no file or directory name specified' 1>&2 - exit 1 -fi - -# ============================================ -# Process options and arguments -# ============================================ - -OPTS="$(getopt -o '#' --long d,1,2,3,4,5,6,7,8,9,a,p -n 'findfileforcmd' -- \ - "${@}")" -[ "$?" -ne 0 ] && exit 1 -eval set -- "${OPTS}" - -while true; do - case "${1}" in - --d) OPT_RETURN_DIRECTORIES='true';; - --1|--2|--3|--4|--5|--6|--7|--8|--9) OPT_RETURN_OCCURRENCE="${1#'--'}";; - --a) OPT_RETURN_ALL_OCCURRENCES='true';; - --p) OPT_PRINT_ONLY='true';; - --) shift; break;; - * ) break;; - esac - shift -done - -# ============================================ -# Process find command options -# ============================================ - -if [ "$#" -ge 2 ]; then - findDir="${2}" -else - findDir='.' -fi - -if [ "${OPT_RETURN_DIRECTORIES}" = 'true' ]; then - findOptType='-type d' -else - findOptType='-type f' -fi - -if [ -z "${OPT_RETURN_OCCURRENCE}" ] && [ "${OPT_RETURN_ALL_OCCURRENCES}" != 'true' ]; then - findOptsPrintQuit='-print -quit' -fi - -# ============================================ -# Begin find process -# ============================================ - -findOutput="$(find "${findDir}" ${findOptType} -name "*${1}*" \ - ${findOptsPrintQuit} 2>/dev/null)" - -if [ -z "${findOutput}" ]; then - echo "findfileforcmd: file or directory \"${@}\" not found" 1>&2 - exit 1 -fi - -if [ "${OPT_RETURN_ALL_OCCURRENCES}" != 'true' ]; then - if [ -n "${OPT_RETURN_OCCURRENCE}" ]; then - findOutputNumOccurs="$(echo "${findOutput}" | wc -l)" - - if [ "${OPT_RETURN_OCCURRENCE}" -gt "${findOutputNumOccurs}" ]; then - OPT_RETURN_OCCURRENCE="${findOutputNumOccurs}" - fi - findOutput="$(echo "${findOutput}" | sed "${OPT_RETURN_OCCURRENCE}q;d")" - else - findOutput="$(echo "${findOutput}" | sed "1q;d")" - fi -fi - -if [ "${OPT_PRINT_ONLY}" = 'true' ]; then - echo "${findOutput}" -else - if [ "${SUPPORT_FILE_NAMES_WITH_SPACES}" = 'true' ]; then - ${EXECUTE_COMMAND} "${findOutput}" - else - ${EXECUTE_COMMAND} ${findOutput} - fi -fi - diff --git a/scripts/file_management-modules/file_retrieval/loctfileforcmd b/scripts/file_management-modules/file_retrieval/loctfileforcmd deleted file mode 100755 index 553bb349..00000000 --- a/scripts/file_management-modules/file_retrieval/loctfileforcmd +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# loctfileforcmd -# -# Description: -# Locate a file or directory for a command. -# -# Examples: -# # Locate a file with a name containing "stat" for command "vim". -# loctfileforcmd {vim} stat -# -# # Locate a directory with a name containing "docu" for command "thunar". -# loctfileforcmd {thunar} --d docu -# -# # same as previous, except return the third occurrence -# loctfileforcmd {thunar} --d --3 docu -# -# Usage: -# loctfileforcmd {} [options] -# -# Usage note: -# Variable LOCATE_FILE_COMMAND in the configurations section must be assigned -# a command that returns a file or directory path. The command must return -# ordinary files by default and directories via the option specified by -# LOCATE_FILE_COMMAND_OPT_DIRECTORIES for option --d to apply. -# -# Options: -# --d return a directory instead of a file -# --<1-9> return the specified occurrence -# --p print the returned files or directories only -# -# Exit codes: -# 0: file or directory found -# 1: error occurred or file or directory not found -# -# Notes: -# The options for this utility use double dashes to avoid overriding the -# options for the command in the brackets. -# - -# ======= CONFIGURATIONS ============== - -# Locate file command -readonly LOCATE_FILE_COMMAND='locatefile' - -# Locate file command option to return directories only; can be empty -readonly LOCATE_FILE_COMMAND_OPT_DIRECTORIES='-d' - -# Locate file command option to change the located occurrence; can be empty; -# must require a numerical argument -readonly LOCATE_FILE_COMMAND_OPT_OCCURRENCE='-o' - -# ======= ! CONFIGURATIONS ============== - -# ============================================ -# Get the execute command -# ============================================ - -# Note: The following could be done using command "set", however, command "set" -# removes all arguments containing "?". - -for ((x=1; x<="$#"; x++)); do - arg="${@:x:1}" - - if [ -z "${arg##*'}'*}" ]; then - EXECUTE_COMMAND="${@:1:x}" - shift "${x}" - fi -done - -if [ -z "${EXECUTE_COMMAND}" ]; then - echo -e 'loctfileforcmd: invalid arguments:\nexecute command not specified' \ - 1>&2 - exit 1 -fi - -EXECUTE_COMMAND="${EXECUTE_COMMAND#{}" -EXECUTE_COMMAND="${EXECUTE_COMMAND%\}}" - -# ============================================ -# Check prerequisites -# ============================================ - -if [ "$#" -eq 0 ]; then - echo 'loctfileforcmd: no file or directory name specified' 1>&2 - exit 1 -fi - -if ! hash "${LOCATE_FILE_COMMAND}" >/dev/null 2>&1; then - echo "loctfileforcmd: command \"${LOCATE_FILE_COMMAND}\" does not exist" 1>&2 - exit 1 -fi - -# ============================================ -# Process options and arguments -# ============================================ - -OPTS="$(getopt -o '#' --long d,1,2,3,4,5,6,7,8,9,p -n 'loctfileforcmd' -- \ - "${@}")" -[ "$?" -ne 0 ] && exit 1 -eval set -- "${OPTS}" - -while true; do - case "${1}" in - --d) OPT_RETURN_DIRECTORIES='true';; - --1|--2|--3|--4|--5|--6|--7|--8|--9) OPT_RETURN_OCCURRENCE="${1#'--'}";; - --p) OPT_PRINT_ONLY='true';; - --) shift; break;; - * ) break;; - esac - shift -done - -# ============================================ -# Process locate file command options -# ============================================ - -if [ "${OPT_RETURN_DIRECTORIES}" = 'true' ] && [ -n \ - "${LOCATE_FILE_COMMAND_OPT_DIRECTORIES}" ]; then - locfileOpts="${LOCATE_FILE_COMMAND_OPT_DIRECTORIES}" -fi - -if [ -n "${OPT_RETURN_OCCURRENCE}" ] && [ -n \ - "${LOCATE_FILE_COMMAND_OPT_OCCURRENCE}" ]; then - locfileOpts+=" ${LOCATE_FILE_COMMAND_OPT_OCCURRENCE} ${OPT_RETURN_OCCURRENCE}" -fi - -# ============================================ -# Begin locate process -# ============================================ - -loctfileOutput="$(${LOCATE_FILE_COMMAND} ${locfileOpts} "${@}")" - -if [ -z "${loctfileOutput}" ]; then - echo "loctfileforcmd: file or directory \"${@}\" not found" 1>&2 - exit 1 -fi - -loctfileOutput="$(echo "${loctfileOutput}" | sed 's/ /\\n/g')" - -if [ "${OPT_PRINT_ONLY}" = 'true' ]; then - echo "${loctfileOutput}" -else - ${EXECUTE_COMMAND} "${loctfileOutput}" -fi - diff --git a/scripts/file_management/README.md b/scripts/file_management/README.md deleted file mode 100644 index c353736f..00000000 --- a/scripts/file_management/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# File management - -## File name manipulation - -* [renmrecr](file_name_manipulation/renmrecr): Rename all files matching a name recursively. - diff --git a/scripts/file_management/file_name_manipulation/renmrecr b/scripts/file_management/file_name_manipulation/renmrecr deleted file mode 100755 index 466d337f..00000000 --- a/scripts/file_management/file_name_manipulation/renmrecr +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# renmrecr -# -# Description: -# Rename all files matching a name recursively. -# -# Usage: -# renmrecr -# - -if [ "$#" -ne 2 ]; then - echo 'renmrecr: invalid number of arguments' 1>&2 - exit 1 -fi - -find . -depth -type f -name "${1}" | while IFS= read -r file; do - mv -i "${file}" "$(dirname "${file}")/${2}" -done - diff --git a/scripts/hardware_management-output_only/README.md b/scripts/hardware_management-output_only/README.md deleted file mode 100644 index ceedac57..00000000 --- a/scripts/hardware_management-output_only/README.md +++ /dev/null @@ -1,10 +0,0 @@ - -# Hardware management - output only - -## Device information - -* [isbluetoothblocked](device_information/isbluetoothblocked): Check if the primary bluetooth device interface is soft blocked. -* [issecondarywlanblocked](device_information/issecondarywlanblocked): Check if a secondary wireless local area network device interface is soft blocked. -* [iswlanblocked](device_information/iswlanblocked): Check if the primary wireless local area network device interface is soft blocked. -* [isrightmonitorenabled](device_information/isrightmonitorenabled): Check if a right monitor (a monitor positioned to the right of the leftmost monitor) is enabled. - diff --git a/scripts/hardware_management-output_only/device_information/isbluetoothblocked b/scripts/hardware_management-output_only/device_information/isbluetoothblocked deleted file mode 100755 index d9811e17..00000000 --- a/scripts/hardware_management-output_only/device_information/isbluetoothblocked +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# isbluetoothblocked -# -# Description: -# Check if the primary bluetooth device interface is soft blocked. -# -# Exit codes: -# 0: is blocked -# 1: is not blocked -# - -IS_BLOCKED="$(rfkill list bluetooth | sed -n 's/Soft blocked: \(.*\)/\1/p' | \ - head -1 | sed 's/^[ \t]*//;s/[ \t]*$//')" - -if [ "${IS_BLOCKED}" = 'yes' ]; then - exit 0 -else - exit 1 -fi - diff --git a/scripts/hardware_management-output_only/device_information/isrightmonitorenabled b/scripts/hardware_management-output_only/device_information/isrightmonitorenabled deleted file mode 100755 index e3658430..00000000 --- a/scripts/hardware_management-output_only/device_information/isrightmonitorenabled +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# isrightmonitorenabled -# -# Description: -# Check if a right monitor (a monitor positioned to the right of the -# leftmost monitor) is enabled. -# -# Returns: -# Monitor type (e.g. "DP", "HDMI", "VGA", "TV", "DVI1") if the monitor is -# enabled -# -# Exit codes: -# 0: is enabled -# 1: is not enabled -# -# Options: -# -o also output offset/starting position of right monitor (returns string -# in the format ",") -# -# Notes: -# All monitors after the second will be ignored. -# -# The right monitor is considered the one with the lowest non-zero X offset. -# The left monitor is always the first one with a zero X offset. -# - -while getopts :o OPT; do - case "${OPT}" in - o) OUTPUT_OFFSET=true;; - \?) - echo "isrightmonitorenabled: option \"${OPTARG}\" unknown" 1>&2 - exit 1 - ;; - esac -done -shift $((OPTIND - 1)) - -IFS=$'\n' -xrandrMntrs=($(xrandr --query | grep ' connected')) -unset IFS - -if [ "${#xrandrMntrs[@]}" -ge 2 ]; then - for xrandrMntr in "${xrandrMntrs[@]}"; do - vals=($(echo "${xrandrMntr}" | perl -ne \ - 'm/([^ ]+) connected (?:primary )?[^+]+\+(\d+).*/; print "$1 $2"')) - - if [ "${#vals[@]}" -eq 2 ]; then - mntrType="${vals[0]}" - offst="${vals[1]}" - - if [[ "${offst}" -gt 0 && (-z "${lwstNonZeroOffst}" || "${offst}" -lt \ - "${lwstNonZeroOffst}") ]]; then - RIGHT_MONITOR_TYPE="${vals[0]}" - RIGHT_MONITOR_OFFST="${vals[1]}" - lwstNonZeroOffst="${offst}" - fi - fi - done - - if [ -n "${RIGHT_MONITOR_TYPE}" ]; then - retStr="${RIGHT_MONITOR_TYPE}" - if [ "${OUTPUT_OFFSET}" = 'true' ]; then - retStr+=",${RIGHT_MONITOR_OFFST}" - fi - echo "${retStr}" - exit 0 - else - exit 1 - fi -else - exit 1 -fi - diff --git a/scripts/hardware_management-output_only/device_information/issecondarywlanblocked b/scripts/hardware_management-output_only/device_information/issecondarywlanblocked deleted file mode 100755 index 9d6c8d67..00000000 --- a/scripts/hardware_management-output_only/device_information/issecondarywlanblocked +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# issecondarywlanblocked -# -# Description: -# Check if a secondary wireless local area network device interface is soft -# blocked. -# -# Exit codes: -# 0: is blocked -# 1: is not blocked -# -# Note: -# The primary WLAN device interface will be checked if a secondary one does -# not exist. -# - -IS_BLOCKED="$(rfkill list wlan | sed -n 's/Soft blocked: \(.*\)/\1/p' | \ - tail -1 | sed 's/^[ \t]*//;s/[ \t]*$//')" - -if [ "${IS_BLOCKED}" = 'yes' ]; then - exit 0 -else - exit 1 -fi - diff --git a/scripts/hardware_management-output_only/device_information/iswlanblocked b/scripts/hardware_management-output_only/device_information/iswlanblocked deleted file mode 100755 index e43ebf15..00000000 --- a/scripts/hardware_management-output_only/device_information/iswlanblocked +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# iswlanblocked -# -# Description: -# Check if the primary wireless local area network device interface is soft -# blocked. -# -# Exit codes: -# 0: is blocked -# 1: is not blocked -# - -IS_BLOCKED="$(rfkill list wlan | sed -n 's/Soft blocked: \(.*\)/\1/p' | \ - head -1 | sed 's/^[ \t]*//;s/[ \t]*$//')" - -if [ "${IS_BLOCKED}" = 'yes' ]; then - exit 0 -else - exit 1 -fi - diff --git a/scripts/mobile_device_management-android/README.md b/scripts/mobile_device_management-android/README.md deleted file mode 100644 index 09e9b5ec..00000000 --- a/scripts/mobile_device_management-android/README.md +++ /dev/null @@ -1,17 +0,0 @@ - -# Mobile device management - Android - -## Application management - -* [sendtextmesgviaandroiddev](application_management/sendtextmesgviaandroiddev): Send a text message via an Android device. - -## Data retrieval - -* [getcontactinfofromandroiddev](data_retrieval/getcontactinfofromandroiddev): Get information of a contact from an Android device. - -## Hardware management - -* [watchandroiddevscreentappos](hardware_management/watchandroiddevscreentappos): Watch the X and Y screen tap positions of an Android device. -* [turnandroiddevscreenoff](hardware_management/turnandroiddevscreenoff): Turn an Android device screen off. -* [turnandroiddevscreenon](hardware_management/turnandroiddevscreenon): Turn an Android device screen on. - diff --git a/scripts/mobile_device_management-android/application_management/sendtextmesgviaandroiddev b/scripts/mobile_device_management-android/application_management/sendtextmesgviaandroiddev deleted file mode 100755 index 819cdd70..00000000 --- a/scripts/mobile_device_management-android/application_management/sendtextmesgviaandroiddev +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# sendtextmesgviaandroiddev -# -# Description: -# Send a test message via an Android device. -# -# Usage: -# sendtextmesgviaandroiddev -# -# : may contain "\n" for newlines -# -# Notes: -# If the message fails to send and simply opens up the thread of the contact -# of whom the message is being sent to, click the back button from the thread. -# - -if [ "$#" -lt 2 ]; then - echo 'sendtextmesgviaandroiddev: invalid number of arguments' 1>&2 - exit 1 -fi - -readonly PHONE_NUMBER="${1}" -shift -readonly MESSAGE="$(echo "${@}" | sed 's/\\n/${NL}/g')" - -# Screen must be on for an sms to be sent using this method. -isScreenOn="$(adb -d shell 'dumpsys power' | grep mScreenOn)" - -# Exit if no device was found. -if [ $? -eq 1 ]; then - exit -fi - -if [[ "${isScreenOn##*=}" = *'false'* ]]; then - adb -d shell 'input keyevent KEYCODE_POWER;' -fi - -adb -d shell "NL=$'\n' ; am start -a android.intent.action.SENDTO -d \ - sms:${PHONE_NUMBER} --es sms_body \"${MESSAGE}\" --ez exit_on_sent true; \ - input keyevent 66" >/dev/null - diff --git a/scripts/mobile_device_management-android/data_retrieval/getcontactinfofromandroiddev b/scripts/mobile_device_management-android/data_retrieval/getcontactinfofromandroiddev deleted file mode 100755 index 04993d7a..00000000 --- a/scripts/mobile_device_management-android/data_retrieval/getcontactinfofromandroiddev +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getcontactinfofromandroiddev -# -# Description: -# Get information of a contact from an Android device. -# -# Usage: -# getcontactinfofromandroiddev -# - -if [ "$#" -eq 0 ]; then - echo 'getcontactinfofromandroiddev: contact phone number or name required' \ - 1>&2 - exit 1 -fi - -adb -d shell content query --uri \ - content://com.android.contacts/data/phones/filter/"${@}" | tr ',' '\n' - diff --git a/scripts/mobile_device_management-android/hardware_management/turnandroiddevscreenoff b/scripts/mobile_device_management-android/hardware_management/turnandroiddevscreenoff deleted file mode 100755 index 4a2e823c..00000000 --- a/scripts/mobile_device_management-android/hardware_management/turnandroiddevscreenoff +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# turnandroiddevscreenoff -# -# Description: -# Turn an Android device screen off. -# - -readonly IS_SCREEN_ON="$(adb -d shell 'dumpsys power' | grep \ - 'mHoldingDisplaySuspendBlocker=')" - -if [[ "${IS_SCREEN_ON##*=}" = *'true'* ]]; then - adb -d shell 'input keyevent KEYCODE_POWER;' -fi - diff --git a/scripts/mobile_device_management-android/hardware_management/turnandroiddevscreenon b/scripts/mobile_device_management-android/hardware_management/turnandroiddevscreenon deleted file mode 100755 index b161f8e5..00000000 --- a/scripts/mobile_device_management-android/hardware_management/turnandroiddevscreenon +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# turnandroiddevscreenon -# -# Description: -# Turn an Android device screen on. -# - -readonly IS_SCREEN_ON="$(adb -d shell 'dumpsys power' | grep \ - 'mHoldingDisplaySuspendBlocker=')" - -if [[ "${IS_SCREEN_ON##*=}" = *'false'* ]]; then - adb -d shell 'input keyevent KEYCODE_POWER;' -fi - diff --git a/scripts/mobile_device_management-android/hardware_management/watchandroiddevscreentappos b/scripts/mobile_device_management-android/hardware_management/watchandroiddevscreentappos deleted file mode 100755 index e82105c9..00000000 --- a/scripts/mobile_device_management-android/hardware_management/watchandroiddevscreentappos +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# watchandroiddevscreentappos -# -# Description: -# Watch the X and Y screen tap positions of an Android device. -# -# Supplemental feature: -# Output is converted from hexidecimal to decimal. -# -# Usage: -# watchandroiddevscreentappos [seconds] -# -# [seconds]: (optional) number of seconds to watch for tap events -# - -# ======= CONFIGURATIONS ============== - -# Defult number of seconds to watch for tap events -readonly DEFAULT_WATCH_TIME=25 - -# ======= ! CONFIGURATIONS ============== - -if [ "$#" -ge 2 ]; then - watchTime="${2}" -else - watchTime="${DEFAULT_WATCH_TIME}" -fi - -hxecho() { - echo -n "$((16#"${1}"))" -} - -export -f hxecho - -timeout "${watchTime}" adb -d shell getevent -l /dev/input/event2 | sed \ - 's/\(.*ABS_MT_POSITION..[^0]*\)\(.*\)/echo -n "\1 "; hxecho \2/e' - diff --git a/scripts/mobile_device_management-generic/README.md b/scripts/mobile_device_management-generic/README.md deleted file mode 100644 index d57c451a..00000000 --- a/scripts/mobile_device_management-generic/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Mobile device management - generic - -## Mounting - -* [mntmtp](mounting/mntmtp): Mount and unmount an MTP device. - diff --git a/scripts/mobile_device_management-generic/mounting/mntmtp b/scripts/mobile_device_management-generic/mounting/mntmtp deleted file mode 100755 index 1bc2ffb7..00000000 --- a/scripts/mobile_device_management-generic/mounting/mntmtp +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# mntmtp -# -# Description: -# Mount and unmount an MTP device. -# -# Usage: -# mntmtp -# -# : -# "mount" or "m" to mount -# "umount" or "u" to unmount -# -# Dependencies: -# jmtpfs -# -# Set up: -# Create user group "fuse" and add the current system user to it by running -# the following commands: -# sudo groupadd fuse -# sudo gpasswd -a "${USER}" fuse -# -# Note: -# This has only been tested with Android devices. -# - -# ======= CONFIGURATIONS ============== - -# Mountpoint path of MTP device -MNTPNT_PATH='/mnt/mtp' - -# ======= ! CONFIGURATIONS ============== - -if [ "$#" -eq 0 ]; then - echo 'mntmtp: no arguments: "mount", "unmount", "m" or "u" required' 1>&2 - exit 1 -fi - -case "${1}" in - 'mount' | 'm') - if [ ! -d "${MNTPNT_PATH}" ]; then - mkdir "${MNTPNT_PATH}" - fi - - if ! mount | grep "${MNTPNT_PATH}" >/dev/null; then - jmtpfs "${MNTPNT_PATH}" - - if mount | grep "${MNTPNT_PATH}" >/dev/null; then - # newline prepended to separate message from jmtpfs output - echo -e "\nmntmtp: successfully mounted device on ${MNTPNT_PATH}" - fi - fi - ;; - - 'unmount' | 'u') - if ! mountpoint "${MNTPNT_PATH}" >/dev/null; then - echo "mntmtp: device not mounted on ${MNTPNT_PATH}" 1>&2 - exit 1 - fi - if [[ "$PWD" = "${MNTPNT_PATH}"* ]]; then - echo "mntmtp: must leave mountpoint directory" 1>&2 - exit 1 - fi - - fusermount -u "${MNTPNT_PATH}" - - if [ "$?" -eq 0 ] && ! mount | grep "${MNTPNT_PATH}" >/dev/null; then - echo "mntmtp: successfully unmounted device from ${MNTPNT_PATH}" - fi - ;; - - *) - echo 'mntmtp: action unknown: "mount", "unmount", "m" or "u" required' 1>&2 - exit 1 - ;; -esac - diff --git a/scripts/network_management-output_only/README.md b/scripts/network_management-output_only/README.md deleted file mode 100644 index f329d362..00000000 --- a/scripts/network_management-output_only/README.md +++ /dev/null @@ -1,11 +0,0 @@ - -# Network management - output only - -## Internet information - -* [connectedtointernet](internet_information/connectedtointernet): Check if connected to the internet. - -## Local area network information - -* [connectedtonetwork](local_area_network_information/connectedtonetwork): Check if connected to a network. - diff --git a/scripts/network_management-output_only/internet_information/connectedtointernet b/scripts/network_management-output_only/internet_information/connectedtointernet deleted file mode 100755 index f2c902c4..00000000 --- a/scripts/network_management-output_only/internet_information/connectedtointernet +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# connectedtointernet -# -# Description: -# Check if connected to the internet. -# -# Source: -# https://stackoverflow.com/a/932187/8031513 -# - -# ping the default gateway -if $(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" &>/dev/null) -then - exit 0 -fi - -exit 1 - diff --git a/scripts/network_management-output_only/local_area_network_information/connectedtonetwork b/scripts/network_management-output_only/local_area_network_information/connectedtonetwork deleted file mode 100755 index 4d2c4a1c..00000000 --- a/scripts/network_management-output_only/local_area_network_information/connectedtonetwork +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# connectedtonetwork -# -# Description: -# Check if connected to a network. -# -# Dependencies: -# networkmanager -# - -NETWORK_CONNECTED_STATUS="$(nmcli g | sed -n 's/\(connected\).*/\1/p')" - -if [ "${NETWORK_CONNECTED_STATUS}" = 'connected' ]; then - exit 0 -else - exit 1 -fi - diff --git a/scripts/shell_management-modules/README.md b/scripts/shell_management-modules/README.md deleted file mode 100644 index 61160585..00000000 --- a/scripts/shell_management-modules/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Shell management - modules - -## Process management - -* [execinbg](process_management/execinbg): Execute a command in the background. - diff --git a/scripts/shell_management-modules/process_management/execinbg b/scripts/shell_management-modules/process_management/execinbg deleted file mode 100755 index 6621a91a..00000000 --- a/scripts/shell_management-modules/process_management/execinbg +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# execinbg -# -# Description: -# Execute a command in the background. -# -# Usage: -# execinbg -# -# Returns: -# The PID of the executed command or nothing if stdout points to a terminal. -# -# Source: -# (link is now dead) -# http://felixmilea.com/2014/12/running-bash-commands-background-properly/ -# -# Notes: -# This script "will remove the command from the shell’s job list and redirect -# all of its output to /dev/null unless a file descriptor other than a -# terminal is provided." -# -# Using this script has the following advantage over using the nohup command -# directly: -# The script works by putting together all the arguments as a string and -# evaluating it as a command. The script also checks stdout and stderr to -# see if they point to a terminal, and if they do, it will pass /dev/null -# instead, otherwise it will let the command inherit the specified stdout -# and stderr. -# - -if test -t 1; then - exec 1>/dev/null -fi -if test -t 2; then - exec 2>/dev/null -fi - -nohup "${@}" &>/dev/null & - -# Print the PID of the executed command so the caller can retrieve it. -echo "$!" - diff --git a/scripts/shell_management/README.md b/scripts/shell_management/README.md deleted file mode 100644 index b8ce1c91..00000000 --- a/scripts/shell_management/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -# Shell management - -## History management - -* [remvlastnentriesfrombashhist](history_management/remvlastnentriesfrombashhist): Remove the last N entries from the bash history. - diff --git a/scripts/shell_management/history_management/remvlastnbashhistentries b/scripts/shell_management/history_management/remvlastnbashhistentries deleted file mode 100644 index 623bbddc..00000000 --- a/scripts/shell_management/history_management/remvlastnbashhistentries +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# remvlastnentriesfrombashhist -# -# Description: -# Remove the last N entries from the bash history. -# -# Usage (script must be sourced for history command to work): -# source remvlastnentriesfrombashhist; _remvlastnentriesfrombashhist <1-100> -# -# Source: -# http://unix.stackexchange.com/a/65076 -# - -_remvlastnentriesfrombashhist() { - local numCurrHistEntries="$(history | wc -l)" - - if [ "$#" -eq 0 ]; then - echo -e 'remvlastnentriesfrombashhist: no argument' 1>&2 - return 1 - elif [[ ! "${1}" =~ ^[0-9]+$ || "${1}" -lt 1 || "${1}" -gt 100 ]]; then - echo -e 'remvlastnentriesfrombashhist: invalid argument; must be a'\ - ' number\n between 1 and 100 (inclusive)' 1>&2 - return 1 - fi - - local count="${1}" - local start=$((numCurrHistEntries - count)) - - while [ "${count}" -ge 0 ]; do - history -d "${start}" - ((count--)) - done -} - diff --git a/scripts/shell_management/history_management/remvlastnentriesfrombashhist b/scripts/shell_management/history_management/remvlastnentriesfrombashhist deleted file mode 100755 index e385413e..00000000 --- a/scripts/shell_management/history_management/remvlastnentriesfrombashhist +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# remvlastnentriesfrombashhist -# -# Description: -# Remove the last N entries from the bash history. -# -# Usage (script must be sourced for history command to work): -# source remvlastnentriesfrombashhist; _remvlastnentriesfrombashhist <1-100> -# -# Source: -# http://unix.stackexchange.com/a/65076 -# - -_remvlastnentriesfrombashhist() { - local numCurrHistEntries="$(history | wc -l)" - - if [ "$#" -eq 0 ]; then - echo -e 'remvlastnentriesfrombashhist: no argument' 1>&2 - return 1 - elif [[ ! "${1}" =~ ^[0-9]+$ || "${1}" -lt 1 || "${1}" -gt 100 ]]; then - echo -e 'remvlastnentriesfrombashhist: invalid argument; must be a number\n'\ - ' between 1 and 100 (inclusive)' 1>&2 - return 1 - fi - - local count="${1}" - local start=$((numCurrHistEntries - count)) - - while [ "${count}" -ge 0 ]; do - history -d "${start}" - ((count--)) - done -} - diff --git a/scripts/text_manipulation/README.md b/scripts/text_manipulation/README.md deleted file mode 100644 index b93065d9..00000000 --- a/scripts/text_manipulation/README.md +++ /dev/null @@ -1,11 +0,0 @@ - -# Text manipulation - -## Matching - -* [replrecr](matching/replrecr): Replace all occurrences of a string recursively. - -## X11 - -* [changexseltextcase](x11/changexseltextcase): Change the case of the selected text. - diff --git a/scripts/text_manipulation/matching/replrecr b/scripts/text_manipulation/matching/replrecr deleted file mode 100755 index d51baf5e..00000000 --- a/scripts/text_manipulation/matching/replrecr +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# replrecr -# -# Description: -# Replace all occurrences of a string recursively. -# -# Supplemental feature: -# This solution allows a backup directory of the directories in which it is -# run to be created. -# -# Usage: -# replrecr -# -# Notes: -# All characters in both arguments are accepted as literals. -# - -# ======= CONFIGURATIONS ============== - -# Backup the directory in which this script is run. -readonly BACKUP=true - -# Directory where backup directories are created -readonly BACKUPS_DIR="${HOME}/.unixfoundation/shell/replrecr-backups/" - -# ======= ! CONFIGURATIONS ============== - -if [ "$#" -ne 2 ]; then - echo 'replrecr: invalid number of arguments' 1>&2 - exit 1 -elif [ -z "${1}" ]; then - echo 'replrecr: first argument empty' 1>&2 - exit 1 -fi - -if [ "${BACKUP}" != 'false' ]; then - if [ ! -d "${BACKUPS_DIR}" ]; then - mkdir -p "${BACKUPS_DIR}" - fi - - cp -R "$PWD" "${BACKUPS_DIR}" -fi - -ARGS[0]="$(echo "${1}" | sed 's/[]\/$*.^|[]/\\&/g')" -ARGS[1]="$(echo "${2}" | sed 's/[\/&]/\\&/g')" - -find . -type f -print0 | xargs -0 sed -i "s/${ARGS[0]}/${ARGS[1]}/g" - diff --git a/scripts/text_manipulation/x11/changexseltextcase b/scripts/text_manipulation/x11/changexseltextcase deleted file mode 100755 index 73b19eb5..00000000 --- a/scripts/text_manipulation/x11/changexseltextcase +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# changexseltextcase -# -# Description: -# Change the case of the selected text. -# -# Usage: -# changexseltextcase (--upper | --lower) -# -# Notes: -# This utility should be used with a keybinding or in a script. -# -# If the text is not being converted, increase the usleep time in the xte -# command. -# - -case "${1}" in - '--upper'|'--lower') - readonly MODE="${1}" - ;; - *) - # output errors as a desktop notification since this script is meant to be - # used with a keybinding and errors printed to stderr will not be seen. - msg='Mode not specified or invalid; must use option\n--upper or --lower' - notify-send 'changecase (err)' "${msg}" - exit 1 - ;; -esac - -readonly PREV_CLIPBOARD_CONTENT="$(xclip -o -selection c)" - -# use "xclip -out -selection primary" instead of "xsel" as it causes the -# selected text to be unselected in some applications. -readonly SEL_TEXT="$(xclip -out -selection primary)" - -if [ "${MODE}" = '--upper' ]; then - chngdCase="$(echo -n "${SEL_TEXT}" | tr '[:lower:]' '[:upper:]')" -else - chngdCase="$(echo -n "${SEL_TEXT}" | tr '[:upper:]' '[:lower:]')" -fi - -echo -n "${chngdCase}" | xclip -selection c -xte 'usleep 200000' 'keydown Control_L' 'key v' 'keyup Control_L' - -# Must sleep before restoring the clipboard content because otherwise the -# keyevents will run after, causing it to get pasted instead. -(sleep .1 && echo -n "${PREV_CLIPBOARD_CONTENT}" | xclip -selection c) & - diff --git a/scripts/x11_management-output_only/README.md b/scripts/x11_management-output_only/README.md deleted file mode 100644 index e6c4c89f..00000000 --- a/scripts/x11_management-output_only/README.md +++ /dev/null @@ -1,26 +0,0 @@ - -# X11 management - output only - -## Window property information - -* [getactvwindclass](window_property_information/getactvwindclass): Get the class of the active window. -* [getactvwindid](window_property_information/getactvwindid): Get the ID of the active window. -* [getactvwindname](window_property_information/getactvwindname): Get the name of the active window. -* [getactvwindpid](window_property_information/getactvwindpid): Get the PID of the active window. -* [getfirstwindidinclass](window_property_information/getfirstwindidinclass): Get the ID of the first active window in a class. -* [getfirstwindnameinclass](window_property_information/getfirstwindnameinclass): Get the name of the first active window in a class. -* [getnextwindidinactvclass](window_property_information/getnextwindidinactvclass): Get the ID of the next active window in the class of the active window. -* [getwindclassbyid](window_property_information/getwindclassbyid): Get the class of a window by ID. -* [getwindclassbyname](window_property_information/getwindclassbyname): Get the class of a window by name. -* [getwindidbyname](window_property_information/getwindidbyname): Get the ID of a window by name. -* [getwindidbypid](window_property_information/getwindidbypid): Get the ID of a window by PID (if the process has a window). -* [getwindidbypid2](window_property_information/getwindidbypid2): Get the ID of a window by PID (if the process has a window) (2). -* [getwindidsinclass](window_property_information/getwindidsinclass): Get the IDs of all windows in a class. -* [getwindnamebyid](window_property_information/getwindnamebyid): Get the name of a window by ID. -* [getwindnamesinclass](window_property_information/getwindnamesinclass): Get the names of all windows in a class. -* [getwindpidbyid](window_property_information/getwindpidbyid): Get the PID of a window by ID. - -## Window state information - -* [iswindopen](window_state_information/iswindopen): Check if a window is open by name or class. - diff --git a/scripts/x11_management-output_only/window_property_information/getactvwindclass b/scripts/x11_management-output_only/window_property_information/getactvwindclass deleted file mode 100755 index ea704162..00000000 --- a/scripts/x11_management-output_only/window_property_information/getactvwindclass +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getactvwindclass -# -# Description: -# Get the class of the active window. -# -# Returns: -# Full qualified class string (class and classname; e.g. "xterm.XTerm")) of -# window -# - -getActvWindId() { - echo "$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5 | rev | cut -c 2- | \ - rev | sed 's/^0x/0x0/')" -} - -getWindClassById() { - echo "$(xprop -id "${1}" WM_CLASS | sed -n \ - 's/[^"]*"\([^"]*\)",\s"\([^"]*\)"/\1.\2/p')" -} - -echo "$(getWindClassById "$(getActvWindId)")" - diff --git a/scripts/x11_management-output_only/window_property_information/getactvwindid b/scripts/x11_management-output_only/window_property_information/getactvwindid deleted file mode 100755 index 94b0c221..00000000 --- a/scripts/x11_management-output_only/window_property_information/getactvwindid +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getactvwindid -# -# Description: -# Get the ID of the active window. -# - -WINDOW_ID="$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5 | rev | cut -c \ - 2- | rev | sed 's/^0x/0x0/')" - -echo "${WINDOW_ID}" - diff --git a/scripts/x11_management-output_only/window_property_information/getactvwindname b/scripts/x11_management-output_only/window_property_information/getactvwindname deleted file mode 100755 index 6f1503a7..00000000 --- a/scripts/x11_management-output_only/window_property_information/getactvwindname +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getactvwindname -# -# Description: -# Get the name of the active window. -# - -getActvWindId() { - echo "$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5 | rev | cut -c 2- | \ - rev | sed 's/^0x/0x0/')" -} - -WINDOW_NAME="$(xprop -id "$(getActvWindId)" WM_NAME | sed -e \ - 's/.*"\(.*\)".*/\1/')" - -echo "${WINDOW_NAME}" - diff --git a/scripts/x11_management-output_only/window_property_information/getactvwindpid b/scripts/x11_management-output_only/window_property_information/getactvwindpid deleted file mode 100755 index d6e54b68..00000000 --- a/scripts/x11_management-output_only/window_property_information/getactvwindpid +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getactvwindpid -# -# Description: -# Get the PID of the active window. -# - -getActvWindId() { - echo "$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5 | rev | cut -c 2- | \ - rev | sed 's/^0x/0x0/')" -} - -getWindPidById() { - echo "$(xprop -id "${1}" | awk '/_NET_WM_PID/ {print $3}')" -} - -echo "$(getWindPidById $(getActvWindId))" - diff --git a/scripts/x11_management-output_only/window_property_information/getfirstwindidinclass b/scripts/x11_management-output_only/window_property_information/getfirstwindidinclass deleted file mode 100755 index 6d44e43f..00000000 --- a/scripts/x11_management-output_only/window_property_information/getfirstwindidinclass +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getfirstwindidinclass -# -# Description: -# Get the ID of the first active window in a class. -# -# Options: -# -n [name] return only IDs of windows with titles partially matched by -# [name] -# -# Usage: -# getfirstwindidinclass -# -# : case-sensitive; can match any part of the full qualified -# class string (i.e. class and classname; e.g. "xterm.XTerm") -# - -while getopts n: OPT; do - case "${OPT}" in - n) OPT_WIND_NAME="${OPTARG}" - ;; - esac -done -shift $((OPTIND - 1)) - -if [ "$#" -eq 0 ]; then - exit 1 -fi - -getWindIdsInClass() { - echo "$(wmctrl -lx | awk -v class="${1}" -v name="${OPT_WIND_NAME}" \ - '{windId = $1; classFld = $3}; $1=$2=$3=$4=""; classFld ~ class && $0 ~ \ - name {print windId}')" -} - -CLASS_WIND_IDS=($(getWindIdsInClass "${1}")) - -if [ ${#CLASS_WIND_IDS[@]} -eq 0 ]; then - exit -fi - -echo "${CLASS_WIND_IDS[0]}" - diff --git a/scripts/x11_management-output_only/window_property_information/getfirstwindnameinclass b/scripts/x11_management-output_only/window_property_information/getfirstwindnameinclass deleted file mode 100755 index 95e1e4b6..00000000 --- a/scripts/x11_management-output_only/window_property_information/getfirstwindnameinclass +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getfirstwindnameinclass -# -# Description: -# Get the name of the first active window in a class. -# -# Usage: -# getfirstwindnameinclass -# -# : case-sensitive; can match any part of the full qualified -# class string (i.e. class and classname; e.g. "xterm.XTerm") -# - -if [ "$#" -eq 0 ]; then - exit 1 -fi - -getWindNamesInClass() { - echo "$(wmctrl -lx | awk '{printf "%s", $3; $1=$2=$3=$4=""; print $0}' | awk \ - -v class="${1}" '$1 ~ class {$1=""; sub(/^[ \t]+/, "", $0); print $0}')" -} - -IFS=$'\n' -CLASS_WIND_NAMES=($(getWindNamesInClass "${1}")) -unset IFS - -if [ ${#CLASS_WIND_NAMES[@]} -eq 0 ]; then - exit -fi - -echo "${CLASS_WIND_NAMES[0]}" - diff --git a/scripts/x11_management-output_only/window_property_information/getnextwindidinactvclass b/scripts/x11_management-output_only/window_property_information/getnextwindidinactvclass deleted file mode 100755 index a0559128..00000000 --- a/scripts/x11_management-output_only/window_property_information/getnextwindidinactvclass +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getnextwindidinactvclass -# -# Description: -# Get the ID of the next window in the class of the active window. -# -# Options: -# -n [name] return only IDs of windows with titles partially matched by -# [name] -# -# Returns: -# ID of the next window in class; ID of the active window if no other windows -# in the class exist -# - -while getopts n: OPT; do - case "${OPT}" in - n) OPT_WIND_NAME="${OPTARG}" - ;; - esac -done -shift $((OPTIND - 1)) - -getActvWindId() { - echo "$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5 | rev | cut -c 2- | \ - rev | sed 's/^0x/0x0/')" -} - -ACTV_WIND_ID="$(getActvWindId)" - -getWindIdsInClass() { - echo "$(wmctrl -lx | awk -v class="${1}" '$3 ~ class {print $1}')" -} - -getWindClassById() { - echo "$(xprop -id "${1}" WM_CLASS | sed -n \ - 's/[^"]*"\([^"]*\)",\s"\([^"]*\)"/\1.\2/p')" -} - -CLASS_WIND_IDS=($(getWindIdsInClass "$(getWindClassById "${ACTV_WIND_ID}")")) - -if [ -n "${OPT_WIND_NAME}" ]; then - getWindNameById() { - echo "$(xprop -id "${1}" WM_NAME 2>/dev/null | sed -n \ - 's/[^"]*"\(.*\)./\1/p')" - } - - for windId in "${CLASS_WIND_IDS[@]}"; do - windName="$(getWindNameById "${windId}")" - if [[ "${windName}" = *"${OPT_WIND_NAME}"* ]]; then - clssWindIdsTmp+=("${windId}") - fi - done - - CLASS_WIND_IDS=("${clssWindIdsTmp[@]}") -fi - -for indx in ${!CLASS_WIND_IDS[@]}; do - if [ "${CLASS_WIND_IDS[${indx}]}" = "${ACTV_WIND_ID}" ]; then - clssWindIdsActvWindIdPos="${indx}" - break - fi -done - -if [ "${clssWindIdsActvWindIdPos}" -eq $(("${#CLASS_WIND_IDS[@]}" - 1)) ]; then - echo "${CLASS_WIND_IDS[0]}" -else - echo "${CLASS_WIND_IDS[$((clssWindIdsActvWindIdPos + 1))]}" -fi - diff --git a/scripts/x11_management-output_only/window_property_information/getwindclassbyid b/scripts/x11_management-output_only/window_property_information/getwindclassbyid deleted file mode 100755 index 95668d5a..00000000 --- a/scripts/x11_management-output_only/window_property_information/getwindclassbyid +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getwindclassbyid -# -# Description: -# Get the class of a window by ID. -# -# Usage: -# getwindclassbyid -# -# Returns: -# Full qualified class string (i.e. class and classname; e.g. "xterm.XTerm")) -# of window -# - -if [ "$#" -eq 0 ]; then - exit 1 -elif [[ ! "${1}" =~ '0x'.* ]]; then - echo 'getwindclassbyid: argument not in hexidecimal format' 1>&2 - exit 1 -fi - -WINDOW_CLASS="$(xprop -id "${1}" WM_CLASS 2>/dev/null | sed -n \ - 's/[^"]*"\([^"]*\)",\s"\([^"]*\)"/\1.\2/p')" - -if [ -n "${WINDOW_CLASS}" ]; then - echo "${WINDOW_CLASS}" -fi - diff --git a/scripts/x11_management-output_only/window_property_information/getwindclassbyname b/scripts/x11_management-output_only/window_property_information/getwindclassbyname deleted file mode 100755 index c2f948fe..00000000 --- a/scripts/x11_management-output_only/window_property_information/getwindclassbyname +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getwindclassbyname -# -# Description: -# Get the class of a window by name. -# -# Usage: -# getwindclassbyname -# -# : case-sensitive; matched partially -# -# Returns: -# Full qualified class string (i.e. class and classname; e.g. "xterm.XTerm") -# of window; multiple class strings separated by a newline if more than one -# class exists -# - -if [ "$#" -eq 0 ]; then - exit 1 -fi - -WINDOW_CLASSES=("$(wmctrl -lx | awk -v srchTxt="${1}" '{$1=$2=$4=""; wn = \ - gensub(/([^ ]+[ ]+)(.*)/, "\\2", "g", $0); gsub(/ /, "", wn)} wn ~ srchTxt \ - {print $3}' | sort | uniq)") - -if [ "${#WINDOW_CLASSES[@]}" -gt 0 ] && [ -n "${WINDOW_CLASSES[0]}" ]; then - echo "${WINDOW_CLASSES[@]}" -fi - diff --git a/scripts/x11_management-output_only/window_property_information/getwindidbyname b/scripts/x11_management-output_only/window_property_information/getwindidbyname deleted file mode 100755 index efcfe1b1..00000000 --- a/scripts/x11_management-output_only/window_property_information/getwindidbyname +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getwindidbyname -# -# Description: -# Get the ID of a window by name. -# -# Usage: -# getwindidbyname -# -# : case-sensitive; matched partially -# -# Returns: -# window ID; multiple IDs if more than one window is matched -# - -if [ "$#" -eq 0 ]; then - exit 1 -fi - -WINDOW_IDS=("$(wmctrl -l | awk -v srchTxt="${1}" '{$2=$3=""; wn = \ - gensub(/([^ ]*[ ]+)(.*)/, "\\2", "g", $0)} wn ~ srchTxt {print $1}')") - -if [ "${#WINDOW_IDS[@]}" -gt 0 ] && [ -n "${WINDOW_IDS[0]}" ]; then - echo "${WINDOW_IDS[@]}" -fi - diff --git a/scripts/x11_management-output_only/window_property_information/getwindidbypid b/scripts/x11_management-output_only/window_property_information/getwindidbypid deleted file mode 100755 index e7f243fc..00000000 --- a/scripts/x11_management-output_only/window_property_information/getwindidbypid +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getwindidbypid -# -# Description: -# Get the ID of a window by PID (if the process has a window). -# -# Usage: -# getwindidbypid -# - -if [ "$#" -eq 0 ] || [[ ! "${1}" =~ ^[0-9]+$ ]]; then - exit 1 -fi - -while IFS= read line; do - if [[ "${line}" =~ (0x)([0-9a-z]+)([ ][- ][0-9]+[ ])([0-9]*) ]]; then - winId="${BASH_REMATCH[1]}${BASH_REMATCH[2]}" - pid="${BASH_REMATCH[4]}" - - if [ "${pid}" -eq "${1}" ]; then - WIND_IDS+=("${winId}") - fi - fi -done < <(wmctrl -lp) - -if [ "${#WIND_IDS[@]}" -gt 0 ]; then - echo "${WIND_IDS[@]}" -fi - diff --git a/scripts/x11_management-output_only/window_property_information/getwindidbypid2 b/scripts/x11_management-output_only/window_property_information/getwindidbypid2 deleted file mode 100755 index 96202798..00000000 --- a/scripts/x11_management-output_only/window_property_information/getwindidbypid2 +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env perl -# -# File: -# getwindidbypid -# -# Description: -# Get the ID of a window by PID (if the process has a window) (2). -# -# Usage: -# getwindidbypid -# - -use strict; -use warnings; - -if (scalar @ARGV != 1) { - exit 1; -} elsif ($ARGV[0] !~ m/^[0-9]+$/) { - exit 1; -} - -my $ARG_PID = $ARGV[0]; -my @WMCTRL_OUT = `wmctrl -lp`; -my @WIND_IDS; - -for my $line (@WMCTRL_OUT) { - if ($line =~ m/0x([0-9a-z]+)(?:\s[- ][0-9]+\s)([0-9]*)/) { - my ($winid, $pid) = ($1, $2); - if ($pid == $ARG_PID) { - push @WIND_IDS, '0x'.$winid; - } - } -} - -if (scalar @WIND_IDS > 0) { - print join(" ", @WIND_IDS)."\n"; -} - diff --git a/scripts/x11_management-output_only/window_property_information/getwindidsinclass b/scripts/x11_management-output_only/window_property_information/getwindidsinclass deleted file mode 100755 index 53ab243c..00000000 --- a/scripts/x11_management-output_only/window_property_information/getwindidsinclass +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getwindidsinclass -# -# Description: -# Get the IDs of all windows in a class. -# -# Usage: -# getwindidsinclass -# -# : case-sensitive; can match any part of the full qualified -# class string (class and classname; e.g. "xterm.XTerm") -# -# Returns: -# Window IDs in hexidecimal format separated by a space -# - -if [ "$#" -eq 0 ]; then - exit 1 -fi - -WINDOW_IDS=($(wmctrl -lx | awk -v class="${1}" '$3 ~ class {print $1}')) - -if [ "${#WINDOW_IDS[@]}" -gt 0 ]; then - echo "${WINDOW_IDS[@]}" -fi - diff --git a/scripts/x11_management-output_only/window_property_information/getwindnamebyid b/scripts/x11_management-output_only/window_property_information/getwindnamebyid deleted file mode 100755 index c12543f6..00000000 --- a/scripts/x11_management-output_only/window_property_information/getwindnamebyid +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getwindnamebyid -# -# Description: -# Get the name of a window by ID. -# -# Usage: -# getwindnamebyid -# -# : must be in hexidecimal format -# - -if [ "$#" -eq 0 ]; then - exit 1 -elif [[ ! "${1}" =~ '0x'.* ]]; then - echo 'getwindnamebyid: argument not in hexidecimal format' 1>&2 - exit 1 -fi - -WINDOW_NAME="$(xprop -id "${1}" WM_NAME 2>/dev/null | sed -n \ - 's/[^"]*"\(.*\)./\1/p')" - -if [ -n "${WINDOW_NAME}" ]; then - echo "${WINDOW_NAME}" -fi - diff --git a/scripts/x11_management-output_only/window_property_information/getwindnamesinclass b/scripts/x11_management-output_only/window_property_information/getwindnamesinclass deleted file mode 100755 index 7a6b3c6c..00000000 --- a/scripts/x11_management-output_only/window_property_information/getwindnamesinclass +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getwindnamesinclass -# -# Description: -# Get the names of all windows in a class. -# -# Usage: -# getwindnamesinclass -# -# : case-sensitive; can match any part of the full qualified -# class string (i.e. class and classname; e.g. "xterm.XTerm") -# - -if [ "$#" -eq 0 ]; then - exit 1 -fi - -WIND_NAMES=("$(wmctrl -lx | awk \ - '{printf "%s", $3; $1=$2=$3=$4=""; print $0}' | awk -v class="${1}" \ - '$1 ~ class {$1=""; sub(/^[ \t]+/, "", $0); print $0}')") - -if [ "${#WIND_NAMES[@]}" -gt 0 ] && [ -n "${WIND_NAMES[0]}" ]; then - echo "${WIND_NAMES[@]}" -fi - diff --git a/scripts/x11_management-output_only/window_property_information/getwindpidbyid b/scripts/x11_management-output_only/window_property_information/getwindpidbyid deleted file mode 100755 index 48da0d4b..00000000 --- a/scripts/x11_management-output_only/window_property_information/getwindpidbyid +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# getwindpidbyid -# -# Description: -# Get the PID of a window by ID. -# -# Usage: -# getwindpidbyid -# -# : must be in hexidecimal format -# - -if [ "$#" -eq 0 ]; then - exit 1 -elif [[ ! "${1}" =~ '0x'.* ]]; then - echo 'getwindpidbyid: argument not in hexidecimal format' 1>&2 - exit 1 -fi - -PID="$(xprop -id "${1}" 2>/dev/null | awk '/_NET_WM_PID/ {print $3}')" - -if [ -n "${PID}" ]; then - echo "${PID}" -fi - diff --git a/scripts/x11_management-output_only/window_state_information/iswindopen b/scripts/x11_management-output_only/window_state_information/iswindopen deleted file mode 100755 index f39a84d6..00000000 --- a/scripts/x11_management-output_only/window_state_information/iswindopen +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash -# -# File: -# iswindopen -# -# Description: -# Check if a window is open by name or class. -# -# Usage: -# iswindopen -# -# : case-sensitive; may contain regex -# -# Options: -# -c check if a window is open by class instead of by name (case-sensitive; -# class can be specified using the full qualified class string [i.e. -# class and classname; e.g. "xterm.XTerm"]; does not allow regex) -# -# Exit codes: -# 0: window is open -# 1: window is not open -# 2: no arguments error -# - -if [ "$#" -eq 0 ]; then - exit 2 -fi - -while getopts :c OPT; do - case "${OPT}" in - c) OPT_CLASS=true;; - esac -done -shift $((OPTIND - 1)) - -getWindIdsInClass() { - echo "$(wmctrl -lx | awk -v class="${1}" '$3 ~ class {print $1}')" -} - -if [ "${OPT_CLASS}" = 'true' ]; then - if [ -n "$(getWindIdsInClass "${1}")" ]; then - isWindOpen=true - fi -else - while IFS= read wind; do - if echo "${wind}" | grep -q "${1}"; then - isWindOpen=true - fi - done < <(wmctrl -l | awk '{$1=$2=$3=""; print $0}' | sed 's/^[ \t]*//') -fi - -if [ "${isWindOpen}" = 'true' ]; then - exit 0 -fi - -exit 1 - pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy