select-locate 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/python
  2. # PYTHON_ARGCOMPLETE_OK
  3. import sys
  4. import osex
  5. import curses
  6. import argparse
  7. import argcomplete
  8. import ioex, ioex.selector
  9. def locate_select(patterns, match_all, ignore_case, update_database, multiple):
  10. paths = osex.locate(
  11. patterns,
  12. match_all = match_all,
  13. ignore_case = ignore_case,
  14. update_database = update_database
  15. )
  16. selected_paths = ioex.curses_tty_wrapper(
  17. ioex.selector.select_string,
  18. paths,
  19. multiple = multiple
  20. )
  21. return selected_paths
  22. def _init_argparser():
  23. argparser = argparse.ArgumentParser(description = None)
  24. argparser.add_argument('--ignore-case', action='store_true')
  25. argparser.add_argument('--match-all', action='store_true')
  26. argparser.add_argument('--multiple', action='store_true')
  27. argparser.add_argument('--update-database', action='store_true')
  28. argparser.add_argument('patterns', metavar = 'pattern', nargs = '+')
  29. return argparser
  30. def main(argv):
  31. argparser = _init_argparser()
  32. argcomplete.autocomplete(argparser)
  33. args = argparser.parse_args(argv)
  34. paths = locate_select(**vars(args))
  35. if paths is None:
  36. return 1
  37. else:
  38. print('\n'.join(paths))
  39. return 0
  40. if __name__ == "__main__":
  41. sys.exit(main(sys.argv[1:]))