You are not logged in.

#1 2020-07-27 14:26:41

AcidGod
Member
Registered: 2019-02-13
Posts: 34

Cannot get fzf script to open result in phpstorm - dmenu fzf replaceme

Hi,
I am trying to replace dmenu with fzf, but the problem I face is that every time when my script is trying to open result of fzf in phpstorm I get two windows one with terminal and the other one with phpstorm. If I close terminal window it closes the phpstorm. I do understand that I need to start phpstorm process in a background but no matter what I try it doesn't work. Here are my scripts.

storm script

#!/bin/sh

result=$(find $HOME/www -type d | fzf)

[[ -z $result ]] && exit 

phpstorm $result 

fzfmenu script for binding

#!/usr/bin/env bash
# fzfmenu - fzf as dmenu replacement

input=$(mktemp -u --suffix .storm.input)
output=$(mktemp -u --suffix .storm.output)
mkfifo $input
mkfifo $output
chmod 600 $input $output

# it's better to use st here (starts a lot faster than pretty much everything else)
st -c stormfzf -n stormfzf -e sh -c "storm"  & disown

# handle ctrl+c outside child terminal window
trap "kill $! 2>/dev/null; rm -f $input $output" EXIT

cat > $input
cat $output

If I add `&` to phpstorm $result command it just closes windows before phpstorm starts

Last edited by AcidGod (2020-07-27 15:20:39)

Offline

#2 2020-07-27 16:16:31

ondoho
Member
Registered: 2013-04-30
Posts: 692
Website

Re: Cannot get fzf script to open result in phpstorm - dmenu fzf replaceme

Your script seems overly complicated to me.
What are those fifo's for?
If your intent is to emulate dmenu behaviour with a terminal & fzf, this is what I came up with:

#!/bin/sh
# fzfmenu - fzf as dmenu replacement

# it's better to use st here (starts a lot faster than pretty much everything else)
exec urxvt -e sh -c 'result=$(find $HOME -name "*.sh" | fzf);[ -z "$result" ] && exit;exec geany "$result"'

edit: Ooops, I can see the problem now, which presents just as described in the shorter script above.

Last edited by ondoho (2020-07-27 16:25:21)

Offline

#3 2020-07-27 17:10:57

AcidGod
Member
Registered: 2019-02-13
Posts: 34

Re: Cannot get fzf script to open result in phpstorm - dmenu fzf replaceme

The example of fzfmenu script comes from official repo https://github.com/junegunn/fzf/wiki/Ex … eplacement, I am running it with dwm rather than urxvt.
Basically I need to run fzfmenu to get a suckless terminal popup with fzf running in it. The official fzf menu uses  & disown to send st to the background. Unlike vscode and sublime, phpstorm is using java to start the application which causes the output to be displayed within opened st terminal from fzfmenu script. If I change storm script to nohup for starting phpstorm I can close that st window with java outpup and it keeps the application open, but that the extra step that I want to remove, so that if I bind fzfmenu to the keyboard I can select the folder I need and get it opened in phpstorm without any additional windows.

I can do something as simple as that but it keeps the terminal open after phpstorm starts.

storm script:

#!/bin/bash

result=$(find ~/www -type d | fzf )

[ -z $result ] && exit
nohup phpstorm $result >/dev/null 2>&1

fzfmenu script

#!/usr/bin/env bash

# it's better to use st here (starts a lot faster than pretty much everything else)
st -c fzfmenu -n fzfmenu -e sh -c "storm" & disown

Last edited by AcidGod (2020-07-27 17:17:11)

Offline

#4 2020-07-27 17:24:55

AcidGod
Member
Registered: 2019-02-13
Posts: 34

Re: Cannot get fzf script to open result in phpstorm - dmenu fzf replaceme

I have managed to close the window by adding `sleep 9; kill $!` to fzfmenu script, which gives me 9 seconds to make a selection and then it closes terminal window. Ideally, I need it to be closed straight after fzf selection is made and phpstorm is starting but I have not idea how.

Last edited by AcidGod (2020-07-27 17:26:54)

Offline

#5 2020-07-28 09:34:41

ondoho
Member
Registered: 2013-04-30
Posts: 692
Website

Re: Cannot get fzf script to open result in phpstorm - dmenu fzf replaceme

I think this does what you want:

phpstorm "$(find $HOME/www -type d | fzfmenu)"

(use the example script exactly as it is in the wiki)

Offline

#6 2020-07-28 10:02:18

AcidGod
Member
Registered: 2019-02-13
Posts: 34

Re: Cannot get fzf script to open result in phpstorm - dmenu fzf replaceme

@ondoho I don't if you read the post but I am not trying to figure out the command I need to use to initiate the opening of phpstorm, I am struggling to get the terminal window with phpstorm output to be closed upon phpstorms opening.
On top of that the command you specified in its form will cause phpstorm opening even if no selection is done.

Last edited by AcidGod (2020-07-28 10:03:56)

Offline

#7 2020-07-28 10:40:49

ondoho
Member
Registered: 2013-04-30
Posts: 692
Website

Re: Cannot get fzf script to open result in phpstorm - dmenu fzf replaceme

AcidGod wrote:

@ondoho I don't if you read the post but I am not trying to figure out the command I need to use to initiate the opening of phpstorm, I am struggling to get the terminal window with phpstorm output to be closed upon phpstorms opening.

I know what you want. We both tried it your way and didn't succeed.
The command above does what you want.

AcidGod wrote:

On top of that the command you specified in its form will cause phpstorm opening even if no selection is done.

You can script around that easily. C'mon.

Offline

#8 2020-07-28 13:05:35

AcidGod
Member
Registered: 2019-02-13
Posts: 34

Re: Cannot get fzf script to open result in phpstorm - dmenu fzf replaceme

ondoho wrote:
AcidGod wrote:

@ondoho I don't if you read the post but I am not trying to figure out the command I need to use to initiate the opening of phpstorm, I am struggling to get the terminal window with phpstorm output to be closed upon phpstorms opening.

I know what you want. We both tried it your way and didn't succeed.
The command above does what you want.

AcidGod wrote:

On top of that the command you specified in its form will cause phpstorm opening even if no selection is done.

You can script around that easily. C'mon.

thank you for your kind suggestion

Offline

#9 2020-07-28 14:03:01

AcidGod
Member
Registered: 2019-02-13
Posts: 34

Re: Cannot get fzf script to open result in phpstorm - dmenu fzf replaceme

Here is the solution I came up with so far.

fzfmenu script:

#!/usr/bin/env bash

st -c fzfmenu -n fzfmenu -g "100x12" -e sh -c "storm" & disown

storm script:

#!/bin/bash

result=$(find ~/www -type d | fzf)

[ -z $result ] && exit

(nohup phpstorm $result >/dev/null 2>&1 &)

pkill -f fzfmenu

Last edited by AcidGod (2020-07-28 16:21:22)

Offline

Board footer

Powered by FluxBB