You are not logged in.

#1 2017-07-29 21:41:48

stupidus
Member
Registered: 2012-02-27
Posts: 124

[solved] Script working from terminal, but not as i3 keybind

I am trying to create a script to use ag and rofi to search for files on my system.

~/.scripts/rofi-search

#!/bin/bash

cd ~
searchterm=$(rofi -dmenu -i -p 'Search:')
xdg-open "$(~/.scripts/search $searchterm | rofi -dmenu -i -p 'Results:')"

~/.scripts/search

#!/bin/bash

ag -i -g $1 2> /dev/null

Calling ~/.scripts/rofi-search from the terminal is working fine and doing what I want, meaning it first asks me for a search term, and then shows the results, and I can open the file that I want by hitting enter.

I then added the following line to my i3 config:

bindsym $mod+s exec ~/.scripts/rofi-search

Now, mod+s will open rofi and ask me for the search term. However, it always returns an empty list.

What could be the reason for this behaviour and how could I try to debug this?

Last edited by stupidus (2017-07-30 12:19:24)

Offline

#2 2017-07-30 07:37:32

adesh
Member
Registered: 2016-10-05
Posts: 167

Re: [solved] Script working from terminal, but not as i3 keybind

First, quote $searchtem in xdg-open line.
Second, environment in which i3 executes scripts can be different. In better words, don't rely on environment while scripting. Try using absolute path in place of "~".

Last edited by adesh (2017-07-30 07:38:07)

Offline

#3 2017-07-30 12:18:11

stupidus
Member
Registered: 2012-02-27
Posts: 124

Re: [solved] Script working from terminal, but not as i3 keybind

Thanks, for the help. I applied the changes that you suggested and I also moved everything into one script.

#!/bin/bash

cd /home/stupidus
searchterm=$(rofi -dmenu -i -p 'Search:')
xdg-open "$(ag -i -g "$searchterm" 2> /dev/null | rofi -dmenu -i -p 'Results:')"

However, the result is still the same.

I then tried to use other commands instead of ag, e.g. ls | grep, which worked, so it seemed to be a problem with ag.

I then found this. While it seems unrelated, the second answer suggests to use the --vimgrep option for ag. As it turns out, that solves the problem. I don't really understand why, but at least it's working now.

Offline

Board footer

Powered by FluxBB