Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fzf support? #48

Open
hyiltiz opened this issue Nov 6, 2015 · 18 comments
Open

fzf support? #48

hyiltiz opened this issue Nov 6, 2015 · 18 comments
Labels

Comments

@hyiltiz
Copy link

hyiltiz commented Nov 6, 2015

Would be great if one could do fuzzy search. Maybe you can detect and perform fuzzy search if fzf is present in the system. The implementation should be as easy as adding two pipes, around fzf.

@enkore
Copy link
Owner

enkore commented Nov 7, 2015

It should be possible to integrate fzf and dmenu without changing this application. Maybe fzf even supports a "pipe-through" mode? (maybe something like j4-d-d --dmenu="fzf --pipe-into-and-read-input-from=dmenu")

@hyiltiz
Copy link
Author

hyiltiz commented Nov 7, 2015

Yeah, I think something like that. FZF is a standard UNIX pipe.

On Fri, Nov 6, 2015, 19:01 enkore [email protected] wrote:

It should be possible to integrate fzf and dmenu without changing this
application. Maybe fzf even supports a "pipe-through" mode? (maybe
something like j4-d-d --dmenu="fzf --pipe-into-and-read-input-from=dmenu")


Reply to this email directly or view it on GitHub
#48 (comment)
.

from Google Inbox

@b0ch3nski
Copy link

Please excuse me this little necrobump, but I'm struggling with this approach:

j4-dmenu-desktop --dmenu="fzf --prompt='Run: ' --height 100% --reverse --cycle"

It works, but the selected process is not being started in background and therefore it blocks the launcher terminal from exiting. The same approach works 100% fine using i3-dmenu-desktop and the terminal is gone after application is selected:

i3-dmenu-desktop --dmenu="fzf --prompt='Run: ' --height 100% --reverse --cycle"

... but it's noticeably (painfully) slower :(

@enkore, is there a reason those two behave differently? Can I get somehow j4dd to behave like i3dd?

@enkore
Copy link
Owner

enkore commented Jun 26, 2017

IIRC i3dd uses some proprietary i3 stuff (i3-sendmsg or so) to have i3 start the process on its behalf, j4dd stopped doing that years ago to be independent of i3.

Try

j4-dmenu-desktop --dmenu="fzf --prompt='Run: ' --height 100% --reverse --cycle" &

@b0ch3nski
Copy link

b0ch3nski commented Jun 27, 2017

Adding simple ampersand at the end of command results in:

Failed to read /dev/tty

and nothing shows up.

I believe that i3dd uses i3-msg exec <cmd>.

Would it be possible to just return the selection from j4dd instead of executing it (something like --no-exec)?
Then I could use it this way:

selection=$(j4-dmenu-desktop --no-exec --dmenu="fzf --prompt='Run: ' --height 100% --reverse --cycle")
[[ -z $selection ]] || i3-msg exec $selection

@ritobanrc
Copy link

Is this going to be resolved? I would also like to use fzf as an app launcher, but i3dd + fzf is too slow for my liking. For me, j4dd just doesn't detach from the terminal. Would this be possible to implement?

@b0ch3nski
Copy link

b0ch3nski commented Feb 26, 2019

@ritobanrc see my comment above - someone would have to implement a switch to disable automatic selection execution 🙏

@enkore
Copy link
Owner

enkore commented May 13, 2019

That seems reasonable to me. It should then just output the command line on stdout?

@mmartin
Copy link

mmartin commented May 19, 2019

My solution is to override the SHELL variable.

Create a file which will be used as the fake shell:

#!/bin/bash
function run_dmenu {
    while test $# -gt 0; do
        [[ $1 == fzf ]] && return 0
        shift
    done
    return 1
}
if run_dmenu $*; then
    SHELL=/bin/bash exec /bin/bash "$@"
else
    shift
    [[ $1 == -c ]] && shift
    exec echo "$@"
fi

Then use j4dd like this:

cmd=$(SHELL=/path/to/fake_shell j4-dmenu-desktop --dmenu=fzf | sed -n 2p)
[[ -n "$cmd" ]] && i3-msg exec "$cmd"

@Eisfunke
Copy link

Eisfunke commented Aug 1, 2019

That seems reasonable to me. It should then just output the command line on stdout?

That'd be great!

@feschber
Copy link

feschber commented Sep 14, 2020

so I got this to work with two scripts like this: (on sway)

----------$HOME/scripts/dmenu-fzf.sh--------------------
#!/bin/bash
swaymsg '[title="dmenu-fzf"]' kill ||
alacritty -t dmenu-fzf -e $HOME/scripts/j4-dmenu-fzf.sh
------------$HOME/scripts/j4-dmenu-fzf.sh----------------------
#!/bin/bash
swaymsg '[title="dmenu-fzf"]' kill ||
alacritty -t dmenu-fzf -e $HOME/scripts/j4-dmenu-fzf.sh

its not perfect though, I'm not sure if the Path part of .desktop files is being respected like this...

would be much nicer, if the launched program would just be disowned by j4-dmenu automatically, so the terminal could close afterwards

@feschber
Copy link

Nevermind I just found out about the wrapper part:

#!/bin/bash
swaymsg '[title="dmenu-fzf"]' kill ||
alacritty -t dmenu-fzf -e j4-dmenu-desktop --wrapper='swaymsg exec' --dmenu=fzf

@b0ch3nski
Copy link

FYI: The code for --no-exec is already in develop branch 🍾

@feschber
Copy link

I don't quite understand the difference to --wrapper.

Right now you would use
alacritty -t dmenu-fzf -e j4-dmenu-desktop --wrapper='swaymsg exec' --dmenu=fzf

with --no-exec you would do
alacritty -t dmenu-fzf -e swaymsg exec $(j4-dmenu-desktop --dmenu=fzf --no-exec)

Am I missing something? This would still involve swaymsg / i3msg or any other program to spawn the program.

What I'd have thought would be a good solution is a --bg / --disown flag, that spawns the program in the background and then terminates j4-dmenu-desktop.

That way you could just do
alacritty -t dmenu-fzf -e j4-dmenu-desktop --dmenu=fzf --bg

@enkore
Copy link
Owner

enkore commented Sep 25, 2020

That would be pretty simple, just fork+setsid before executing.

if(background)
switch(fork()) {
case 0:
   setsid();
   break;
case -1:
   perror("fork");
   return 1;
default:
  return 0;
}

exec(...);

@b0ch3nski
Copy link

Please excuse me this little necrobump, but I'm struggling with this approach:

j4-dmenu-desktop --dmenu="fzf --prompt='Run: ' --height 100% --reverse --cycle"

Fast forward from 2017 to 2024 😄 If someone finds this over Google, here is how I ended up solving this:

j4-dmenu-desktop --no-exec --dmenu='fzf --prompt="Run: "' | xargs -I{} swaymsg "exec {}"

--no-exec was available since Sep 2020: 24a5b9e

@enkore I think that this issue can be closed, can't it?

@meator
Copy link
Collaborator

meator commented Jul 9, 2024

@b0ch3nski I haven't investigated this issue in depth, but I believe that --no-exec hackery with xargs -I{} swaymsg "exec {}" should no longer be necessary. I have implemented i3 IPC support in j4-dmenu-desktop. You should be able to execute things through Sway with:

j4-dmenu-desktop --dmenu='fzf --prompt="Run: "' --i3-ipc

or

j4-dmenu-desktop --dmenu='fzf --prompt="Run: "' -I

Support for i3 IPC was introduced in r3.0, but it contains some bugs which prevent it from being used on Sway. Full support for Sway is not in any released version of j4-dmenu-desktop yet, but you could try out the r3.1 release candidate released yesterday.

@markstos
Copy link

The next version of Fuzzel will include --match-mode=fzf which will include fzf-inspired filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants