Yad 0.13 - fill list with arrays

249 views
Skip to first unread message

Gotsi Boon

unread,
Aug 18, 2011, 5:56:16 AM8/18/11
to yad-common
Hi all,

I try to fill a "yad --list" with the elements from three arrays. I
have three columns, the elemeents should be shown in the correct
order.
The arrays are initialised and filled with elements on the fly with
info I grep from files. In advance I don't know how much files are
going to be found and therefore I don't know how much elements will be
in an array. But each array has the same total-number of items in it.

So far it looks like this:

confiles=`ls -1 /home/gotsiboon/somefolder/*.txt`

for f in ${confiles[@]}; do

name=`grep '^name=' $f | awk -F "=" '{print $2}'`
server=`grep '^server=' $f | awk -F "=" '{print $2}'`
user=`grep '^user=' $f | awk -F "=" '{print $2}'`

declare -a aname=("${aname[@]}" "$name")
declare -a aserver=("${aserver[@]}" "$server")
declare -a auser=("${auser[@]}" "$user")

done

yad --list \
--column="Session":TEXT "${aname[@]}" \
--column="Server":TEXT "${aserver[@]}" \
--column="User":TEXT "${auser[@]}"

My problems are:
1. The order of the elements is not correctly shown.
2. If elements are double (as for instance 2 times the same IP), the
specific IP is only listed once instead of twice.

Anybody has a clue how to show the elements for more than one column
in correct order?
I know the 2nd problem has nothing to do with yad, but maybe somebody
has an idea that helps?

If I would have fixed arrays like this:

declare -a aname=('test1' 'test2' 'test3' )
declare -a aserver=('192.168.0.1' '192.168.0.2' '192.168.0.1' )
declare -a auser=('gotsi' 'gotsi' 'boon' )

there wouldn't be the 2nd problem. But I don't know how much and what
elements are in the particular array. The only thing I know is that
there always be exactly a many elements in each array as files with
appropriate info are found.

Thanks & regards,
gotsiboon.

Gotsi Boon

unread,
Aug 18, 2011, 9:52:57 AM8/18/11
to yad-common

Stupid me... I found a typo in the files (where I get the info for my
arrays from). So, forget about 2nd question!

But the question how to order the elements in the array that they are
shown in the correct column is still left unanswered. Doesn't anybody
have a hint for me?


Thanks & regards,
gotsiboon.

Gotsi Boon

unread,
Aug 18, 2011, 9:59:42 AM8/18/11
to yad-common
Alright, now I found the answer to my first question:

I works like this:

confiles=`ls -1 /home/gotsiboon/somefolder/*.txt`

for f in ${confiles[@]}; do

name=`grep '^name=' $f | awk -F "=" '{print $2}'`
server=`grep '^server=' $f | awk -F "=" '{print $2}'`
user=`grep '^user=' $f | awk -F "=" '{print $2}'`

declare -a alist=("${alist[@]}" "$name" "$server" "$user")

done

yad --list \
--column="Session":TEXT \
--column="Server":TEXT \
--column="User":TEXT "${alist[@]}"


Regards,
gotsiboon.

BTW: Victor, once again: Thx for the great YAD!

Victor Ananjevsky

unread,
Aug 19, 2011, 1:01:59 AM8/19/11
to yad-c...@googlegroups.com
On Thu, 18 Aug 2011 06:59:42 -0700 (PDT)
Gotsi Boon <gotsi...@gmail.com> wrote:

> Alright, now I found the answer to my first question:
>
> I works like this:
>
> confiles=`ls -1 /home/gotsiboon/somefolder/*.txt`
>
> for f in ${confiles[@]}; do
>
> name=`grep '^name=' $f | awk -F "=" '{print $2}'`
> server=`grep '^server=' $f | awk -F "=" '{print $2}'`
> user=`grep '^user=' $f | awk -F "=" '{print $2}'`
>
> declare -a alist=("${alist[@]}" "$name" "$server" "$user")
>
> done
>
> yad --list \
> --column="Session":TEXT \
> --column="Server":TEXT \
> --column="User":TEXT "${alist[@]}"
>

some offtopic - using awk in your example is overhead. you may simplify this by using such loop

for f in ${confiles[@]}; do

eval $(sed -r 's/=(.*)$/="\1"/' $1 | grep -o -E "^(name|server|user).*$")


declare -a alist=("${alist[@]}" "$name" "$server" "$user")
done


>

> Regards,
> gotsiboon.
>
> BTW: Victor, once again: Thx for the great YAD!


--
Victor Ananjevsky <anan...@gmail.com>

Gotsi Boon

unread,
Aug 19, 2011, 3:51:33 AM8/19/11
to yad-common

Nice, thanks once more.


On 19 Aug., 07:01, Victor Ananjevsky <anana...@gmail.com> wrote:
> On Thu, 18 Aug 2011 06:59:42 -0700 (PDT)

Reply all
Reply to author
Forward
0 new messages