terminal_velocity icon indicating copy to clipboard operation
terminal_velocity copied to clipboard

crash when trying to pass options to default editor

Open athrabeth opened this issue 10 years ago • 2 comments

I'm trying to invoke some flag in vim at launch, ie: terminal_velocity -e "vim -c 'set spell spelllang=en_us'" SomeLocation

terminal velocity launches, and i can search for a note, but if i create a new one or edit an existing, i get the following crash:

Traceback (most recent call last):
  File "/usr/local/bin/terminal_velocity", line 116, in <module>
    main()
  File "/usr/local/bin/terminal_velocity", line 110, in main
    extension=args.extension, extensions=args.extensions)
  File "/usr/local/lib/python2.7/site-packages/terminal_velocity/urwid_ui.py", line 444, in launch
    loop.run()
  File "/usr/local/lib/python2.7/site-packages/urwid/main_loop.py", line 272, in run
    self.screen.run_wrapper(self._run)
  File "/usr/local/lib/python2.7/site-packages/urwid/raw_display.py", line 242, in run_wrapper
    return fn()
  File "/usr/local/lib/python2.7/site-packages/urwid/main_loop.py", line 337, in _run
    self.event_loop.run()
  File "/usr/local/lib/python2.7/site-packages/urwid/main_loop.py", line 708, in run
    self._loop()
  File "/usr/local/lib/python2.7/site-packages/urwid/main_loop.py", line 787, in _loop
    self._watch_files[fd]()
  File "/usr/local/lib/python2.7/site-packages/urwid/main_loop.py", line 388, in _update
    self.process_input(keys)
  File "/usr/local/lib/python2.7/site-packages/urwid/main_loop.py", line 488, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/usr/local/lib/python2.7/site-packages/terminal_velocity/urwid_ui.py", line 327, in keypress
    system(self.editor, [self.selected_note.abspath], self.loop)
  File "/usr/local/lib/python2.7/site-packages/terminal_velocity/urwid_ui.py", line 41, in system
    raise e
OSError: [Errno 2] No such file or directory

athrabeth avatar May 08 '15 17:05 athrabeth

I've made a patch which should fix this issue: https://github.com/seanh/terminal_velocity/compare/master...brightghost:patch-1 . The previous code wasn't able to handle your arguments, as the python subprocess module expects the arguments to be split into a list but splitting the words in that command is non-trivial.

I've imported the shlex module to handle it. It's also possible to pass the command wholesale to the shell with the shell=True option to suprocess.check_call() , but I suspect this way is faster.

I've not had a chance to do testing on this yet, but I can send a pull request once I do.

brightghost avatar Jul 23 '15 08:07 brightghost

@brightghost Awesome! That looks like a good fix. Looking forward to the pull request

seanh avatar Jul 23 '15 09:07 seanh