#!/usr/bin/env bash
shopt -s nullglob
for ship in "${HOME}/ships/"*; do
  shipname="$(basename "$ship")"
  shipstub="$(basename "$ship" | sed 's/[^A-Za-z0-9]//g' | tr '[:upper:]' '[:lower:]')"
  printf "menu:%s:Write a message from %s:New message\\n" "${shipstub}" "${shipname}"
  printf "  exec:Compose a new message..:edit:${EDITOR:-jed} \"%s/~filename (ending in .txt):~\"\\n" "$ship"
  printf "  exec:Edit Ship Description::${EDITOR:-jed} \"%s\"\\n" "${ship}/.description"
  printf "nop\\n"
  for log in "${ship}/"*; do
    logname="$(basename "${log}")"
    printf "  exec:Edit\\: %s::${EDITOR:-jed} \"%s\"\\n" "$logname" "$log"
  done
  printf "  nop\\n"
  printf "  exit:_Back to main menu..\\n"
done

printf "menu:write:Write a message from which ship?:Author a new message from one of your ships\\n"
for ship in "${HOME}/ships/"*; do
  shipname="$(basename "$ship")"
  shipstub="$(basename "$ship" | sed 's/[^A-Za-z0-9]//g' | tr '[:upper:]' '[:lower:]')"
  printf "  show:%s..::%s\\n" "$shipname" "$shipstub"
done
printf "  nop\\n"
printf "  exit:_Back to main menu..\\n"
