Skip to content

Commit

Permalink
First working draft
Browse files Browse the repository at this point in the history
  • Loading branch information
bantya committed Jan 12, 2019
1 parent d094879 commit 3886017
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.editorconfig
.vscode
make.cmd
build
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Rahul Thakare <https://github.com/bantya>

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.
72 changes: 70 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)!
47 changes: 47 additions & 0 deletions src/zealous.ini
Original file line number Diff line number Diff line change
@@ -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.
94 changes: 94 additions & 0 deletions src/zealous.py
Original file line number Diff line number Diff line change
@@ -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()
Binary file added zealous.ico
Binary file not shown.

0 comments on commit 3886017

Please sign in to comment.