Example #1
0
def fzf(options):
    """Present an fzf style interface for given options."""
    from pyfzf.pyfzf import FzfPrompt
    _fzf = FzfPrompt()
    result = _fzf.prompt(options)
    # print(result)
    return result
Example #2
0
    def __init__(self):
        self.model = Model()
        self.fzf = FzfPrompt()
        self.screen = Screen()

        self.header = ''
        self.info = ''
Example #3
0
 def remove_file(self):
     fzf = FzfPrompt()
     google_file_list = self.file_list()
     file_list = [
         "title:" + gf["title"] + " create_date:" + gf["createdDate"]
         for gf in google_file_list
     ]
     file_dict = {}
     for count, file_name in enumerate(file_list):
         file_dict[file_name] = count
     target_file = fzf.prompt(file_dict)[0]
     file_id = google_file_list[file_dict[target_file]]["id"]
     file1 = self.drive.CreateFile({'id': file_id})
     file1.Trash()  # Move file to trash.
     file1.Delete()  # Permanently delete the file.
Example #4
0
def select_site_and_get_encrypted_password(query, profile):
    with tempfile.NamedTemporaryFile() as tmp:
        with open(os.path.join(HOME, CHROME, profile, LOGIN_DATA), 'rb') as f:
            tmp.write(f.read())
        cursor = sqlite3.connect(tmp.name).cursor()
        cursor.execute('''SELECT origin_url, username_value, password_value
                      FROM logins ORDER BY times_used desc''')
        passwords = []
        for origin_url, account, password in cursor.fetchall():
            password = base64.b64encode(password[3:]).decode('utf8')
            url = urlparse(origin_url)
            title = codecs.decode(url.netloc.encode('utf8'), 'idna')
            if title.lower().startswith('www.'):
                title = title[4:]
            if url.scheme == 'android':
                title = '%s://%s' % (url.scheme, title.split('@')[1])
            passwords.append({
                'type': 'default',
                'title': title,
                'subtitle': account,
                'arg': password,
                'valid': 'true' if len(password) > 0 else 'false',
                'autocomplete': title,
            })
        sites = get_site(passwords)
        fzf = FzfPrompt()
        selected_site = fzf.prompt(sites)
        assert len(selected_site) > 0
        assert selected_site[0].split("\t")

        sitename, username = selected_site[0].split("\t")
        target = None
        for p in passwords:
            new_sub = "NOUSER" if len(p["subtitle"]) == 0 else p["subtitle"]
            if (sitename == p["title"] and username == new_sub):
                target = p
                break
        if DEBUG:
            print("target: ", target)
        password_encrypted = target["arg"]

        return password_encrypted
Example #5
0
def get_site(passwords: list):
    fzf = FzfPrompt()
    if DEBUG:
        print("--- passwords")
        for p in passwords:
            print(p)
        print("--- END ---")

    new_list_with_mail = []
    for p in passwords:
        username = p["subtitle"]
        if len(username) == 0:
            username = "******"
        new_list_with_mail.append({"title": p["title"], "username": username})
    map_passwords_site_with_name = list(
        map(lambda x: x["title"] + "\t" + x["username"], new_list_with_mail))
    if DEBUG:
        for i in map_passwords_site_with_name:
            print(i)

    return map_passwords_site_with_name
Example #6
0
def select_files_in_tree(repo):
    url = f"https://api.github.com/repos/{repo}/git/trees/master?recursive=true"
    res = http.get(url)

    paths = []
    for entry in res.json()["tree"]:
        path = entry["path"]
        if path.endswith(".md") or path.endswith(".rst"):
            paths.append(path)

    if len(paths) == 0:
        click.secho(f"Repository {repo} contains no markdown files")
        raise click.Abort()

    if len(paths) == 1:
        return paths

    try:
        selected = FzfPrompt().prompt(paths, fzf_options="--multi")
    except plumbum.commands.processes.ProcessExecutionError as ex:
        raise click.Abort() from ex
    return selected
Example #7
0
 def run(self, stdscr):
     """
     Arguments selection menu processing..
     :param stdscr: screen
     """
     # init
     Gui.init_colors()
     while True:
         self.draw(stdscr)
         c = stdscr.getch()
         if c == curses.KEY_ENTER or c == 10 or c == 13:
             # try to build the cmd
             # if cmd build is ok -> exit
             # else continue in args menu
             if Gui.cmd.build():
                 break
         elif c == curses.KEY_F10 or c == 27:
             # exit args_menu -> return to cheatslist_menu
             curses.endwin()
             wrapper(self.previous_menu.run)
             break
         elif c == curses.KEY_DOWN:
             self.next_arg()
         elif c == curses.KEY_UP:
             self.previous_arg()
         elif c == 9:
             if Gui.cmd.args:
                 # autocomplete the current argument
                 if Gui.cmd.args[self.current_arg][1]:
                     self.autocomplete_arg()
                 # go to the next argument
                 else:
                     self.next_arg()
         elif c == 20:
             try:
                 from pyfzf.pyfzf import FzfPrompt
                 files = []
                 for fuzz_dir in config.FUZZING_DIRS:
                     files += glob.glob(fuzz_dir, recursive=True)
                 fzf = FzfPrompt().prompt(files)
                 # autocomplete the argument
                 Gui.cmd.args[self.current_arg][1] = fzf[0]
                 # update cursor position
                 self.xcursor = self.x_init + len(fzf[0])
             except ImportError:
                 pass
         elif c == curses.KEY_BACKSPACE or c == 127 or c == 8:
             if self.check_move_cursor(-1):
                 i = self.xcursor - self.x_init - 1
                 Gui.cmd.args[self.current_arg][1] = Gui.cmd.args[self.current_arg][1][:i] + \
                                                     Gui.cmd.args[self.current_arg][1][i + 1:]
                 self.xcursor -= 1
         elif c == curses.KEY_DC or c == 127:
             # DELETE key
             if self.check_move_cursor(1):
                 i = self.xcursor - self.x_init - 1
                 Gui.cmd.args[self.current_arg][1] = Gui.cmd.args[self.current_arg][1][:i + 1] + \
                                                     Gui.cmd.args[self.current_arg][1][i + 2:]
         elif c == curses.KEY_LEFT:
             # Move cursor LEFT
             if self.check_move_cursor(-1): self.xcursor -= 1
         elif c == curses.KEY_RIGHT:
             # Move cursor RIGHT
             if self.check_move_cursor(1): self.xcursor += 1
         elif c == curses.KEY_BEG or c == curses.KEY_HOME:
             # Move cursor to the BEGIN
             self.xcursor = self.x_init
         elif c == curses.KEY_END:
             # Move cursor to the END
             self.xcursor = self.x_init + len(
                 Gui.cmd.args[self.current_arg][1])
         elif 20 <= c < 127 and Gui.cmd.nb_args > 0:
             i = self.xcursor - self.x_init
             Gui.cmd.args[self.current_arg][1] = Gui.cmd.args[self.current_arg][1][:i] + chr(c) + \
                                                 Gui.cmd.args[self.current_arg][1][i:]
             self.xcursor += 1