#!/bin/bash

cipher_dir=$(jq -r .[].cipher_dir "${HOME}/.config/gocryptfs-wofi/config.json")
mount_dir=$(jq -r .[].mount_dir "${HOME}/.config/gocryptfs-wofi/config.json")

op=$(echo -e "Mount\nUnmount" | wofi -w 2 --height 125 -i --dmenu | awk '{print tolower($0)}')

case ${op} in
  mount )
    mkdir -p "${mount_dir}"
    gocryptfs-ui "${cipher_dir}" "${mount_dir}" && notify-send "mounted gocryptfs vault" || notify-send "failed to mount gocryptfs vault"
  ;;
  unmount )
    umount "${mount_dir}" && notify-send "unmounted gocryptfs vault." || notify-send "failed to unmount gocryptfs vault" 
    rmdir "${mount_dir}"
  ;;
esac
