You are not logged in.

#1 2022-08-26 10:18:46

duyinthee
Member
Registered: 2015-06-14
Posts: 172

fzf file launcher

I am using Arch + sway.

I am trying to have a vary little and simple file launcher.
I have a small script like

#!/bin/bash
file=$(fzf)
[ -f "$file" ] && xdg-open "$file" &

It works very well if I execute the script in terminal.
But I want to use it as Rofi, for example, I will keybind to open terminal and run the script in it.
If I execute by keybinding like

bindsym Alt+r exec foot -e /path/to/script

it will start foot and run fzf in it but it does not launch the file by select and enter.
What I am missing.

Last edited by duyinthee (2022-08-26 10:20:51)

Offline

#2 2022-08-26 10:34:48

dogknowsnx
Member
Registered: 2021-04-12
Posts: 392

Re: fzf file launcher

Try removing the trailing '&' from your script...


Wayland.

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#3 2022-08-26 10:51:22

duyinthee
Member
Registered: 2015-06-14
Posts: 172

Re: fzf file launcher

Yeah, by removing "&", it will launch the file but the terminal will not close.

Offline

#4 2022-08-26 11:26:31

seth
Member
Registered: 2012-09-03
Posts: 33,322

Online

#5 2022-08-26 13:31:30

duyinthee
Member
Registered: 2015-06-14
Posts: 172

Re: fzf file launcher

#!/bin/bash
file=$(fzf)
[ -f "$file" ] && "xdg-open "$file" & disown"

and

#!/bin/bash
file=$(fzf)
[ -f "$file" ] && xdg-open "$file" & disown

both do not work.

Offline

#6 2022-08-26 13:33:50

seth
Member
Registered: 2012-09-03
Posts: 33,322

Re: fzf file launcher

What do you mean by "do not work"?
What happens?
Is this maybe an issue of https://bbs.archlinux.org/viewtopic.php … 6#p2053636 ?

Edit: the 2nd one btw. the 1st one is nonsensical

Last edited by seth (2022-08-26 13:34:31)

Online

#7 2022-08-26 14:56:48

duyinthee
Member
Registered: 2015-06-14
Posts: 172

Re: fzf file launcher

I mean it will not open the file.
the script, the 2nd one, btw

#!/bin/bash
file=$(fzf)
[ -f "$file" ] && xdg-open "$file" & disown

will not open the file but the terminal will close.

the way I am trying is that I set keybind to the script to open terminal (foot) and run the script.
so I have this

bindsym Alt+r exec foot -e /path/to/script

in my ~/.config/sway/config.
Then I will hit Alt+r and terminal (foot) will open, fzf in it, I type something for search and hit enter.
Here the way I way I want is that, the file open and the terminal (foot) will close.

I still can't get it works.

Offline

#8 2022-08-26 17:05:29

seth
Member
Registered: 2012-09-03
Posts: 33,322

Re: fzf file launcher

Can you "… && xterm & disown" (assuming xterm is installed) ie. run anything but xdg-open?

Online

#9 2022-08-27 00:37:21

duyinthee
Member
Registered: 2015-06-14
Posts: 172

Re: fzf file launcher

Yes.

#!/bin/bash
file=$(fzf)
[ -f "$file" ] && xterm & disown

the terminal (foot) will close but xterm will not open.

#!/bin/bash
file=$(fzf)
[ -f "$file" ] && xterm && disown

the terminal (foot) will not close but xterm will open.

I tested with alacritty and firefox. All same.

Last edited by duyinthee (2022-08-27 00:38:06)

Offline

#10 2022-08-27 06:06:30

seth
Member
Registered: 2012-09-03
Posts: 33,322

Re: fzf file launcher

the terminal (foot) will not close but xterm will open.

Because that is nonsens. Please do not enter random strings into a shell, you could end up screwing yourself badly.

#!/bin/bash
file=$(fzf)
[ -f "$file" ] && nohup xdg-open "$file" & disown
#!/bin/bash
file=$(fzf)
[ -f "$file" ] || exit
[ -e /dev/fd/0 ] || exec 0</dev/null
[ -e /dev/fd/1 ] || exec 1>/dev/null
[ -e /dev/fd/2 ] || exec 2>/dev/null
xdg-open "$file" & disown

Online

Board footer

Powered by FluxBB