Yad (Yet another Dialog) list columns

3.2k views Asked by At

I need some help with YAD. So here is the code:

contact=$(while read line
            do
                firstname=$(echo $line | awk 'BEGIN { FS="|" } { print $2 }')
                lastname=$(echo $line | awk 'BEGIN { FS="|" } { print $3 }')
                num=$(echo $line | awk 'BEGIN { FS="|" } { print $4 }')
                birthday=$(echo $line | awk 'BEGIN { FS="|" } { print $5 }')

                if [  $firstname != ""  -a  $lastname != "" ] ; then
                    echo "$firstname$lastname"
                else
                    if [ $firstname != "" ] ; then
                        echo "$firstname,"
                    elif [ $lastname != "" ] ; then
                        echo "$lastname"
                    else
                        echo "$num"
                    fi
                fi

            done < "contactlist.txt" )
idlist=$(while read line
            do
                idnum=$(echo $line | awk 'BEGIN { FS="|" } { print $1}')
                echo $idnum
            done < "contactlist.txt" )

sortcontact=$(printf "%s\n" $contact | sort)

selected=$(yad --title="Contacts" --width=200 --height=200 --button="DISPLAY:2" --button="ADD:3" --list --separator=""  --column="List" $sortcontact --column="ID:NUM" $idlist)

The output: the $idlist and $sortcontact are all mixed up.

What I want: the column ID should only have the $idlist while the column List should only have the $sortcontact.

The txt file:

1|Joanne|Perez|9173046751.000000|Mar 31|
2|Nikko|Real|9065887272.000000|Mar 21|
3|Try|Haha|9000000000.000000|Jan 15|
4|Nikko|Real|9065887272.000000|Jan 21|
5|Paolo|Perez|9212345678.000000|Jan 25|
1

There are 1 answers

0
joanne_ On BEST ANSWER
#!/usr/bin/env bash
items=()
while IFS='|' read -r idnum firstname lastname num birthday _; do
    if [[ $firstname || $lastname ]]; then
        items+=( "$firstname $lastname" "$idnum" )
    else
        items+=( "$num" "$idnum" )
    fi
done < <(sort -t'|' -k2 contactlist.txt)

selected=$(yad --title=Contacts --width=200 --height=200 \
               --button=DISPLAY:2 --button=ADD:3 --list \
               --separator= --column=List --column=ID:NUM \
               "${items[@]}")

Answered by geirha in: https://askubuntu.com/questions/408710/yad-list-columns/408732?noredirect=1#408732