hillaryychan / ulauncher-fzf

Find files and directories in Ulauncher using fzf (and fd)
https://ext.ulauncher.io/-/github-hillaryychan-ulauncher-fzf
MIT License
53 stars 8 forks source link

Loading ... #9

Closed hemanti0503 closed 2 years ago

hemanti0503 commented 2 years ago

It doesn't work for me, unfortunately (uLauncher 5.14.3). All I get after typing in "fzf" is "Loading...".

image

I tried different settings, including choosing a different start folder, excluding files, only searching for directories, ... Nothing helps, though.

Anything I could do to debug? I've installed all the dependencies.

hillaryychan commented 2 years ago

Hello! Thanks for trying out my extension.

Got a few questions that can maybe help us figure out what going on:

  1. which OS?
  2. how have you installed the extension? via ulauncher's extension menu?
  3. are you able to run the dependencies via the terminal? i.e. fzf with fzf and fd with fd or fdfind
  4. can you send in some logging info you get from running the extension?
hemanti0503 commented 2 years ago

Hello and thank you for your fast reply! :)

  1. Linux Mint 20.2
  2. Yes, copying and pasting the Github repository link there. Just checked for updates.
  3. They all run fine in the terminal.
  4. Do you mean terminal messages after launching ulauncher from the terminal? There are none for this extension, unfortunately.
hillaryychan commented 2 years ago

Interesting.

Logging currently doesn't start until we enter the search function for the extension, which means it's erroring sometime before that.

I'll let you know when I've added more logging statements for us to figure out when it's happening

hillaryychan commented 2 years ago

@hemanti0503 I've added some more logging.

Update the extension and let me know what you get.

hemanti0503 commented 2 years ago

I updated successfully, but still can't see logging from the extension.

hillaryychan commented 2 years ago

Not even logging for the extension being connected on startup?

2022-01-17 22:40:31,252 | INFO | ulauncher.api.server.ExtensionController: handleConnected() | Extension "com.github.hillaryychan.ulauncher-fzf" connected
2022-01-17 22:40:31,253 | DEBUG | ulauncher.api.server.ExtensionController: _send_event() | Send event PreferencesEvent to "com.github.hillaryychan.ulauncher-fzf"
com.github.hillaryychan.ulauncher-fzf | 2022-01-17 22:40:31,254 | DEBUG | ulauncher.api.client.Client: on_message() | Incoming event PreferencesEvent

Are your other extensions working properly for you?

E: what command are you running ulauncher with to view logs?

hemanti0503 commented 2 years ago

I found out, I can output debug message with ulauncher -v. This is the message I'm getting at startup of ulauncher (regarding fzf):

2022-01-17 20:13:43,965 | DEBUG | ulauncher.api.server.ExtensionController: _send_event() | Send event PreferencesEvent to "com.github.hillaryychan.ulauncher-fzf"
com.github.hillaryychan.ulauncher-fzf | 2022-01-17 20:13:43,966 | DEBUG | ulauncher.api.client.Client: on_message() | Incoming event PreferencesEvent

When I enter "fzf x", I'm getting this:

com.github.hillaryychan.ulauncher-fzf | 2022-01-17 20:19:44,563 | DEBUG | ulauncher.api.client.Client: on_message() | Incoming event KeywordQueryEvent
com.github.hillaryychan.ulauncher-fzf | 2022-01-17 20:19:44,563 | DEBUG | __main__: check_dependencies() | Checking and getting binaries for dependencies
2022-01-17 20:19:44,978 | DEBUG | ulauncher.ui.windows.UlauncherWindow: show_results() | render 1 results
2022-01-17 20:19:45,173 | DEBUG | ulauncher.api.server.ExtensionController: _send_event() | Send event KeywordQueryEvent to "com.github.hillaryychan.ulauncher-fzf"
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ulauncher/api/client/Client.py", line 54, in on_message
    self.extension.trigger_event(event)
  File "/usr/lib/python3/dist-packages/ulauncher/api/client/Extension.py", line 52, in trigger_event
    action = listener.on_event(event, self)
  File "/home/hm/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 134, in on_event
    bin_names, errors = extension.check_dependencies()
  File "/home/hm/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 58, in check_dependencies
    bin_names = self.assign_bin_name(bin_names, "fzf_bin", "fzf")
  File "/home/hm/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 48, in assign_bin_name
    subprocess.check_call(["command", "-v", testing_cmd], stdout=subprocess.DEVNULL)
  File "/usr/lib/python3.8/subprocess.py", line 359, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] Datei oder Verzeichnis nicht gefunden: 'command'
com.github.hillaryychan.ulauncher-fzf | 2022-01-17 20:19:45,264 | DEBUG | ulauncher.api.client.Client: on_message() | Incoming event KeywordQueryEvent
com.github.hillaryychan.ulauncher-fzf | 2022-01-17 20:19:45,264 | DEBUG | __main__: check_dependencies() | Checking and getting binaries for dependencies

This looks like it could be more helpful. ;)

hillaryychan commented 2 years ago

Cool so it looks like command isn't available on Mint, which is strange considering it is a POSIX compatible command.

We can try an alternative. What output do you get when you run type fzf?

hemanti0503 commented 2 years ago
$ type fzf
fzf is /usr/bin/fzf
hillaryychan commented 2 years ago

Perfect. I'll change how we check and get the binaries to use type then

hillaryychan commented 2 years ago

@hemanti0503 I've merged the changes. Can you check if the extension works now?

hemanti0503 commented 2 years ago

Unfortunately, it still does not:

2022-01-18 15:53:04,555 | DEBUG | ulauncher.ui.windows.UlauncherWindow: show_results() | render 9 results
2022-01-18 15:53:04,558 | DEBUG | ulauncher.ui.windows.UlauncherWindow: show_results() | render 1 results
2022-01-18 15:53:04,718 | DEBUG | ulauncher.ui.windows.UlauncherWindow: show_results() | render 1 results
2022-01-18 15:53:05,660 | DEBUG | ulauncher.ui.windows.UlauncherWindow: show_results() | render 1 results
2022-01-18 15:53:05,856 | DEBUG | ulauncher.api.server.ExtensionController: _send_event() | Send event KeywordQueryEvent to "com.github.hillaryychan.ulauncher-fzf"
com.github.hillaryychan.ulauncher-fzf | 2022-01-18 15:53:05,868 | DEBUG | ulauncher.api.client.Client: on_message() | Incoming event KeywordQueryEvent
com.github.hillaryychan.ulauncher-fzf | 2022-01-18 15:53:05,868 | DEBUG | __main__: check_dependencies() | Checking and getting binaries for dependencies
2022-01-18 15:53:07,091 | DEBUG | ulauncher.ui.windows.UlauncherWindow: show_results() | render 1 results
2022-01-18 15:53:07,288 | DEBUG | ulauncher.api.server.ExtensionController: _send_event() | Send event KeywordQueryEvent to "com.github.hillaryychan.ulauncher-fzf"
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ulauncher/api/client/Client.py", line 54, in on_message
    self.extension.trigger_event(event)
  File "/usr/lib/python3/dist-packages/ulauncher/api/client/Extension.py", line 52, in trigger_event
    action = listener.on_event(event, self)
  File "/home/hm/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 134, in on_event
    bin_names, errors = extension.check_dependencies()
  File "/home/hm/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 58, in check_dependencies
    bin_names = self.assign_bin_name(bin_names, "fzf_bin", "fzf")
  File "/home/hm/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 48, in assign_bin_name
    subprocess.check_call(["type", testing_cmd], stdout=subprocess.DEVNULL)
  File "/usr/lib/python3.8/subprocess.py", line 359, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] Datei oder Verzeichnis nicht gefunden: 'type'
com.github.hillaryychan.ulauncher-fzf | 2022-01-18 15:53:07,371 | DEBUG | ulauncher.api.client.Client: on_message() | Incoming event KeywordQueryEvent
com.github.hillaryychan.ulauncher-fzf | 2022-01-18 15:53:07,371 | DEBUG | __main__: check_dependencies() | Checking and getting binaries for dependencies
hillaryychan commented 2 years ago

In your python repl, can you run the following for me

import subprocess
subprocess.check_call(["type", "fzf"], shell=True, stdout=subprocess.DEVNULL)

Is the output just 0?

hemanti0503 commented 2 years ago

It is (was) not:

 $ python
Python 2.7.18 (default, Mar  8 2021, 13:02:45) 
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.check_call(["type", "fzf"], shell=True, stdout=subprocess.DEVNULL)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'DEVNULL'

From this, I figured, that my system used python2 as standard, so I did sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1. Now, your code just gives 0, but I can't start ulauncher anymore. :(

$ ulauncher
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(ulauncher:2234923): Gtk-CRITICAL **: 17:05:37.815: gtk_icon_theme_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
Failed to connect to bus: No such file or directory
Traceback (most recent call last):
  File "/usr/bin/ulauncher", line 28, in <module>
    main()
  File "/usr/lib/python3/dist-packages/ulauncher/main.py", line 96, in main
    bus = dbus.SessionBus()
  File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 212, in __new__
    return Bus.__new__(cls, Bus.TYPE_SESSION, private=private,
  File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 102, in __new__
    bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 124, in __new__
    bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 153, in apport_excepthook
    with os.fdopen(os.open(pr_filename,
FileNotFoundError: [Errno 2] No such file or directory: '/var/crash/_usr_bin_ulauncher.1000.crash'

Original exception was:
Traceback (most recent call last):
  File "/usr/bin/ulauncher", line 28, in <module>
    main()
  File "/usr/lib/python3/dist-packages/ulauncher/main.py", line 96, in main
    bus = dbus.SessionBus()
  File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 212, in __new__
    return Bus.__new__(cls, Bus.TYPE_SESSION, private=private,
  File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 102, in __new__
    bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 124, in __new__
    bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
oktayacikalin commented 2 years ago

In your python repl, can you run the following for me

import subprocess
subprocess.check_call(["type", "fzf"], shell=True, stdout=subprocess.DEVNULL)

Is the output just 0?

I'm getting 0. elementary OS 6.1 does not seem to have type installed, but rather command :-)

hillaryychan commented 2 years ago

@oktayacikalin type and command are bash builtin commands according to manpages. I wonder why its not in elementary OS 6.1 :disappointed:

@hemanti0503 based on your previous logs it looks like you were running ulauncher with python 3.8 not python 2. I believe/suspect the real reason why you couldn't run command or type for the extension was because I wasn't calling check_call with shell=True. (see https://stackoverflow.com/questions/62732701/error-while-trying-to-run-command-with-subprocess)

If you can find a way to get ulauncher running again that would be great and we can continue trying to fix this, but now it seems the problem is out of the scope for what I would know.

I think the best we can do right now is

hemanti0503 commented 2 years ago

I tried to open ulauncher with a new shell and voila - it works again. :) However, fzf is still not working. I checked, but there were no updates. Also, error is the same:

2022-01-18 17:52:36,876 | DEBUG | ulauncher.api.server.ExtensionController: _send_event() | Send event KeywordQueryEvent to "com.github.hillaryychan.ulauncher-fzf"
com.github.hillaryychan.ulauncher-fzf | 2022-01-18 17:52:36,930 | DEBUG | ulauncher.api.client.Client: on_message() | Incoming event KeywordQueryEvent
com.github.hillaryychan.ulauncher-fzf | 2022-01-18 17:52:36,930 | DEBUG | __main__: check_dependencies() | Checking and getting binaries for dependencies
2022-01-18 17:52:38,480 | DEBUG | ulauncher.ui.windows.UlauncherWindow: show_results() | render 1 results
2022-01-18 17:52:38,678 | DEBUG | ulauncher.api.server.ExtensionController: _send_event() | Send event KeywordQueryEvent to "com.github.hillaryychan.ulauncher-fzf"
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ulauncher/api/client/Client.py", line 54, in on_message
    self.extension.trigger_event(event)
  File "/usr/lib/python3/dist-packages/ulauncher/api/client/Extension.py", line 52, in trigger_event
    action = listener.on_event(event, self)
  File "/home/hm/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 134, in on_event
    bin_names, errors = extension.check_dependencies()
  File "/home/hm/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 58, in check_dependencies
    bin_names = self.assign_bin_name(bin_names, "fzf_bin", "fzf")
  File "/home/hm/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 48, in assign_bin_name
    subprocess.check_call(["type", testing_cmd], stdout=subprocess.DEVNULL)
  File "/usr/lib/python3.8/subprocess.py", line 359, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] Datei oder Verzeichnis nicht gefunden: 'type'
com.github.hillaryychan.ulauncher-fzf | 2022-01-18 17:52:38,733 | DEBUG | ulauncher.api.client.Client: on_message() | Incoming event KeywordQueryEvent
com.github.hillaryychan.ulauncher-fzf | 2022-01-18 17:52:38,733 | DEBUG | __main__: check_dependencies() | Checking and getting binaries for dependencies

I don't understand the shell=true thing. Why is that specific to my system? Shouldn't that be a problem on everyone's system? Would it be something you would fix?

oktayacikalin commented 2 years ago

Yeah, opening up a new terminal window shows that type and command are available. I don't know what caused them to disappear before.

Now I'm getting the following:

2022-01-18 11:28:18,821 | DEBUG | ulauncher.api.server.ExtensionController: _send_event() | Send event KeywordQueryEvent to "com.github.hillaryychan.ulauncher-fzf"
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ulauncher/api/client/Client.py", line 54, in on_message
    self.extension.trigger_event(event)
  File "/usr/lib/python3/dist-packages/ulauncher/api/client/Extension.py", line 52, in trigger_event
    action = listener.on_event(event, self)
  File "/home/oktay/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 134, in on_event
    bin_names, errors = extension.check_dependencies()
  File "/home/oktay/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 58, in check_dependencies
    bin_names = self.assign_bin_name(bin_names, "fzf_bin", "fzf")
  File "/home/oktay/.local/share/ulauncher/extensions/com.github.hillaryychan.ulauncher-fzf/main.py", line 48, in assign_bin_name
    subprocess.check_call(["command", "-v", testing_cmd], stdout=subprocess.DEVNULL)
  File "/usr/lib/python3.8/subprocess.py", line 359, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] Datei oder Verzeichnis nicht gefunden: 'command'

Due to type and command being only available in the bash and not in the filesystem, you should use shell=True, I guess.

hillaryychan commented 2 years ago

I was a bit hesitant to use shell=True because there are security considerations for it. But since we are hard coding the commands being passed in it should be okay.

Before I follow through with this, I did find something that could be a better alternative on the subprocess docs

To search for an unqualified name on PATH, use shutil.which().

Can you guys tell me what you get on your python 3 repl when you run this:

import shutil
shutil.which("fzf")
hemanti0503 commented 2 years ago
$ python
Python 3.8.10 (default, Nov 26 2021, 20:14:08) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.which("fzf")
'/usr/bin/fzf'
oktayacikalin commented 2 years ago
$ python3
Python 3.8.10 (default, Nov 26 2021, 20:14:08) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.which("fzf")
'/usr/bin/fzf'
>>> 

I always liked the which command :-)

hillaryychan commented 2 years ago

I think we've found our solution then :tada:

I will make changes accordingly asap

hillaryychan commented 2 years ago

@hemanti0503 and @oktayacikalin everything working now/still working?

oktayacikalin commented 2 years ago

After reading and installing the requirements on the GitHub page.... it works! :smiley: :+1:

Please put a little reminder on the extension description page that one should install those tools first. (I'm a coder, but I'm intentionally doing this from a users' perspective)

hemanti0503 commented 2 years ago

Works like a charm now. Thank you for fixing this so fast and also for this beautiful extension! This is exactly what I was looking for. :)

Do you know by any chance, if/how I can make ulauncher output more than 15 results?

hillaryychan commented 2 years ago

@hemanti0503 currently I've hardcoded the number of results to be 15 cause that was what suited me but I've created #15 to add this in soon.

Also thank you all for using this extension and giving feedback. Wasn't actually expecting anyone else to use this :sweat_smile:

hemanti0503 commented 2 years ago

Thank you! Why I installed it in the beginning was that it's the only extension I found that will give me the possibility to exclude directories. But now I'm also amazed by its speed.