def _get_items(self, query): if query.endswith("$"): query = query[:-1] located_files = run(self._locate(query), stdout=PIPE) located_files = located_files.stdout.decode("utf-8").split("\n") for filep in located_files: yield QuicksearchItem(filep) else: yield QuicksearchItem( None, title="Use $ to end your query", description= "The number of displayed files is limited to 50. The query can contain globbling characters." )
def _suggest_projects(self, query): regexs = ["No Regular Expression History."] if os.path.isfile(REGULAREXPRESSIONHIST): with open(REGULAREXPRESSIONHIST, "r") as f: regexs = f.readlines() found = False for regex in regexs: regex = regex.strip() if not regex == "": match = contains_chars(regex.lower(), query.lower()) if match or not query: found = True yield QuicksearchItem(regex, highlight=match) if not found: yield QuicksearchItem(query)
def load_files_for_dir(self, query, parse_dir, base_path): lst_search_items = [] for file_name in listdir(parse_dir): self.limit_file_count -= 1 self.files_found += 1 file_path = join(parse_dir, file_name) # show_status_message("_suggest_my_subfolders_and_files: " + file_path) file_name_clean = file_name file_name = join(base_path, file_name) if isdir(file_path): self.folders_found += 1 file_name = '[' + file_name + ']' match = contains_chars(file_name.lower(), query.lower()) if match or not query: lst_search_items.append( QuicksearchItem(file_path, file_name, highlight=match)) if isdir(file_path): new_base_path = join(base_path, file_name_clean) if self.limit_file_count > 0: lst_search_items += self.load_files_for_dir( query, file_path, new_base_path) return lst_search_items
def _suggest_favorite(self, query): favorites = [""] if os.path.isfile(FAVORITELIST): with open(FAVORITELIST, "r") as f: favorites = f.readlines() for favTuple in favorites: if '|' in favTuple: favName = favTuple.split('|')[0] match = contains_chars(favName.lower(), query.lower()) if match or not query: yield QuicksearchItem(favName, highlight=match)
def _suggest_directory(self, query): directories = ["Home|~"] if os.path.isfile(FAVORITELIST): with open(FAVORITELIST, "r") as f: directories = f.readlines() for dirTuple in directories: if '|' in dirTuple: dirName = dirTuple.split('|')[0] match = contains_chars(dirName.lower(), query.lower()) if match or not query: yield QuicksearchItem(dirName, highlight=match)
def _suggest_shortener(self, query): shorteners = ["No shorteners are setup."] if os.path.isfile(SHORTENERLIST): with open(SHORTENERLIST, "r") as f: shorteners = f.readlines() for shortTuple in shorteners: if shortTuple.strip() != "": shortName = shortTuple.split('|')[0] match = contains_chars(shortName.lower(), query.lower()) if match or not query: yield QuicksearchItem(shortName, highlight=match)
def _suggest_projects(self, query): projects = ["No Projects are setup."] if os.path.isfile(PROJECTSLIST): with open(PROJECTSLIST, "r") as f: projects = f.readlines() for projectTuple in projects: if projectTuple.strip() != "": project = projectTuple.split('|')[0].strip() match = contains_chars(project.lower(), query.lower()) if match or not query: yield QuicksearchItem(project, highlight=match)
def _get_items(self, query): bookmarks = \ load_json('FTP Bookmarks.json', default={}) for item in sorted(bookmarks.keys()): try: index = item.lower().index(query) except ValueError: continue else: highlight = range(index, index + len(query)) yield QuicksearchItem(item, highlight=highlight)
def _suggest_my_files_and_folders(self, query): dir_path = as_human_readable(self.pane.get_path()) list_directory_content = listdir(dir_path) list_directory_content = sorted(list_directory_content, key=lambda s: s.lower()) for file_name in list_directory_content: file_path = join(dir_path, file_name) if isdir(file_path): file_name = '[' + file_name + ']' match = contains_chars(file_name.lower(), query.lower()) if match or not query: yield QuicksearchItem(file_path, file_name, highlight=match)
def _suggest_script(self, query): scriptVars = _GetScriptVars() scripts = scriptVars['command_line_history'] # # Suggested one to the user and let them pick. # for script in scripts: if script.strip() != "": scriptName = script match = contains_chars(scriptName.lower(), query.lower()) if match or not query: yield QuicksearchItem(scriptName, highlight=match)
def _get_items(self, query): bookmarks = \ load_json('FTP History.json', default={}) for item, _ in sorted(bookmarks.items(), key=itemgetter(1), reverse=True): try: index = item.lower().index(query) except ValueError: continue else: highlight = range(index, index + len(query)) yield QuicksearchItem(item, highlight=highlight)
def _suggest_script(self, query): scripts = [] maskPackagePath = as_human_readable(self.pane.get_path()) + os.path.sep + 'maskfile.md' maskPackagePtr = open(npmPackagePath,"r") maskScript = npmPackagePtr.read() maskPackagePtr.close() for scriptName, command in scriptNames: scripts.append(scriptName) # # Suggested one to the user and let them pick. # for script in scripts: if script.strip() != "": scriptName = script match = contains_chars(scriptName.lower(), query.lower()) if match or not query: yield QuicksearchItem(scriptName, highlight=match)
def _get_items(self, query): if not query: for command in self._git_commands: yield command else: option = query.lower() try: yield self._git_commands[self._git_keys.index(option)] except ValueError: # If it it not one of the letters, tries to filter for item in self._git_commands: try: index = item.title.lower().index(query.lower()) highlight = range(index, index + len(query)) yield QuicksearchItem(item.value, item.title, highlight=highlight) except ValueError: continue
def _suggest_script(self, query): show_alert('/usr/bin/osascript "' + path.dirname(path.realpath(__file__)) + '/serviceMenu.scpt"') output = run('/usr/bin/osascript "' + path.dirname(path.realpath(__file__)) + '/serviceMenu.scpt"', stdout=PIPE, shell=True) show_alert(output.stdout.decode("utf-8")) services = json.loads(output.stdout.decode("utf-8")) # # Suggested one to the user and let them pick. # for service in services: if service.name.strip() != "": serviceName = service.name match = contains_chars(serviceName.lower(), query.lower()) if match or not query: yield QuicksearchItem(serviceName, highlight=match)
def _suggest_script(self, query): scripts = ["No scripts are setup."] # # Get a list of scripts. # scriptDir = _GetScriptVars() scripts = os.listdir(scriptDir['directory']) # # Suggested one to the user and let them pick. # for script in scripts: scriptName = script.strip() if scriptName != "": match = False if query: match = contains_chars(script.lower(), query.lower()) else: match = True if scriptName[0] == '.' or scriptName[0] == 'L' or scriptName[0] == 'R': match = False if match: yield QuicksearchItem(scriptName)
class ListGitCommands(DirectoryPaneCommand): _git_commands = [ QuicksearchItem('add', 'Add', highlight=range(0, 1)), QuicksearchItem('switch', 'Checkout/Switch Branch', highlight=range(4, 5)), QuicksearchItem('clone', 'Clone', highlight=range(3, 4)), QuicksearchItem('commit', 'Commit', highlight=range(0, 1)), QuicksearchItem('diff', 'Diff', highlight=range(0, 1)), QuicksearchItem('repocreate', 'Init', highlight=range(0, 1)), QuicksearchItem('log', 'Logs Folder', highlight=range(0, 1)), QuicksearchItem('log_file', 'Logs File', highlight=range(5, 6)), QuicksearchItem('pull', 'Pull', highlight=range(0, 1)), QuicksearchItem('push', 'Push', highlight=range(2, 3)), QuicksearchItem('resolve', 'Resolve Conflicts', highlight=range(0, 1)), ] _git_keys = ['a', 'k', 'n', 'c', 'd', 'i', 'l', 'f', 'p', 's', 'r'] def _execute(self, command, path=None, close_on_end=2): arg_command = '/command:' + command if path is None: pane_path = self.pane.get_path() path = as_human_readable(pane_path) arg_path = '/path:"{}"'.format(path) arg_close_on_end = '/closeonend={}'.format(close_on_end) exec_command = [ "TortoiseGitProc.exe", arg_command, arg_path, arg_close_on_end ] show_status_message(' '.join(exec_command)) subprocess.run(' '.join(exec_command)) def __call__(self): result = show_quicksearch(self._get_items) if result: query, value = result if value == 'log_file': file = self.pane.get_file_under_cursor() if file is None: self._execute('log') else: self._execute('log', as_human_readable(file)) else: self._execute(value) else: pass def _get_items(self, query): if not query: for command in self._git_commands: yield command else: option = query.lower() try: yield self._git_commands[self._git_keys.index(option)] except ValueError: # If it it not one of the letters, tries to filter for item in self._git_commands: try: index = item.title.lower().index(query.lower()) highlight = range(index, index + len(query)) yield QuicksearchItem(item.value, item.title, highlight=highlight) except ValueError: continue