Find in files script?
has anyone written a « find in files » script for Pythonista?
Basically a script that would search .py or text files within a folder and return results in the console.
The first few weeks after installing Pythonista, I was astonished not to find many of the basic functions of most script editors, such as « comment line(s) », and « Find/Replace ».
After searching this forum and the web, I finally found what I needed, but it took me some time, and I was quite surprised that these scripts were not stored in an organized place. The search feature of this forum is not very efficient for that purpose.
If anyone could help me, I would give him... all my gratitude!
Search/replace within a file is already/part of the editor. There is a little switch to switch from find only to find/replace.
There are context menu options to comment or indent a section of code, iirc.
If suggest reading through the About Pythonista section of the help docs, as there are a few really useful features that might not be obvious when you first pick up the app.
If you are trying to find text within a not opened file, you should install stash, which includes a grep command
As for community written tools/scripts... The forum search doesn't work that well, but Google with the host:omz-software.com works well. Also, on GitHub
there is the pythonista-tools repo, which isn't really actively maintained but has some old stuff which can get you going.
Is a good repository of scripts shared in the forums.
BTW, there used to be a repo called editmenu, which can be found on GitHub, which included some features missing from the editor at the time --but most of those features exist in a nicer form in app now, so we stopped working on it.
Black Mamba adds a lot of keyboard shortcut support, if you use an external keyboard.
@jmmelko you could put this kind of (quick and dirty) script as Pythonista tool (it searchs in the .py or .txt files of the folder of the edited file)
You can edit and run it for testing, without setting it as a tool
import console import editor import os import ui def main(): t = console.input_alert('text to search',hide_cancel_button=True) if t == '': return t = t.lower() path = editor.get_path() path = path[:path.rfind('/')] fileslist = os.listdir(path) for file in fileslist: if file.lower()[-3:] == '.py' or file.lower()[-4:] == '.txt': with open(path+'/'+file,mode='rt', encoding='utf-8') as fil: content = fil.read().lower() lines = content.split('\n') first = True for line in lines: if line.find(t) >= 0: if first: first = False print(file) print(' ',line) if __name__ == '__main__': main()
if os.path.splitext(file)[-1].lower() in (".py", ".txt"):