PK!dotedit/__init__.pyPK!H&&dotedit/__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, not args.no_hooks) 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)")) parser.add_argument("-n", "--no-hooks", action="store_true", help="Do not run pre or post edit hooks") return parser def open_editor(path, run_hooks): if run_hooks: run_hook("pre-edit") call([os.environ.get("EDITOR", "nano"), path]) if run_hooks: 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!!>/m0dotedit/completions/bash/dotedit-completion.bashcomplete -W "--completions \ -h --help \ -l --list \ -n --no-hooks \ -r --remove \ -u --update \ $(dotedit --list)" dotedit PK!`rXX%dotedit/completions/fish/dotedit.fishcomplete --exclusive --command dotedit --long-option completions \ --arguments "bash zsh fish" \ --description "output completion script for SHELL. \ (bash, zsh & fish currently supported)" complete --no-files --command dotedit --short-option h --long-option help \ --description "show help and exit" complete --no-files --command dotedit --short-option l --long-option list \ --description "list programs with known paths and exit" complete --no-files --command dotedit --short-option n --long-option no-hooks \ --description "Do not run pre or post edit hooks" 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 --arguments '(dotedit --list)' \ --description "program to edit dotfile of" PK!\ dotedit/completions/zsh/_dotedit#compdef dotedit local -a args args=$(dotedit --list) if [[ ${#args[@]} -gt 0 ]] then _alternative "arguments:custom arg:($args)" fi _arguments \ '--completions[output completion script for SHELL. (bash, zsh & fish currently supported)]' \ '-h[display help]' '--help[display help]' \ '-l[list programs with known paths]' '--list[list programs with known paths]' \ '-n[Do not run pre or post edit hooks] --no-hooks[Do not run pre or post edit hooks]' \ '-r[remove PROGRAM path and exit]' '--remove[remove PROGRAM path and exit]' \ '-u[update PROGRAM path and exit]' '--update[update PROGRAM path and exit]' \ PK!HEP/+1(dotedit-1.2.0.dist-info/entry_points.txtN+I/N.,()J/IM,z񹉙yV PK!̋S77dotedit-1.2.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.2.0.dist-info/WHEEL 1 0 =Rn>ZD:_dhRUQTk-k]m`Q'iPK!H?y*t dotedit-1.2.0.dist-info/METADATAWrG O!HHwI?y(S4&q:wn݋LU;8}J?I?i[2^Fu>;Y`21S^tG8BU鐕*G(W)0*ޗ$3$NMȼ*iOTڑHw詚ZAHj9 ^Jg) r J1yg)~-F#k,l)O{<s霚*dx) ν~ ʹ=֗ʒ%CqCe= 3TB"+6>uuT#t oMWcPZқ[j%uI(Px•^Y O?(]]mffeQԳ$?x?f7,D}-97pFTyly̒sUyE֙Ww*W^L}tqv҇3,STU*jԪD} >Jf|BwbTG+WA_Cx= f551Aɉg1|pOv*|zc‘p{b6Iꧠ/xB_c]I*kX| x 1],@|4xxE08nQz@a#`!5п" 3@i=>N8!#34NfRJ?osSMz@vK5&xχ^ _~sx d: 1 C/1`Qz #,;$QYȎϒf,Ӊ+47AP~X8#Ey vnӼ u6&ηfJժ8y7D3n xU|/N^ t8ކ|E#o$M _'DO~ѫ^?{=6$zT΃ł uV9у1ϙ0EMFv!  Xo&f!NonB;2`P?~uw^E´r#+MnPMA4(JC[W4Q9+ؽYQ#"WIby`#p&͒J΃dtBO"aToj1h1:A 㭳\/sCU$ ńkjɚEr;ȼn\O+&E`]8|X5sL4ӣ 玳Hq")n@t!PK!HJ&#z*dotedit-1.2.0.dist-info/RECORDur@}flwQqChCk <5U }S}q4=CʌbvZihW1+tt^!PIg ֚ដ;Te#lb4[Fy#& M3a/hMվ!NHd9g=zօeB[ j-WS[^*yc=[knLd' mNL9$im/EѸXe'.3HQB75dW0ߊIs$5 *9&adarsY0Gܨ5ct>m\S2_Ur%!d4l[^wG{hܴy竌wltAlrj,.}4E(xjM5'.F.R %Η P@0CPC~0*((# P4#v |*Xg6HJ Pa=`PK!dotedit/__init__.pyPK!H&&1dotedit/__main__.pyPK!<dotedit/_path_completer.pyPK!=&&dotedit/_path_matcher.pyPK!  ssdotedit/_path_store.pyPK!!>/m0dotedit/completions/bash/dotedit-completion.bashPK!`rXX% dotedit/completions/fish/dotedit.fishPK!\ >%dotedit/completions/zsh/_doteditPK!HEP/+1('dotedit-1.2.0.dist-info/entry_points.txtPK!̋S77l(dotedit-1.2.0.dist-info/LICENSEPK!H,TT,dotedit-1.2.0.dist-info/WHEELPK!H?y*t o-dotedit-1.2.0.dist-info/METADATAPK!HJ&#z*2dotedit-1.2.0.dist-info/RECORDPK 5