├── .circleci
└── config.yml
├── CHANGELOG.md
├── ISSUE_TEMPLATE.md
├── LICENSE
├── README.rst
├── auto-notify.plugin.zsh
├── img
└── notification-example.png
└── tests
├── test_auto_notify_format.zunit
├── test_auto_notify_send.zunit
├── test_is_auto_notify_ignored.zunit
└── test_plugin.zunit
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 |
3 |
4 | test: &test
5 | steps:
6 | - checkout
7 | - run:
8 | name: Install Dependencies
9 | command: apt-get update && apt-get install -y curl git ncurses-bin libnotify-bin
10 | - run:
11 | name: Download requirements
12 | command: |
13 | mkdir -p ~/bin
14 | curl -L https://raw.githubusercontent.com/molovo/revolver/master/revolver > ~/bin/revolver
15 | curl -L https://github.com/molovo/zunit/releases/download/v0.8.2/zunit > ~/bin/zunit
16 | chmod u+x ~/bin/{revolver,zunit}
17 | - run:
18 | name: Run Zunit
19 | command: |
20 | export TERM="xterm-256color"
21 | export PATH="$HOME/bin:$PATH"
22 | zunit --verbose
23 |
24 |
25 | jobs:
26 | lint:
27 | docker:
28 | - image: "python:3.11"
29 | steps:
30 | - checkout
31 | - run:
32 | name: run restructuredtext linter
33 | command: |
34 | pip install restructuredtext_lint
35 | rst-lint *.rst
36 |
37 | test-zsh-5.1:
38 | docker:
39 | - image: "zshusers/zsh:5.1.1"
40 | <<: *test
41 |
42 | test-zsh-5.2:
43 | docker:
44 | - image: "zshusers/zsh:5.2"
45 | <<: *test
46 |
47 | test-zsh-5.3:
48 | docker:
49 | - image: "zshusers/zsh:5.3.1"
50 | <<: *test
51 |
52 | test-zsh-5.4:
53 | docker:
54 | - image: "zshusers/zsh:5.4.2"
55 | <<: *test
56 |
57 | test-zsh-5.5:
58 | docker:
59 | - image: "zshusers/zsh:5.5.1"
60 | <<: *test
61 |
62 | test-zsh-5.6:
63 | docker:
64 | - image: "zshusers/zsh:5.6.2"
65 | <<: *test
66 |
67 | workflows:
68 | version: 2
69 | test:
70 | jobs:
71 | - lint
72 | - test-zsh-5.1
73 | - test-zsh-5.2
74 | - test-zsh-5.3
75 | - test-zsh-5.4
76 | - test-zsh-5.5
77 | - test-zsh-5.6
78 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Changelog for zsh-auto-notify
2 | =============================
3 |
4 | 0.11.1
5 | ------
6 | * Thank you to @devnoname120 for this release
7 | * Add support to MACOS for control of notifications on SIGINT
8 |
9 | 0.11.0
10 | ------
11 | * thankyou to @tommyhaley for the contributions in this release
12 | * Support forwarding notifications over SSH
13 | * Add options for
14 | * controlling notification history persistence
15 | * control behaviour of notifications on SIGINT
16 |
17 | 0.10.2
18 | ------
19 | * Use preferable array argument expansion for flexible parameters
20 |
21 | 0.10.1
22 | ------
23 | * Fix regression where not setting icon on Linux would cause issues (#59 #58)
24 |
25 | 0.10.0
26 | -----
27 | * Allow specifying an icon with notify-send backends
28 |
29 | 0.8.0
30 | -----
31 | * Change notify-send application title to `zsh`
32 |
33 | 0.7.0
34 | -----
35 | * Allow alternate `AUTO_NOTIFY_WHITELIST` for specifying commands to allow
36 |
37 | 0.6.0
38 | -----
39 | * Display warning and disable auto-notify if notify-send is not installed (Linux only)
40 |
41 | 0.5.1
42 | -----
43 | * Improved handling of MacOS notifications via #16 (Thanks @dmitmel!)
44 |
45 | 0.5.0
46 | -----
47 | * Support changing notification title and body using AUTO_NOTIFY_TITLE and AUTO_NOTIFY_BODY
48 |
49 | 0.4.0
50 | -----
51 | * Add `AUTO_NOTIFY_EXPIRE_TIME` configuration option
52 | * Improvements to notification formatting
53 | * Exit code is now displayed in notifications
54 | * Notifications on linux now show as critical if long command exits with non-zero exit code
55 |
56 | 0.3.0
57 | -----
58 | * Add support for environments where standard history is disabled. Fixed in #10
59 |
60 | 0.2.0
61 | -----
62 | * Initial stable release
63 |
--------------------------------------------------------------------------------
/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | # Issue Details
2 |
3 | Please provide the following details when opening an issue:
4 |
5 | ## Operating System (uname -a)
6 |
7 | ## zsh version (zsh --version)
8 |
9 | ## auto-notify version (echo "$AUTO_NOTIFY_VERSION")
10 |
11 | ## How is auto-notify installed?
12 |
13 | - [ ] zplug
14 | - [ ] oh-my-zsh
15 | - [ ] Antigen
16 | - [ ] Other (please specify)
17 |
18 | ## Steps to reproduce the issue
19 |
20 | ## gist link to your zshrc
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 |
3 | Version 3, 29 June 2007
4 |
5 | Copyright © 2007 Free Software Foundation, Inc.
6 |
7 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The GNU General Public License is a free, copyleft license for software and other kinds of works.
12 |
13 | 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.
14 |
15 | 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.
16 |
17 | 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.
18 |
19 | 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.
20 |
21 | 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.
22 |
23 | 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.
24 |
25 | 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.
26 |
27 | 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.
28 |
29 | The precise terms and conditions for copying, distribution and modification follow.
30 |
31 | TERMS AND CONDITIONS
32 |
33 | 0. Definitions.
34 |
35 | “This License” refers to version 3 of the GNU General Public License.
36 |
37 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
38 |
39 | “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.
40 |
41 | 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.
42 |
43 | A “covered work” means either the unmodified Program or a work based on the Program.
44 |
45 | 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.
46 |
47 | 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.
48 |
49 | 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.
50 |
51 | 1. Source Code.
52 |
53 | 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.
54 |
55 | 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.
56 |
57 | 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.
58 |
59 | 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.
60 |
61 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
62 |
63 | The Corresponding Source for a work in source code form is that same work.
64 |
65 | 2. Basic Permissions.
66 |
67 | 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.
68 |
69 | 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.
70 |
71 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
72 |
73 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
74 |
75 | 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.
76 |
77 | 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.
78 |
79 | 4. Conveying Verbatim Copies.
80 |
81 | 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.
82 |
83 | 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.
84 |
85 | 5. Conveying Modified Source Versions.
86 |
87 | 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:
88 |
89 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
90 | 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”.
91 | 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.
92 | 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.
93 | 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.
94 |
95 | 6. Conveying Non-Source Forms.
96 |
97 | 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:
98 |
99 | 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.
100 | 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.
101 | 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.
102 | 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.
103 | 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.
104 | 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.
105 |
106 | 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.
107 |
108 | “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.
109 |
110 | 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).
111 |
112 | 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.
113 |
114 | 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.
115 |
116 | 7. Additional Terms.
117 |
118 | “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.
119 |
120 | 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.
121 |
122 | 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:
123 |
124 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
125 | 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
126 | 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
127 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
128 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
129 | 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.
130 | 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.
131 |
132 | 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.
133 |
134 | 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.
135 |
136 | 8. Termination.
137 |
138 | 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).
139 |
140 | 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.
141 |
142 | 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.
143 |
144 | 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.
145 |
146 | 9. Acceptance Not Required for Having Copies.
147 |
148 | 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.
149 |
150 | 10. Automatic Licensing of Downstream Recipients.
151 |
152 | 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.
153 |
154 | 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.
155 |
156 | 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.
157 |
158 | 11. Patents.
159 |
160 | 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”.
161 |
162 | 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.
163 |
164 | 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.
165 |
166 | 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.
167 |
168 | 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.
169 |
170 | 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.
171 |
172 | 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.
173 |
174 | 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.
175 |
176 | 12. No Surrender of Others' Freedom.
177 |
178 | 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.
179 |
180 | 13. Use with the GNU Affero General Public License.
181 |
182 | 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.
183 |
184 | 14. Revised Versions of this License.
185 |
186 | 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.
187 |
188 | 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.
189 |
190 | 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.
191 |
192 | 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.
193 |
194 | 15. Disclaimer of Warranty.
195 |
196 | 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.
197 |
198 | 16. Limitation of Liability.
199 |
200 | 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.
201 |
202 | 17. Interpretation of Sections 15 and 16.
203 |
204 | 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.
205 |
206 | END OF TERMS AND CONDITIONS
207 |
208 | How to Apply These Terms to Your New Programs
209 |
210 | 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.
211 |
212 | 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.
213 |
214 |
215 | Copyright (C)
216 |
217 | This program is free software: you can redistribute it and/or modify
218 | it under the terms of the GNU General Public License as published by
219 | the Free Software Foundation, either version 3 of the License, or
220 | (at your option) any later version.
221 |
222 | This program is distributed in the hope that it will be useful,
223 | but WITHOUT ANY WARRANTY; without even the implied warranty of
224 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
225 | GNU General Public License for more details.
226 |
227 | You should have received a copy of the GNU General Public License
228 | along with this program. If not, see .
229 | Also add information on how to contact you by electronic and paper mail.
230 |
231 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
232 |
233 | Copyright (C)
234 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
235 | This is free software, and you are welcome to redistribute it
236 | under certain conditions; type `show c' for details.
237 | 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”.
238 |
239 | 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 .
240 |
241 | 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 .
242 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | ZSH Auto-Notify
2 | ===============
3 |
4 | |CircleCI| |Version| |GPLv3|
5 |
6 | Simple zsh plugin that automatically sends out a notification when a long running task
7 | has completed.
8 |
9 | Useful for those commands you don't predict will take long to run or just plain forgot
10 | to keep track of. Leave the task running and go do something else - ``auto-notify`` will
11 | let you know when the task is done! :tada:
12 |
13 | * Usage_
14 | * Requirements_
15 | * Installation_
16 | * Configuration_
17 | * `Temporarily Disabling Notifications`_
18 | * Contributing_
19 | * `Running Tests`_
20 |
21 | Usage
22 | -----
23 |
24 | You don't need to do anything. Once it's installed,
25 | ``zsh-auto-notify`` will let you know if a long running task has completed its work via a
26 | notification in your desktop environment.
27 |
28 | .. image:: img/notification-example.png
29 |
30 | Requirements
31 | ------------
32 |
33 | ``auto-notify`` officially supports zsh versions 5.1 onwards.
34 |
35 | It is possible the plugin might work on even older versions.
36 | However they would not have been tested as part of the CI test process.
37 |
38 | Supported desktop environments:
39 |
40 | * Linux X/Wayland (Requires ``notify-send`` to be installed)
41 | * MacOSX
42 |
43 | Installation
44 | ------------
45 |
46 | Add one of the following to your ``.zshrc`` file depending on your
47 | package manager:
48 |
49 | ZPlug_
50 |
51 | ::
52 |
53 | zplug "MichaelAquilina/zsh-auto-notify"
54 |
55 | Antigen_
56 |
57 | ::
58 |
59 | antigen bundle "MichaelAquilina/zsh-auto-notify"
60 |
61 | Zgen_
62 |
63 | ::
64 |
65 | zgen load "MichaelAquilina/zsh-auto-notify"
66 |
67 | Fig_
68 |
69 | Install ``zsh-auto-notify`` with Fig in just one click.
70 |
71 | .. image:: https://fig.io/badges/install-with-fig.svg
72 | :target: https://fig.io/plugins/other/zsh-auto-notify_MichaelAquilina
73 | :alt: Install with Fig
74 |
75 | oh-my-zsh_
76 |
77 | Copy this repository to ``$ZSH_CUSTOM/custom/plugins``, where ``$ZSH_CUSTOM``
78 | is the directory with custom plugins of oh-my-zsh `(read more) `_:
79 | ::
80 |
81 | git clone https://github.com/MichaelAquilina/zsh-auto-notify.git $ZSH_CUSTOM/plugins/auto-notify
82 |
83 |
84 | Then add this line to your ``.zshrc``. Make sure it is **before** the line ``source $ZSH/oh-my-zsh.sh``.
85 |
86 | ::
87 |
88 | plugins=(auto-notify $plugins)
89 |
90 |
91 | Configuration
92 | -------------
93 |
94 | **Notification Threshold**
95 |
96 | By default, ``auto-notify`` will send notifications for tasks that take longer than 10 seconds. You
97 | can configure this value by setting the environment variable ``AUTO_NOTIFY_THRESHOLD``:
98 |
99 | ::
100 |
101 | # Set threshold to 20seconds
102 | export AUTO_NOTIFY_THRESHOLD=20
103 |
104 | **Notification Formatting**
105 |
106 | You can change the formatting of notifications by setting the values for ``AUTO_NOTIFY_TITLE`` and
107 | ``AUTO_NOTIFY_BODY``. When writing these values, the following variables will be replaced according to
108 | the data that ``auto-notify`` has detected:
109 |
110 | * ``%command`` - the command that the user executed
111 | * ``%elapsed`` - number of seconds that elapsed
112 | * ``%exit_code`` - the exit code of the command that was executed
113 |
114 | An example of how these values can be set is shown below:
115 |
116 | ::
117 |
118 | export AUTO_NOTIFY_TITLE="Hey! %command has just finished"
119 | export AUTO_NOTIFY_BODY="It completed in %elapsed seconds with exit code %exit_code"
120 |
121 | **Notification Expiration Time**
122 |
123 | You can set how long a notification sent by ``auto-notify`` will remain showing by setting the environment
124 | variable ``AUTO_NOTIFY_EXPIRE_TIME`` to a custom value in milliseconds. The default value is set to 8 seconds.
125 | NOTE: This configuration option currently only works for Linux.
126 |
127 | ::
128 |
129 | # Set notification expiry to 10 seconds
130 | export AUTO_NOTIFY_EXPIRE_TIME=10000
131 |
132 | **Notification Forwarding Over SSH**
133 |
134 | You can configure whether notifications will be forwarded to SSH client by setting the environment
135 | variable ``AUTO_NOTIFY_ENABLE_SSH`` to enable ("1") or disable ("0"). The default value is set to 0.
136 | NOTE: This configuration option currently only works for Linux.
137 |
138 | ::
139 |
140 | # Enable notification forwarding to SSH client
141 | export AUTO_NOTIFY_ENABLE_SSH=1
142 | # Disable notification forwarding to SSH client
143 | export AUTO_NOTIFY_ENABLE_SSH=0
144 |
145 | **Notification Persistence in Notification History**
146 |
147 | You can configure whether notifications will persist in notification history by setting the environment
148 | variable ``AUTO_NOTIFY_ENABLE_TRANSIENT`` to enable ("1") or disable ("0"). The default value is set to 1.
149 | NOTE: This configuration option currently only works for Linux.
150 |
151 | ::
152 |
153 | # Enable persistent notifications
154 | export AUTO_NOTIFY_ENABLE_TRANSIENT=0
155 | # Disable persistent notifications
156 | export AUTO_NOTIFY_ENABLE_TRANSIENT=1
157 |
158 | **Notification Cancel on SIGINT**
159 |
160 | You can configure whether notifications will be cancelled when procees is terminated with SIGINT by setting the environment
161 | variable ``AUTO_NOTIFY_CANCEL_ON_SIGINT`` to enable ("1") or disable ("0"). The default value is set to 0.
162 |
163 | ::
164 |
165 | # Enable cancellation of notifications on SIGINT
166 | export AUTO_NOTIFY_CANCEL_ON_SIGINT=1
167 | # Disable cancellation of notifications on SIGINT
168 | export AUTO_NOTIFY_CANCEL_ON_SIGINT=0
169 |
170 |
171 | **Ignored Commands**
172 |
173 | A number of commands do not get notifications for long running times due to their nature (e.g. ``watch`` or ``man``).
174 | The list of ignored commands is specified in the ``AUTO_NOTIFY_IGNORE`` environment variable. This can be modified
175 | or completely overwritten based on your use case.
176 |
177 | ::
178 |
179 | # Add docker to list of ignored commands
180 | AUTO_NOTIFY_IGNORE+=("docker")
181 |
182 | Make sure that you append to the array above *after* your plugin manager has been loaded in your ``zshrc``.
183 |
184 | If you wish to completely redefine what is ignored and not ignored, then just set ``AUTO_NOTIFY_IGNORE`` to
185 | a new array.
186 |
187 | ::
188 |
189 | # redefine what is ignored by auto-notify
190 | export AUTO_NOTIFY_IGNORE=("docker" "man" "sleep")
191 |
192 | **Using a Whitelist to ignore commands**
193 |
194 | If you wish to use a whitelist approach instead of the default blacklist approach used by ``AUTO_NOTIFY_IGNORE``,
195 | you can do so by defining the environment variable ``AUTO_NOTIFY_WHITELIST`` with the elements you wish to
196 | allow ``auto-notify`` to track and send notifications for. NOTE: If ``AUTO_NOTIFY_WHITELIST`` is defined,
197 | then all the values in ``AUTO_NOTIFY_IGNORE`` are not used.
198 |
199 | ::
200 |
201 | export AUTO_NOTIFY_WHITELIST=("apt-get" "docker")
202 |
203 | **Adding an icon - Linux**
204 |
205 | If you wish to have an icon displayed on command success and/or failure, you can do so by defining the environmental variables ``AUTO_NOTIFY_ICON_SUCCESS`` and ``AUTO_NOTIFY_ICON_FAILURE`` respectively.
206 |
207 | ::
208 |
209 | export AUTO_NOTIFY_ICON_SUCCESS=/path/to/success/icon.png
210 | export AUTO_NOTIFY_ICON_FAILURE=/path/to/failure/icon.png
211 |
212 |
213 |
214 | Temporarily Disabling Notifications
215 | -----------------------------------
216 |
217 | You can temporarily disable auto notify by running the command ``disable_auto_notify``.
218 |
219 | When you want to re-enable notifications, run the command ``enable_auto_notify``.
220 |
221 | Contributing
222 | ------------
223 |
224 | Pull requests and Feedback are welcome! :tada:
225 |
226 | I have tried to cater for as many use cases that I can think of.
227 | However, they are naturally tailored to to my own workflow and I could
228 | be missing many others.
229 |
230 | Because of this if there is a specific use case that does not work as
231 | you would expect or if you have any suggestions to how the plugin should
232 | behave, feel free to `open an
233 | issue `__
234 |
235 | Running Tests
236 | -------------
237 |
238 | Install `zunit `__. Run ``zunit`` in the root
239 | directory of the repo.
240 |
241 | ::
242 |
243 | $ zunit
244 | Launching ZUnit
245 | ZUnit: 0.8.2
246 | ZSH: zsh 5.3.1 (x86_64-suse-linux-gnu)
247 |
248 | ✔ version exported
249 | ✔ hook functions are loaded by default
250 | ✔ enable/disable auto-notify
251 | ✔ auto-notify-send does not send notification for short task
252 | ✔ auto-notify-send does not send notification for ignored commands
253 |
254 | NOTE: It is required that you use a minimum zunit version of 0.8.2
255 |
256 | .. _Zplug: https://github.com/zplug/zplug
257 |
258 | .. _Antigen: https://github.com/zsh-users/antigen
259 |
260 | .. _ZGen: https://github.com/tarjoilija/zgen
261 |
262 | .. _Fig: https://fig.io
263 |
264 | .. _oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh
265 |
266 | .. |GPLv3| image:: https://img.shields.io/badge/License-GPL%20v3-blue.svg
267 | :target: https://www.gnu.org/licenses/gpl-3.0
268 |
269 | .. |CircleCI| image:: https://circleci.com/gh/MichaelAquilina/zsh-auto-notify.svg?style=svg
270 | :target: https://circleci.com/gh/MichaelAquilina/zsh-auto-notify
271 |
272 | .. |Version| image:: https://badge.fury.io/gh/MichaelAquilina%2Fzsh-auto-notify.svg
273 | :target: https://badge.fury.io/gh/MichaelAquilina%2Fzsh-auto-notify
274 |
--------------------------------------------------------------------------------
/auto-notify.plugin.zsh:
--------------------------------------------------------------------------------
1 | export AUTO_NOTIFY_VERSION="0.11.1"
2 |
3 | # Time it takes for a notification to expire
4 | [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] &&
5 | export AUTO_NOTIFY_EXPIRE_TIME=8000
6 | # Threshold in seconds for when to automatically show a notification
7 | [[ -z "$AUTO_NOTIFY_THRESHOLD" ]] &&
8 | export AUTO_NOTIFY_THRESHOLD=10
9 | # Enable or disable notifications for SSH sessions (0 = disabled, 1 = enabled)
10 | [[ -z "$AUTO_NOTIFY_ENABLE_SSH" ]] &&
11 | export AUTO_NOTIFY_ENABLE_SSH=0
12 | # Enable transient notifications to prevent them from being saved in the notification history
13 | [[ -z "$AUTO_NOTIFY_ENABLE_TRANSIENT" ]] &&
14 | export AUTO_NOTIFY_ENABLE_TRANSIENT=1
15 | # Configure whether notifications should be canceled when receiving a SIGINT (Ctrl+C)
16 | [[ -z "$AUTO_NOTIFY_CANCEL_ON_SIGINT" ]] &&
17 | export AUTO_NOTIFY_CANCEL_ON_SIGINT=0
18 |
19 |
20 | # List of commands/programs to ignore sending notifications for
21 | [[ -z "$AUTO_NOTIFY_IGNORE" ]] &&
22 | export AUTO_NOTIFY_IGNORE=(
23 | 'vim'
24 | 'nvim'
25 | 'less'
26 | 'more'
27 | 'man'
28 | 'tig'
29 | 'watch'
30 | 'git commit'
31 | 'top'
32 | 'htop'
33 | 'ssh'
34 | 'nano'
35 | )
36 |
37 | function _auto_notify_format() {
38 | local MESSAGE="$1"
39 | local command="$2"
40 | local elapsed="$3"
41 | local exit_code="$4"
42 | MESSAGE="${MESSAGE//\%command/$command}"
43 | MESSAGE="${MESSAGE//\%elapsed/$elapsed}"
44 | MESSAGE="${MESSAGE//\%exit_code/$exit_code}"
45 | printf "%s" "$MESSAGE"
46 | }
47 |
48 | function _auto_notify_message() {
49 | local command="$1"
50 | local elapsed="$2"
51 | local exit_code="$3"
52 | local platform="$(uname)"
53 | # Run using echo -e in order to make sure notify-send picks up new line
54 | local DEFAULT_TITLE="\"%command\" Completed"
55 | local DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")"
56 |
57 | # Exit code 130 indicates termination by SIGINT (Ctrl+C).
58 | # If AUTO_NOTIFY_CANCEL_ON_SIGINT is enabled, suppress the notification.
59 | if [[ "$exit_code" -eq 130 ]] && [[ "${AUTO_NOTIFY_CANCEL_ON_SIGINT}" -eq 1 ]]; then
60 | return
61 | fi
62 |
63 | local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}"
64 | local text="${AUTO_NOTIFY_BODY:-$DEFAULT_BODY}"
65 |
66 | title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")"
67 | body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")"
68 |
69 | if [[ "$platform" == "Linux" ]]; then
70 | # Set default notification properties
71 | local urgency="normal"
72 | local transient="--hint=int:transient:$AUTO_NOTIFY_ENABLE_TRANSIENT"
73 | local icon="${AUTO_NOTIFY_ICON_SUCCESS:-""}"
74 |
75 | # Handle specific exit codes
76 | if [[ "$exit_code" -eq 130 ]]; then
77 | urgency="critical"
78 | transient="--hint=int:transient:1"
79 | icon="${AUTO_NOTIFY_ICON_FAILURE:-""}"
80 | elif [[ "$exit_code" -ne 0 ]]; then
81 | # For all other non-zero exit codes, mark the notification as critical.
82 | urgency="critical"
83 | icon="${AUTO_NOTIFY_ICON_FAILURE:-""}"
84 | fi
85 |
86 | local arguments=("$title" "$body" "--app-name=zsh" "$transient" "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME")
87 |
88 | if [[ -n "$icon" ]]; then
89 | arguments+=("--icon=$icon")
90 | fi
91 |
92 | # Check if the script is running over SSH
93 | if [[ -n "${SSH_CLIENT}" || -n "${SSH_CONNECTION}" ]]; then
94 | # Extract the client IP address from environment
95 | local client_ip="${SSH_CLIENT%% *}"
96 | [[ -z "$client_ip" ]] && client_ip="${SSH_CONNECTION%% *}"
97 |
98 | # Forward the notify-send command to the client machine via SSH
99 | ssh "${USER}@${client_ip}" "$(printf '%q ' notify-send "${arguments[@]}")"
100 | else
101 | # If not running over SSH, send notification locally
102 | notify-send "${arguments[@]}"
103 | fi
104 |
105 | elif [[ "$platform" == "Darwin" ]]; then
106 | osascript \
107 | -e 'on run argv' \
108 | -e 'display notification (item 1 of argv) with title (item 2 of argv)' \
109 | -e 'end run' \
110 | "$body" "$title" \
111 | 2> >(grep -Ev 'ApplePersistence=(NO|YES)' >&2)
112 | # ^ osascript outputs "ApplePersistence=NO" to stderr on every run, which clutters the terminal.
113 | # ^ Filter stderr to remove only this message while preserving any legitimate error messages.
114 | else
115 | printf "Unknown platform for sending notifications: $platform\n"
116 | printf "Please post an issue on gitub.com/MichaelAquilina/zsh-auto-notify/issues/\n"
117 | fi
118 | }
119 |
120 | function _is_auto_notify_ignored() {
121 | local command="$1"
122 | # split the command if its been piped one or more times
123 | local command_list=("${(@s/|/)command}")
124 | local target_command="${command_list[-1]}"
125 | # Remove leading whitespace
126 | target_command="$(echo "$target_command" | sed -e 's/^ *//')"
127 |
128 | # Ignore the command if running over SSH and AUTO_NOTIFY_ENABLE_SSH is disabled
129 | if [[ -n ${SSH_CLIENT-} || -n ${SSH_TTY-} || -n ${SSH_CONNECTION-} ]] && [[ "${AUTO_NOTIFY_ENABLE_SSH-1}" == "0" ]]; then
130 | print "yes"
131 | return
132 | fi
133 |
134 | # Remove sudo prefix from command if detected
135 | if [[ "$target_command" == "sudo "* ]]; then
136 | target_command="${target_command/sudo /}"
137 | fi
138 |
139 | # If AUTO_NOTIFY_WHITELIST is defined, then auto-notify will ignore
140 | # any item not defined in the white list
141 | # Otherwise - the alternative (default) approach is used where the
142 | # AUTO_NOTIFY_IGNORE blacklist is used to ignore commands
143 |
144 | if [[ -n "$AUTO_NOTIFY_WHITELIST" ]]; then
145 | for allowed in $AUTO_NOTIFY_WHITELIST; do
146 | if [[ "$target_command" == "$allowed"* ]]; then
147 | print "no"
148 | return
149 | fi
150 | done
151 | print "yes"
152 | else
153 | for ignore in $AUTO_NOTIFY_IGNORE; do
154 | if [[ "$target_command" == "$ignore"* ]]; then
155 | print "yes"
156 | return
157 | fi
158 | done
159 | print "no"
160 | fi
161 | }
162 |
163 | function _auto_notify_send() {
164 | # Immediately store the exit code before it goes away
165 | local exit_code="$?"
166 |
167 | if [[ -z "$AUTO_COMMAND" && -z "$AUTO_COMMAND_START" ]]; then
168 | return
169 | fi
170 |
171 | if [[ "$(_is_auto_notify_ignored "$AUTO_COMMAND_FULL")" == "no" ]]; then
172 | local current="$(date +"%s")"
173 | let "elapsed = current - AUTO_COMMAND_START"
174 |
175 | if [[ $elapsed -gt $AUTO_NOTIFY_THRESHOLD ]]; then
176 | _auto_notify_message "$AUTO_COMMAND" "$elapsed" "$exit_code"
177 | fi
178 | fi
179 |
180 | # Empty tracking so that notifications are not
181 | # triggered for any commands not run (e.g ctrl+C when typing)
182 | _auto_notify_reset_tracking
183 | }
184 |
185 | function _auto_notify_track() {
186 | # $1 is the string the user typed, but only when history is enabled
187 | # $2 is a single-line, size-limited version of the command that is always available
188 | # To still do something useful when history is disabled, although with reduced functionality, fall back to $2 when $1 is empty
189 | AUTO_COMMAND="${1:-$2}"
190 | AUTO_COMMAND_FULL="$3"
191 | AUTO_COMMAND_START="$(date +"%s")"
192 | }
193 |
194 | function _auto_notify_reset_tracking() {
195 | # Command start time in seconds since epoch
196 | unset AUTO_COMMAND_START
197 | # Full command that the user has executed after alias expansion
198 | unset AUTO_COMMAND_FULL
199 | # Command that the user has executed
200 | unset AUTO_COMMAND
201 | }
202 |
203 | function disable_auto_notify() {
204 | add-zsh-hook -D preexec _auto_notify_track
205 | add-zsh-hook -D precmd _auto_notify_send
206 | }
207 |
208 | function enable_auto_notify() {
209 | autoload -Uz add-zsh-hook
210 | add-zsh-hook preexec _auto_notify_track
211 | add-zsh-hook precmd _auto_notify_send
212 | }
213 |
214 | _auto_notify_reset_tracking
215 |
216 |
217 | platform="$(uname)"
218 | if [[ "$platform" == "Linux" ]] && ! type notify-send > /dev/null; then
219 | printf "'notify-send' must be installed for zsh-auto-notify to work\n"
220 | printf "Please install it with your relevant package manager\n"
221 | else
222 | enable_auto_notify
223 | fi
224 |
--------------------------------------------------------------------------------
/img/notification-example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MichaelAquilina/zsh-auto-notify/fce24a374793d02e9322231f7814d1b09d4c9195/img/notification-example.png
--------------------------------------------------------------------------------
/tests/test_auto_notify_format.zunit:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env zunit
2 |
3 | @setup {
4 | load "../auto-notify.plugin.zsh"
5 | }
6 |
7 | @test 'auto-notify-format no parameters' {
8 | run _auto_notify_format "Hello World" "foo" "bar" "baz"
9 |
10 | assert $state equals 0
11 | assert "$output" same_as "Hello World"
12 | }
13 |
14 | @test 'auto-notify-format correct formatting 1' {
15 | run _auto_notify_format "Command run is - %command (%elapsed seconds)" "zypper up" "10" "0"
16 |
17 | assert $state equals 0
18 | assert "$output" same_as "Command run is - zypper up (10 seconds)"
19 | }
20 |
21 | @test 'auto-notify-format correct formatting 2' {
22 | run _auto_notify_format "Exit code is %exit_code!" "zypper up" "10" "-101"
23 |
24 | assert $state equals 0
25 | assert "$output" same_as "Exit code is -101!"
26 | }
27 |
--------------------------------------------------------------------------------
/tests/test_auto_notify_send.zunit:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env zunit
2 |
3 | @setup {
4 | load "../auto-notify.plugin.zsh"
5 |
6 | function notify-send {
7 | echo - "Notification Title: $1"
8 | echo - "Notification Body: $2"
9 | echo - "${@:3}"
10 | }
11 |
12 | function uname {
13 | echo - "Linux"
14 | }
15 |
16 | # Mock date function to return a frozen timestamp
17 | function date {
18 | if [[ "$1" == +"%s" ]]; then
19 | echo - "11100"
20 | else
21 | date - "$@"
22 | fi
23 | }
24 | }
25 |
26 | @test 'auto-notify-send does not send notification if tracking not set' {
27 | unset AUTO_COMMAND
28 | unset AUTO_COMMAND_FULL
29 | unset AUTO_COMMAND_START
30 |
31 | run _auto_notify_send
32 |
33 | assert $state equals 0
34 | assert "$output" is_empty
35 | }
36 |
37 | @test 'auto-notify-send does not send notification for short task' {
38 | AUTO_COMMAND="foo bar -r"
39 | AUTO_COMMAND_FULL="foo bar -r"
40 | AUTO_COMMAND_START=11099
41 | run _auto_notify_send
42 |
43 | assert $state equals 0
44 | assert "$output" is_empty
45 | }
46 |
47 | @test 'auto-notify-send does not send notification for ignored commands' {
48 | for command in $AUTO_NOTIFY_IGNORE; do
49 | AUTO_COMMAND="somealias"
50 | AUTO_COMMAND_FULL="$command"
51 | AUTO_COMMAND_START=11000
52 | run _auto_notify_send
53 |
54 | assert $state equals 0
55 | assert "$output" is_empty
56 | done
57 | }
58 |
59 | @test 'auto-notify-send does not send notification for ignored piped commands' {
60 | AUTO_COMMAND="echo hello world | less -r"
61 | AUTO_COMMAND_FULL="echo hello world | less -r"
62 | AUTO_COMMAND_START=11000
63 | run _auto_notify_send
64 |
65 | assert $state equals 0
66 | assert "$output" is_empty
67 | }
68 |
69 | @test 'auto-notify-send does not send notification for ignored commands with arguments' {
70 | for command in $AUTO_NOTIFY_IGNORE; do
71 | AUTO_COMMAND="somealias bar -r"
72 | AUTO_COMMAND_FULL="$command bar -r"
73 | AUTO_COMMAND_START=11000
74 | run _auto_notify_send
75 |
76 | assert $state equals 0
77 | assert "$output" is_empty
78 | done
79 | }
80 |
81 | @test 'auto-notify-send sends notification on Linux' {
82 | AUTO_COMMAND="f bar -r"
83 | AUTO_COMMAND_FULL="foo bar -r"
84 | AUTO_COMMAND_START=11080
85 | AUTO_NOTIFY_EXPIRE_TIME=15000
86 | AUTO_NOTIFY_ENABLE_TRANSIENT=0
87 | run _auto_notify_send
88 |
89 | assert $state equals 0
90 | assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed'
91 | assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds"
92 | assert "$lines[3]" same_as "Exit code: 0"
93 | assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:0 --urgency=normal --expire-time=15000"
94 | }
95 |
96 | @test 'auto-notify-send sends notification and icon on Linux on success' {
97 | AUTO_COMMAND="f bar -r"
98 | AUTO_COMMAND_FULL="foo bar -r"
99 | AUTO_COMMAND_START=11080
100 | AUTO_NOTIFY_EXPIRE_TIME=15000
101 | AUTO_NOTIFY_ENABLE_TRANSIENT=0
102 | AUTO_NOTIFY_ICON_SUCCESS=/path/to/success/icon.png
103 | run _auto_notify_send
104 |
105 | assert $state equals 0
106 | assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed'
107 | assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds"
108 | assert "$lines[3]" same_as "Exit code: 0"
109 | assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:0 --urgency=normal --expire-time=15000 --icon=/path/to/success/icon.png"
110 | }
111 |
112 | @test 'auto-notify-send sends notification on macOS' {
113 | AUTO_COMMAND="f bar -r"
114 | AUTO_COMMAND_FULL="foo bar -r"
115 | AUTO_COMMAND_START=11080
116 |
117 | function uname {
118 | echo - "Darwin"
119 | }
120 |
121 | function osascript {
122 | echo - "${@}"
123 | }
124 |
125 | run _auto_notify_send
126 |
127 | assert $state equals 0
128 | assert "$lines[1]" same_as '-e on run argv -e display notification (item 1 of argv) with title (item 2 of argv) -e end run Total time: 20 seconds'
129 | assert "$lines[2]" same_as 'Exit code: 0 "f bar -r" Completed'
130 | }
131 |
132 | @test 'auto-notify-send sends warning on unsupported platform' {
133 | AUTO_COMMAND="f bar -r"
134 | AUTO_COMMAND_FULL="foo bar -r"
135 | AUTO_COMMAND_START=11080
136 |
137 | function uname {
138 | echo - "Hal9000"
139 | }
140 |
141 | run _auto_notify_send
142 | assert $state equals 0
143 | assert "$lines[1]" same_as "Unknown platform for sending notifications: Hal9000"
144 | assert "$lines[2]" same_as "Please post an issue on gitub.com/MichaelAquilina/zsh-auto-notify/issues/"
145 | }
146 |
147 | @test 'auto-notify-send sends custom message' {
148 | AUTO_COMMAND="doom -i"
149 | AUTO_COMMAND_FULL="doom -i"
150 | AUTO_COMMAND_START=11055
151 | AUTO_NOTIFY_TITLE="%command has completed in %elapseds yo"
152 | AUTO_NOTIFY_BODY="%command exited with code %exit_code"
153 |
154 | run _auto_notify_send
155 |
156 | assert $state equals 0
157 | assert "$lines[1]" same_as 'Notification Title: doom -i has completed in 45s yo'
158 | assert "$lines[2]" same_as "Notification Body: doom -i exited with code 0"
159 | }
160 |
--------------------------------------------------------------------------------
/tests/test_is_auto_notify_ignored.zunit:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env zunit
2 |
3 | @setup {
4 | load "../auto-notify.plugin.zsh"
5 | }
6 |
7 | @test 'is_auto_notify_ignored - commands outside AUTO_NOTIFY_IGNORE' {
8 | run _is_auto_notify_ignored "echo hello world"
9 |
10 | assert $state equals 0
11 | assert "$output" same_as "no"
12 | }
13 |
14 | @test 'is_auto_notify_ignored - all commands in AUTO_NOTIFY_IGNORE' {
15 | for command in $AUTO_NOTIFY_IGNORE; do
16 | run _is_auto_notify_ignored $command
17 |
18 | assert $state equals 0
19 | assert "$output" same_as "yes"
20 | done
21 | }
22 |
23 | @test 'is_auto_notify_ignored - piped commands which are not ignored' {
24 | run _is_auto_notify_ignored "echo hello world | base64 -e"
25 |
26 | assert $state equals 0
27 | assert "$output" same_as "no"
28 | }
29 |
30 | @test 'is_auto_notify_ignored - piped commands which are ignored' {
31 | run _is_auto_notify_ignored "echo hello world | hexdump | less -R"
32 |
33 | assert $state equals 0
34 | assert "$output" same_as "yes"
35 | }
36 |
37 | @test 'is_auto_notify_ignored - AUTO_NOTIFY_WHITELIST disallowed' {
38 | AUTO_NOTIFY_WHITELIST="foobar"
39 |
40 | run _is_auto_notify_ignored "boom baz"
41 |
42 | assert $state equals 0
43 | assert "$output" same_as "yes"
44 | }
45 |
46 | @test 'is_auto_notify_ignored - AUTO_NOTIFY_WHITELIST allowed' {
47 | AUTO_NOTIFY_WHITELIST="foobar"
48 |
49 | run _is_auto_notify_ignored "foobar baz"
50 |
51 | assert $state equals 0
52 | assert "$output" same_as "no"
53 | }
54 |
55 | @test 'is_auto_notify_ignored - AUTO_NOTIFY_WHITELIST allowed with sudo' {
56 | AUTO_NOTIFY_WHITELIST="foobar"
57 |
58 | run _is_auto_notify_ignored "sudo foobar baz"
59 |
60 | assert $state equals 0
61 | assert "$output" same_as "no"
62 | }
63 |
--------------------------------------------------------------------------------
/tests/test_plugin.zunit:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env zunit
2 |
3 | @setup {
4 | function uname {
5 | printf "Linux"
6 | }
7 | # Mock function for passing builds where we don't
8 | # really need notify-send to be installed (e.g. Mac OSX)
9 | function notify-send {
10 | }
11 | }
12 |
13 | @test 'print warning if notify-send is not installed' {
14 | function type {
15 | return 1
16 | }
17 |
18 | run load "../auto-notify.plugin.zsh"
19 |
20 | assert "$lines[1]" same_as "'notify-send' must be installed for zsh-auto-notify to work"
21 | assert "$lines[2]" same_as "Please install it with your relevant package manager"
22 |
23 | @test 'dont load auto-notify if notify-send is not installed' {
24 | function type {
25 | return 1
26 | }
27 |
28 | load "../auto-notify.plugin.zsh"
29 |
30 | assert "_auto_notify_track" not_in $preexec_functions
31 | assert "_auto_notify_send" not_in $precmd_functions
32 | }
33 |
34 |
35 | @test 'hook functions are loaded by default' {
36 | load "../auto-notify.plugin.zsh"
37 |
38 | assert '_auto_notify_track' in $preexec_functions
39 | assert '_auto_notify_send' in $precmd_functions
40 | }
41 |
42 | @test 'enable/disable auto-notify' {
43 | load "../auto-notify.plugin.zsh"
44 |
45 | disable_auto_notify
46 | assert '_auto_notify_track' not_in $preexec_functions
47 | assert '_auto_notify_send' not_in $precmd_functions
48 |
49 | enable_auto_notify
50 | assert '_auto_notify_track' in $preexec_functions
51 | assert '_auto_notify_send' in $precmd_functions
52 | }
53 |
--------------------------------------------------------------------------------