Tomas-M / xlunch

Graphical app launcher for X with minimal dependencies
http://xlunch.org
GNU General Public License v3.0
219 stars 37 forks source link

entries.dsv is found when running xlunch from terminal, but not in other cases. #91

Open fredx181 opened 6 years ago

fredx181 commented 6 years ago

When running xlunch from terminal without input, e.g.-i /path/to/entries_file it will find automatically /etc/xlunch/entries.dsv or $HOME/.config/xlunch/entries.dsv if one of these exists. Which is intended behavior, as far as I understand, and works fine (when run from terminal).

But in case of a script (without specifying -i /path/to/entries_file) entries.dsv seems not found when running it from a file-manager, by clicking on the script. I found this is the case with file managers:

Fred

PMunch commented 6 years ago

Hmm, this is a really strange bug. I tried to create a simple wrapping script that would log any output from the script to a file. But after running it from pcmanfm the log file is completely empty and xlunch started without any entries. Not entirely sure what causes this though.. Clicking it and select "Execute in terminal" works just fine, it's just when it runs without a terminal that it happens.

I have it running from scripts in my setup though, but those are executing by keyboard shortcuts through i3. So it's something that all these menus and file managers have in common which prevents xlunch from running properly..

PMunch commented 6 years ago

I think this has to do with how xlunch is able to read from a pipe stream as well as from a file. In normal operation it will wait for data on stdin, fail, and then default back to looking for files. For some reason it think it get's input on stdin so it tries to read entries from there instead, which fails because there aren't any there. To circumvent this you can either just cat your entries to xlunch, or you can use the --input flag to tell xlunch explicitly to read from a file.

fredx181 commented 6 years ago

Ok, pity that it can't be fixed. What I actually want is that the script checks if entries.dsv exist in one of the default locations. If not, use gentriesquick to pipe to xlunch But this workaround works OK for me:

if [ ! -f /etc/xlunch/entries.dsv -a ! -f $HOME/.config/xlunch/entries.dsv ]; then
# pipe genquick to xlunch
x_lunch (){ gentriesquick 48 | xlunch "$@"; }
else
# use entries.dsv, if exist in $HOME it has priority
[ -f $HOME/.config/xlunch/entries.dsv ] && ENTRIES=$HOME/.config/xlunch/entries.dsv || ENTRIES=/etc/xlunch/entries.dsv
x_lunch (){ xlunch -i "$ENTRIES" "$@"; }
fi
# run function x_lunch with arguments
x_lunch ... ... ...

I used this also in the examples that are contained in the .deb package concept I made: https://github.com/Tomas-M/xlunch/issues/48#issuecomment-412264773

fredx181 commented 6 years ago

On second thought, I didn't like the above, so worked around the problem in a different way now:

#!/bin/bash

if [ ! -f /etc/xlunch/entries.dsv -a ! -f $HOME/.config/xlunch/entries.dsv ]; then
# pipe genquick to xlunch
gentriesquick 48 | /usr/local/xlunch/xlunch "$@"
else
# use entries.dsv, if exist in $HOME it has priority
[ -f $HOME/.config/xlunch/entries.dsv ] && ENTRIES=$HOME/.config/xlunch/entries.dsv || ENTRIES=/etc/xlunch/entries.dsv
/usr/local/xlunch/xlunch -i "$ENTRIES" "$@"
fi

This way I can use xlunch normally in scripts, without having to use function like in above comment. Works for me !