Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-at-localhost committed Oct 8, 2019
1 parent 081701b commit 57ea881
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
Binary file added recoll.ico
Binary file not shown.
71 changes: 71 additions & 0 deletions recoll.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# Recoll Package configuration file
# More info at http://keypirinha.com
#

[main]
# Plugin's main configuration section.

# The installation location of foobar2000 on the system
# * Every backslash must be escaped by putting a backslash in front of it (e.g. "\\")
# * Default: "C:\\Program Files (x86)\\Recoll\\recoll.exe"
#file_path =

# TODO:
# ======================
#
# Additional commands for filtering
#
# See docs: https://www.lesbonscomptes.com/recoll/usermanual/#RCL.SEARCH.COMMANDLINE
# https://www.lesbonscomptes.com/recoll/manpages/recollq.1.html
#
# [-o|-a|-f] [-q] <query string>
# Runs a recoll query and displays result lines.
# Default: will interpret the argument(s) as a xesam query string
# Query elements:
# * Implicit AND, exclusion, field spec: t1 -t2 title:t3
# * OR has priority: t1 OR t2 t3 OR t4 means (t1 OR t2) AND (t3 OR t4)
# * Phrase: "t1 t2" (needs additional quoting on cmd line)
# -o Emulate the GUI simple search in ANY TERM mode
# -a Emulate the GUI simple search in ALL TERMS mode
# -f Emulate the GUI simple search in filename mode
# -q is just ignored (compatibility with the recoll GUI command line)
#
# Common options:
# -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR
# -S fld : sort by field <fld>
# -D : sort descending
# -s stemlang : set stemming language to use (must exist in index...)
# Use -s "" to turn off stem expansion
#
# Examples
#
# * Search only in filenames:
#commands = -f
# * Order by document size desc
#commands = -S dbytes -D
# * Order by file modification time asc
#commands = -S fmtime -D

[var]
# As usual in Keyprinha's configuration files, you may optionally include a
# [var] section as a placeholder for the definition of variables that are
# reusable anywhere else in this file.
#
# Also 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 them here.
#
# REMINDER: Keypirinha's pre-defined values are: APP_DIR, APP_EXE, PROFILE_DIR,
# PROFILE_DIR_INSTALLED_PACKS, PROFILE_DIR_LIVE_PACKS and PROFILE_DIR_USER.
# See the documentation for more information

[env]
# As usual in Keyprinha's configuration files, the [env] section is
# automatically included and populated at runtime. It contains every user's
# environment variable.
#
# Keypirinha detects when the environment changes. When it does, the environment
# block is updated and a ENV_CHANGED message is broadcasted to every loaded
# plugins so the plugin has a chance to reload configuration if needed.
115 changes: 115 additions & 0 deletions recoll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Keypirinha: a fast launcher for Windows (keypirinha.com)
# Credits https://github.com/ueffel wrote the majority of the code

import keypirinha as kp
import subprocess
import urllib
import keypirinha_util as kpu

class recoll(kp.Plugin):

CONFIG_SECTION_MAIN = "main"
DEFAULT_FILE_PATH = "C:\\Program Files (x86)\\Recoll\\recoll.exe"
DEFAULT_COMMANDS = "-t"

# Variables
file_path = DEFAULT_FILE_PATH
commands = DEFAULT_COMMANDS

def __init__(self):
super().__init__()
self._debug = False
self.dbg("CONSTRUCTOR")

def on_start(self):
self.dbg("On Start")
self._read_config()

def on_catalog(self):
self.set_catalog([
self.create_item(
category=kp.ItemCategory.KEYWORD,
label="Recoll",
short_desc="Queries the recoll index",
target="recoll",
args_hint=kp.ItemArgsHint.REQUIRED,
hit_hint=kp.ItemHitHint.KEEPALL
)
])

def on_suggest(self, user_input, items_chain):
if not items_chain or not user_input:
return

# avoid flooding if user still typing
if self.should_terminate(0.250):
return

suggestions = []

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
output, err = subprocess.Popen([self.file_path,
self.commands.strip(),
user_input],
stdout=subprocess.PIPE,
shell=False,
startupinfo=startupinfo).communicate()
if err:
self.err(err)
output_str = output.decode("utf-8")
self.dbg("Commands: {}".format(self.commands.strip()))
self.dbg("Input: {}".format(user_input))
self.info(output_str)

idx = 0
for line in output_str.splitlines():
if idx < 2:
idx += 1
continue
fields = line.split("\t")
file = fields[1][1:-1]
text = fields[2][1:-1]

suggestions.append(self.create_item(
category=kp.ItemCategory.REFERENCE,
label=text,
short_desc=urllib.parse.unquote(file)[8:],
target=str(idx),
data_bag=str(file),
args_hint=kp.ItemArgsHint.FORBIDDEN,
hit_hint=kp.ItemHitHint.KEEPALL
))

# limit to 100 results
if idx > 100:
break
idx += 1

self.set_suggestions(suggestions, kp.Match.ANY, kp.Sort.NONE)

def on_execute(self, item, action):
file = item.data_bag()
#os.startfile(urllib.parse.unquote(file)[8:])
kpu.shell_execute(file)

def _read_config(self):
self.dbg("Read Config")

settings = self.load_settings()
self.file_path = settings.get(
"file_path",
self.CONFIG_SECTION_MAIN,
self.DEFAULT_FILE_PATH)
self.dbg("Loaded file_path: {}".format(self.file_path))

# TODO: use more cmd options from ini file
self.commands = settings.get(
"commands",
self.CONFIG_SECTION_MAIN,
self.DEFAULT_COMMANDS)

if self.commands.find(self.DEFAULT_COMMANDS) == -1:
self.commands = self.DEFAULT_COMMANDS+" "+self.commands

self.dbg("Loaded commands: {}".format(self.commands))

0 comments on commit 57ea881

Please sign in to comment.