#!/bin/bash

[ $# -eq 0 ] && { echo "Usage: $0 file.yaml"; exit 1; }

DIR=$(dirname "$0")

var=$(python3 "$DIR"/bookmarks.py "$1" | dmenu -i -l 20)

if [ -z "$var" ]
then
    exit
fi

if [[ "$var" == *"\""* ]]; then
    xdotool type "$(python3 "$DIR"/bookmarks.py "$1" "$var")"
    exit
fi

while true
do
    var=$(python3 "$DIR"/bookmarks.py "$1" "$var" | dmenu -i -l 20)

    if [ -z "$var" ]
    then
        exit
    fi

    if [[ "$var" == *"\""* ]]; then
        xdotool type "$(python3 "$DIR"/bookmarks.py "$1" "$var")"
        exit
    fi
done
