#!/usr/bin/env bash

dmenu_string="Wrong parameter"

case $1 in
    "rename")
        dmenu_string="Rename desktop to: " ;;
    "delete")
        dmenu_string="Really delete this desktop? (n = abort): " ;;
    "swap")
        dmenu_string="Swap desktop with desktop: " ;;
    "swapfollow")
        dmenu_string="Swap and follow desktop with desktop: " ;;
esac

if [[ $1 == "delete" || $1 == "rename" ]]; then
    desktop=$(echo "" | dmenu -i -fn Hack -nb "#282a36" -nf "#f8f8f2" -sb "#44475a" -sf "#f8f8f2" -p "$dmenu_string")
else
    if [[ $1 != "bubbleprev" && $1 != "bubblenext" ]]; then
        desktop=$(bspc query -m focused -D --names | dmenu -i -fn Hack -nb "#282a36" -nf "#f8f8f2" -sb "#44475a" -sf "#f8f8f2" -p "$dmenu_string")
    fi
fi

case $1 in
    "rename")
        if [[ $desktop != "" ]];
        then
            bspc desktop -n $desktop
        fi
        ;;
    "delete")
        echo $desktop
        if [[ $desktop != "n" ]];
        then
            bspc desktop -r
        fi
        ;;
    "swap")
        bspc desktop -s $desktop ;;
    "swapfollow")
        bspc desktop -s $desktop --follow ;;
    "bubbleprev")
        bspc desktop -b prev ;;
    "bubblenext")
        bspc desktop -b next ;;
esac
