#!/usr/bin/env bash
# winezgui-remove-wine-created-shortcuts
# Remove all .desktop files, which has WINEPREFIX value
# Reason is to keep menus uncluttered.
# Installing software with wine creates many shortcuts which looks cluttered.
# winezgui needs to keep it clean, like flatpak, system install should also be
# clutter free!
# WineZGUI game prefix should not clutter system menu.
winezgui-remove-wine-created-shortcuts()
{
  dbug "I: $(basename ${0}): Launched ${FUNCNAME[0]}"
    
  SOURCE "script-check-variables-loaded-or-not"
  script-check-variables-loaded-or-not
  WINE_SHORTCUT_DIR="$(realpath -m ~/.local/share/applications/wine)"
  # e.g., ~/.local/share/winezgui/npp.8.4.2.Installer.x64 for npp created by
  # Installed at $WINE_SHORTCUT_DIR,
  SAVEIFS=${IFS}
  IFS=$(echo -en "\n\b")
  # if applications/wine directory exists and it is writable
  if [ -d "${WINE_SHORTCUT_DIR}" ] && [ -w "${WINE_SHORTCUT_DIR}" ]; then
  WINE_SHORTCUTS=$(grep -ri "winezgui" "${WINE_SHORTCUT_DIR}" \
                  |cut -f1 -d ":"|sort -u)
  fi
  if [ ! -z "$WINE_SHORTCUTS" ]; then
       rm $WINE_SHORTCUTS  && \
       dbug "I: Script: Launch: Remove Wine Created Shortcuts: Removed!"
  fi
  IFS=${SAVEIFS}
  unset WINE_SHORTCUTS
  return 0
}
