configure 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. set -e
  3. set -u
  4. set -o pipefail
  5. get_current_mutt_config() {
  6. local dot_mutt_config=${1:?}
  7. local firstline=
  8. touch ${dot_mutt_config}
  9. read -r firstline < ${dot_mutt_config}
  10. echo ${firstline}
  11. }
  12. mutt_configure_main() {
  13. local dot_mutt_dir=${1:?}
  14. local load_current=${2:-"current"}
  15. local dot_mutt_config=${dot_mutt_dir}/.mutt-config
  16. local current_mutt_config=$(get_current_mutt_config $dot_mutt_config)
  17. mkdir -p ${dot_mutt_dir}/tmp
  18. if [ "current" == "$load_current" ]; then
  19. echo ${current_mutt_config}/config
  20. else
  21. local first=""
  22. local hit=""
  23. local done=""
  24. for file in ${dot_mutt_dir}/var/*; do
  25. [ -e "$file" ] || continue
  26. if [ "" == "$first" ]; then
  27. first="$file"
  28. fi
  29. if [ "" == "$current_mutt_config" ]; then
  30. current_mutt_config="$first"
  31. echo $first > ${dot_mutt_config}
  32. fi
  33. if [ "$hit" == "hit" ]; then
  34. done="done"
  35. echo "$file" > ${dot_mutt_config}
  36. break
  37. fi
  38. if [ "$file" == "$current_mutt_config" ]; then
  39. hit="hit"
  40. fi
  41. done
  42. if [ "$done" != "done" ]; then
  43. echo "$first" > ${dot_mutt_config}
  44. fi
  45. local next_mutt_config=$(get_current_mutt_config $dot_mutt_config)
  46. echo ${next_mutt_config}/config
  47. fi
  48. }
  49. mutt_configure_main "${HOME}/.mutt" ${1:-}