You are not logged in.

#1 2016-10-28 08:11:53

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,740

yad gui file selector

So basically I'am looking for a better looking alternative for this
http://worldwidemann.com/a-gui-file-pic … s-of-code/

The usage is like
a. type a command line, like: mpv
b. some hotkey to open multiple file selector (all this defined in .bashrc)
c. selection is magically pasted to command line, getting: mpv '/path/to/file1' '/path/to/file2'

Now i'am stuck here (Yad dialog looks perfect to me, especially since it has sort-by-date column)

select_files() {
                      yad --file --multiple
}
bind -x '"\C-g":select_files'
# ctrl+g launches file-selector.

which obviously doesn't work, ideas on how to proceed?

Last edited by brontosaurusrex (2016-10-28 10:51:38)

Offline

#2 2016-10-28 09:14:52

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: yad gui file selector

You need to get the returned value(s) from the yad file dialog.

retfile=$(yad --file --multiple)
echo "$retfile"    # just to see what you have

There probably should be some error checking in there, in case the dialog was cancelled etc, along the lines of

if $?;then...else

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2016-10-28 09:23:26

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,740

Re: yad gui file selector

Another non-working example

select_files() {
local files="$(yad --file --multiple)"
IFS='|' read -ra array <<< "$files"
READLINE_LINE="${READLINE_LINE:0:READLINE_POINT}$files${READLINE_LINE:READLINE_POINT}"
READLINE_POINT=$((READLINE_POINT + ${#array}))
}
bind -x '"\C-g":select_files'

Is there a way to make yad to return some sane parameters  (instead of pipe separated list)?

Last edited by brontosaurusrex (2016-10-28 09:23:47)

Offline

#4 2016-10-28 09:34:21

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: yad gui file selector

brontosaurusrex wrote:

...
Is there a way to make yad to return some sane parameters  (instead of pipe separated list)?

Well, that is the expected behaviour for yad. You can tell it use a different delimiter, but you will always get a returned list.

The BL scripts have some examples you can inspect, eg the conky chooser script, '/usr/bin/bl-cconkyzen'.


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#5 2016-10-28 10:21:09

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,740

Re: yad gui file selector

The one that is very close (and I don't know what is actually doing anymore, so pure magic)

# Yad gui file selector
# put in .bashrc and call with ctrl+g from terminal
select_files() { 
local file files i IFS=' '
local -n l=READLINE_LINE p=READLINE_POINT
while IFS= read -rd '' file; do printf -v 'files[i++]' %q "$file"
done < <(yad --file --multiple --width=600 --height=600 --center | tr '|\n' '\0\0')
files="${files[*]}" l=${l:0:p}$files${l:p} p=$((p+${#files})); 
}
bind -x '"\C-g":select_files'

(Thanks to geirha from freenode/#bash)

Last edited by brontosaurusrex (2016-10-28 11:13:17)

Offline

#6 2016-11-11 12:25:41

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,740

Re: yad gui file selector

--quoted-output

@misko_2083, Nice, that will teach me to read the manuals more carefully.

Offline

Board footer

Powered by FluxBB