From 3886017a89ad62bc4af0c430066510b07dbf6eca Mon Sep 17 00:00:00 2001 From: Rahul Thakare Date: Sun, 13 Jan 2019 00:34:13 +0530 Subject: [PATCH] First working draft --- .gitignore | 4 +++ LICENSE | 21 +++++++++++ README.md | 72 +++++++++++++++++++++++++++++++++++-- src/zealous.ini | 47 ++++++++++++++++++++++++ src/zealous.py | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ zealous.ico | Bin 0 -> 3779 bytes 6 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 src/zealous.ini create mode 100644 src/zealous.py create mode 100644 zealous.ico diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8c8856 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.editorconfig +.vscode +make.cmd +build diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d46af34 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Rahul Thakare + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index c2f40ed..85b1ac7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,70 @@ -# Keypirinha-Zealous -Keypirinha plugin for exploring Zeal docs. +# Keypirinha Plugin: Zealous + +This is Zealous, a plugin for the +[Keypirinha](http://keypirinha.com) launcher. + +**TODO:** write a brief description of this package. Optionally add a +screenshot. + + +## Download + +**TODO:** indicate where the latest `.keypirinha-package` file can be +downloaded. For example a URL to the `releases` list like: +https://github.com/bantya/Keypirinha-Zealous/releases + + +## Install + +Once the `Zealous.keypirinha-package` file is installed, +move it to the `InstalledPackage` folder located at: + +* `Keypirinha\portable\Profile\InstalledPackages` in **Portable mode** +* **Or** `%APPDATA%\Keypirinha\InstalledPackages` in **Installed mode** (the + final path would look like + `C:\Users\%USERNAME%\AppData\Roaming\Keypirinha\InstalledPackages`) + + +## Usage + +**TODO:** list the items, if any, inserted to the Catalog by the plugin(s) of +this package. Some plugins only make suggestions, in which case a description of +what kind of suggestions are to be expected by the user may help. + + +## Change Log + +**TODO:** describe notable changes for each release. Below is a template for +version 1.0. + +### v1.0 + +* Added foo item +* Fixed bug that was doing bad things when item "bar" was selected + + +## License + +**TODO:** recommended section. Below is an example that goes with the default +LICENSE file (MIT license). Do not forget to add your name in the `LICENSE` +file! + +This package is distributed under the terms of the MIT license. + + +## Credits + +**TODO:** optional section. + + +## Contribute + +**TODO:** optional section. Below is a template example, based on the one found +in Keypirinha's Packages repository. + +1. Check for open issues or open a fresh issue to start a discussion around a + feature idea or a bug. +2. Fork this repository on GitHub to start making your changes to the **dev** + branch. +3. Send a pull request. +4. Add yourself to the *Contributors* section below (or create it if needed)! diff --git a/src/zealous.ini b/src/zealous.ini new file mode 100644 index 0000000..2e695cc --- /dev/null +++ b/src/zealous.ini @@ -0,0 +1,47 @@ +# +# Zoaler Package configuration file +# More info at http://keypirinha.com +# + +# NOTE TO PLUGIN DEVELOPER: +# * This file may be removed from the package if no plugin requires +# configuration +# * The [main] section below is an example and not mandatory, however it is good +# practice to keep the [var] and [env] sections, as well as their respective +# comments +# * This comment block may be removed! + +[main] +# Plugin's main configuration section + +[docs] +# The zeal docs list + +[var] +# As in every Keypirinha's configuration file, you may optionally include a +# [var] section to declare variables that you want to reuse anywhere else in +# this file. +# +# Note that the [var] section is inherited, which means that any value defined +# in the main configuration file of the application (i.e.: "Keypirinha.ini") has +# already been made available to this file as well so you do not need to +# duplicate it here unless you want to override it. +# +# REMINDER: For convenience, Keypirinha silently populates this section with +# predefined values that may come handy. Here are some of them: APP_DIR, +# APP_EXE, PROFILE_DIR, PROFILE_DIR_INSTALLED_PACKS, PROFILE_DIR_LIVE_PACKS, +# PROFILE_DIR_USER and the KNOWNFOLDER_* and KNOWNFOLDERGUID_* values. +# +# See the "Configuration" chapter of the documentation for more information. + + +[env] +# For convenience, Keypirinha populates this [env] section in every loaded +# configuration file so you can easily access to environment variables like +# PATH for example from this file using syntax: ${env:PATH} +# +# If an environment variable happens to be changed while Keypirinha is running +# and this modification impacts current configuration, application and packages +# configuration will be reloaded if needed only. +# +# See the "Configuration" chapter of the documentation for more information. diff --git a/src/zealous.py b/src/zealous.py new file mode 100644 index 0000000..a327588 --- /dev/null +++ b/src/zealous.py @@ -0,0 +1,94 @@ +# Keypirinha: a fast launcher for Windows (keypirinha.com) + +import re +import os +import subprocess +import keypirinha as kp +import keypirinha_util as kpu + +class Zealous(kp.Plugin): + SECTION_DOCS = 'docs' + + SECTION_MAIN = 'main' + + REGEX_INPUT = r'(\S+)\s(.+)' + + ITEM_CAT = kp.ItemCategory.USER_BASE + 1 + + def __init__(self): + super().__init__() + self._debug = True + + def on_start(self): + self._gather_docs() + + def on_catalog(self): + self.on_start() + + def on_suggest(self, user_input, items_chain): + + input = re.search(self.REGEX_INPUT, user_input) + + if input is None: + return None + + for docid in self.docs: + idx, term = input.groups() + if docid == idx: + doc = self._get_setting(docid, self.SECTION_DOCS) + suggestion = self._set_suggestion(docid, doc, term) + + self.set_suggestions(suggestion) + + def _set_suggestion(self, docid, doc, term): + return [ + self.create_item( + category = self.ITEM_CAT, + label = docid + ' : Search ' + doc + ' for ' + term, + short_desc = doc + ':' + term, + target = doc + ':' + term, + args_hint = kp.ItemArgsHint.FORBIDDEN, + hit_hint = kp.ItemHitHint.IGNORE + ) + ] + + def _set_error(self, msg): + return [ + self.create_error_item( + label = "Error", + short_desc = msg, + target = error + ) + ] + + def on_execute(self, item, action): + if item.category() != self.ITEM_CAT: + return + + zeal_exe = self._get_setting('path', self.SECTION_MAIN) + if not 'zeal.exe' in zeal_exe: + zeal_exe = os.path.join(zeal_exe, 'zeal.exe') + + if os.path.isfile(zeal_exe): + try: + cmd = [zeal_exe] + cmd.append(item.target()) + subprocess.Popen(cmd, cwd=os.path.dirname(zeal_exe)) + except Exception as e: + self.dbg("Zeal - (%s)" % (e)) + else: + self.err('Could not find your %s executable.\n\nPlease edit Zeal.sublime-settings' % (zeal_exe)) + + def _gather_docs(self): + self.docs = self.load_settings().keys(self.SECTION_DOCS) + + def _get_setting(self, setting, section): + return self.load_settings().get_stripped( + setting, + section=section, + fallback=section + ) + + def on_events(self, flags): + if flags & kp.Events.PACKCONFIG: + self.on_start() diff --git a/zealous.ico b/zealous.ico new file mode 100644 index 0000000000000000000000000000000000000000..5f4c89110755c69ae0983e893a2450af26f42547 GIT binary patch literal 3779 zcmV;!4m|ORP)MN^Eh3>ii&As>BKIh&*Fm?{K#LxT}M#m?Ce~S2X z?H0h;PXK4e-3#7d>OKR@KJ0{iRQ;?!4ng3 z;P4Mj4t2HTFy1%>@Oj)b=n6!!_Fx3|92*k7RdQ?su3W!!Uyt<9Nb;tT1RG>e^*EHT z_zo5=Jp;dabbxsPgFE}lhva4q3q-Ot1TViAhQBQ9gFihVg-7T2lMTe=XUW0@`GDMx zJp$$7#Wg*!V0kb6`K1WVdo~Wg`(uJ^JZ1nkzs>>`42rdART!Rrtq-33Tc42Ykurbx zT5l|7fox$(Wk?A2?CX6(FqG>L&&0__w?bLj0F=LwP{#Vd_rrmTM8VXpW`UGawL1hK z?&^lBO<|~9*9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