PK!dotedit/__init__.pyPK!kX>WWdotedit/__main__.pyimport sys import os import os.path import argparse import readline from pkg_resources import resource_stream from subprocess import call from shutil import copy from ._path_completer import _PathCompleter from ._path_store import _PathStore from . import _path_matcher def main(): parser = init_argparse() args = parser.parse_args() data_path = (os.environ.get('XDG_DATA_HOME', os.environ.get('HOME') + '/.local/share') + '/dotedit') store = _PathStore(data_path) if args.list: [print(program) for program in store.list()] elif args.completions: print_comp_script(args.completions) elif args.remove: store.remove(args.remove) elif args.update: try: existing = store.get(args.update) except LookupError: return 1 path = read_path("Add path to {0}: ".format(args.update), existing) store.update(args.update, path) elif args.program != "none": try: path = store.get(args.program) except LookupError: path = read_path("Add path to {0}: ".format(args.program), _path_matcher.best_match(args.program)) store.add(args.program, path) open_editor(path) else: parser.print_usage() return 1 return 0 def init_argparse(): parser = argparse.ArgumentParser() parser.add_argument("program", nargs="?", default="none", help="program to edit dotfile of") parser.add_argument("-l", "--list", action="store_true", help="list programs with known paths and exit") parser.add_argument("-r", "--remove", metavar='PROGRAM', help="remove PROGRAM path and exit") parser.add_argument("-u", "--update", metavar='PROGRAM', help="update PROGRAM path and exit") parser.add_argument("--completions", metavar="SHELL", help=("output completion script for SHELL. " + "(bash, zsh & fish currently supported)")) return parser def open_editor(path): run_hook("pre-edit") call([os.environ.get("EDITOR", "nano"), path]) run_hook("post-edit") def run_hook(name): hook = get_config_directory() + "/hooks/" + name if os.path.exists(hook) and os.access(hook, os.X_OK): call([hook]) def get_config_directory(): home = os.environ.get("HOME") config_dir = (os.environ.get("XDG_CONFIG_HOME", home + "/.config") + "/dotedit") return config_dir def read_path(prompt, initial_text): def pre_input_hook(): readline.insert_text(initial_text) readline.redisplay() readline.set_pre_input_hook(pre_input_hook) readline.parse_and_bind("tab: complete") readline.parse_and_bind("set match-hidden-files on") readline.set_completer(_PathCompleter().complete) try: path = input(prompt) except (EOFError, KeyboardInterrupt) as e: sys.exit(1) readline.set_pre_input_hook() readline.set_completer() return path def print_comp_script(shell): home = os.environ.get('HOME') config_home = os.environ.get('XDG_CONFIG_HOME') res_name = "completions/" if shell == 'bash': res_name += "bash/dotedit-completion.bash" elif shell == 'zsh': res_name += "zsh/_dotedit" elif shell == 'fish': res_name += "fish/dotedit.fish" else: raise ValueError("Completions not supported for this shell") print(resource_stream(__name__, res_name).read().decode()) if __name__ == "__main__": sys.exit(main()) PK!<dotedit/_path_completer.pyimport os import os.path import readline class _PathCompleter: def complete(self, text, state): if state == 0: dir_ = os.path.dirname(readline.get_line_buffer()) if os.path.exists(dir_): os.chdir(dir_) if dir_ != "": self.matches = [ f for f in os.listdir(os.curdir) if f.startswith(text)] try: result = self.matches[state] except IndexError: result = None if len(self.matches) == 1: path = os.curdir + "/" + result if os.path.isdir(path): result += '/' return result PK!=&&dotedit/_path_matcher.pyimport os import os.path def best_match(program): home_path = os.environ.get('HOME') default_config_path = home_path + '/.config' config_path = os.environ.get('XDG_CONFIG_HOME', default_config_path) best_match = config_path + '/' matches = [f for f in os.listdir(config_path) if f.casefold().startswith(program.casefold())] if len(matches) == 1: best_match += matches[0] if os.path.exists(best_match): files = os.listdir(best_match) if len(files) == 1: best_match += '/' + files[0] elif len(matches) == 0: matches = [f for f in os.listdir(home_path) if f.casefold().startswith('.') and f.casefold().startswith('.' + program.casefold())] if len(matches) > 0: best_match = home_path if len(matches) == 1: best_match += '/' + matches[0] elif len(matches) > 1: best_match += '/.' + program else: best_match += program return best_match PK!  ssdotedit/_path_store.pyimport os import os.path import sqlite3 class _PathStore: def __init__(self, path): self._path = (path + 'dotedit.db' if path.endswith('/') else path + '/dotedit.db') if not os.path.exists(self._path): self._create_db() def get(self, program): connection = sqlite3.connect(self._path) cursor = connection.cursor() cursor.execute("SELECT path from paths WHERE program=?", (program,)) row = cursor.fetchone() cursor.close() connection.close() if row is None: raise LookupError() return row[0] def list(self): connection = sqlite3.connect(self._path) cursor = connection.cursor() cursor.execute("SELECT program from paths") rows = cursor.fetchall() cursor.close() connection.close() return [tup[0] for tup in rows if tup] def add(self, program, path): connection = sqlite3.connect(self._path) cursor = connection.cursor() cursor.execute("INSERT INTO paths VALUES(?,?)", (program, path,)) cursor.close() connection.commit() connection.close() def update(self, program, path): connection = sqlite3.connect(self._path) cursor = connection.cursor() cursor.execute("REPLACE INTO paths VALUES(?,?)", (program, path,)) cursor.close() connection.commit() connection.close() def remove(self, program): connection = sqlite3.connect(self._path) cursor = connection.cursor() cursor.execute("DELETE FROM paths WHERE program=?", (program,)) cursor.close() connection.commit() connection.close() def _create_db(self): try: os.makedirs(os.path.dirname(self._path)) except OSError as e: if e.errno != os.errno.EEXIST: raise connection = sqlite3.connect(self._path) cursor = connection.cursor() cursor.execute("CREATE TABLE paths (program text, path text)") cursor.close() connection.commit() connection.close() PK!o_*bb0dotedit/completions/bash/dotedit-completion.bashcomplete -W "--completions -h --help -l --list -r --remove -u --update $(dotedit --list)" dotedit PK!Ҋd%dotedit/completions/fish/dotedit.fishcomplete --no-files --command dotedit --short-option l --long-option list \ --description "list programs with known paths and exit" complete --exclusive --command dotedit --short-option r --long-option remove \ --arguments '(dotedit --list)' \ --description "remove PROGRAM path and exit" complete --exclusive --command dotedit --short-option u --long-option update \ --arguments '(dotedit --list)' \ --description "update PROGRAM path and exit" complete --no-files --command dotedit --short-option h --long-option help \ --description "show help and exit" complete --no-files --command dotedit --arguments '(dotedit --list)' \ --description "program to edit dotfile of" complete --no-files --command dotedit --long-option completions \ --arguments "bash zsh fish" \ --description "output completion script for SHELL. (bash, zsh & fish currently supported)" PK!R>7 dotedit/completions/zsh/_dotedit#compdef dotedit local -a args args=$(dotedit --list) if [[ ${#args[@]} -gt 0 ]] then _alternative "arguments:custom arg:($args)" fi _arguments '-h[display help]' '--help[display help]' \ '-l[list programs with known paths]' '--list[list programs with known paths]' \ '-u[update PROGRAM path and exit]' '--update[update PROGRAM path and exit]' \ '-r[remove PROGRAM path and exit]' '--remove[remove PROGRAM path and exit]' \ '--completions[output completion script for SHELL. (bash, zsh & fish currently supported)]' PK!HEP/+1(dotedit-1.1.0.dist-info/entry_points.txtN+I/N.,()J/IM,z񹉙yV PK!̋S77dotedit-1.1.0.dist-info/LICENSEMIT License Copyright (c) 2018 Daniel Alm Grundström 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. PK!H,TTdotedit-1.1.0.dist-info/WHEEL 1 0 =Rn>ZD:_dhRUQTk-k]m`Q'iPK!HذnS dotedit-1.1.0.dist-info/METADATAVRF}h ]R,yr*^.+P`RJԶg-(ygcI}Md" ~*1_dmHD98 w2YpL4T)Z@iU:& #;v06Y$lTQ|bԖTϻ=gHl{يQQnl6I0NԉuſdqT)xuu7T#gMa$SZҙGlu:95%OsbrAJ'K2gJw+ꗅ2LQIuM<ҷh5Y"$ N*^" u2MYt_29?7N)c\ sc%l]E%*g/UՂ zᝋy'i!6-Nyj  }ݏ;04H)j+C @ɊXb%$#v'I1}%PyK>}]+'~Vsa{OP6a?'IQ[€m` NQXyyE4lu{W#149q0fϥ3潦&d7Si P0 o}=|{xd!tkC2`; #$vԨߎόȳӁg4d%%n.٧U00F!6Ӽ &&o ̐U[`ff558t7z M u;]hb#C ci}?_APUNo?}E"^DI(3Z%Tk9BLdNi:1 X &8' [E߾{]=grR{0.HuNr *(Eih*JB8 \t !iGgP*=# ?vYa'C+7.񉻞D?y0PK!dotedit/__init__.pyPK!kX>WW1dotedit/__main__.pyPK!<dotedit/_path_completer.pyPK!=&&dotedit/_path_matcher.pyPK!  ssdotedit/_path_store.pyPK!o_*bb0dotedit/completions/bash/dotedit-completion.bashPK!Ҋd%ldotedit/completions/fish/dotedit.fishPK!R>7 _#dotedit/completions/zsh/_doteditPK!HEP/+1(%dotedit-1.1.0.dist-info/entry_points.txtPK!̋S77)&dotedit-1.1.0.dist-info/LICENSEPK!H,TT*dotedit-1.1.0.dist-info/WHEELPK!HذnS ,+dotedit-1.1.0.dist-info/METADATAPK!HWv~(0dotedit-1.1.0.dist-info/RECORDPK 93