.emacs-autogen.sh
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 25 Dec 2023 20:15:49 +0200
changeset 1772 d97be992a1f9
parent 1764 a40a9f231aa0
permissions -rwxr-xr-x
Introduced Org state FAILED.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
702
0617020b53d8 Fix shebang for FreeBSD.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 696
diff changeset
     1
#!/usr/bin/env bash
386
3efe37437745 Explore environment for abilities and tup config in ~/.emacs-autogen.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
1763
bcd7574bc9c3 Added support for MINGW64 for aspell detection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1446
diff changeset
     3
set -x
bcd7574bc9c3 Added support for MINGW64 for aspell detection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1446
diff changeset
     4
386
3efe37437745 Explore environment for abilities and tup config in ~/.emacs-autogen.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
if [ -z "$1" ]; then
3efe37437745 Explore environment for abilities and tup config in ~/.emacs-autogen.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
  echo "Where config file?"
3efe37437745 Explore environment for abilities and tup config in ~/.emacs-autogen.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
  exit 1
3efe37437745 Explore environment for abilities and tup config in ~/.emacs-autogen.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
fi
3efe37437745 Explore environment for abilities and tup config in ~/.emacs-autogen.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
3efe37437745 Explore environment for abilities and tup config in ~/.emacs-autogen.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
cfg=$1
3efe37437745 Explore environment for abilities and tup config in ~/.emacs-autogen.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    12
# Set host_os:
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    13
#   windows, linux, unknown
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    14
# host_distro:
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    15
#   cygwin, debian, unknown
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    16
check_platform() {
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    17
  case `uname -s` in
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    18
    CYGWIN_NT-*)
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    19
      host_os=windows
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    20
      host_distro=cygwin
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    21
      ;;
1763
bcd7574bc9c3 Added support for MINGW64 for aspell detection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1446
diff changeset
    22
    MINGW64_NT-*)
bcd7574bc9c3 Added support for MINGW64 for aspell detection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1446
diff changeset
    23
      host_os=windows
bcd7574bc9c3 Added support for MINGW64 for aspell detection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1446
diff changeset
    24
      host_distro=mingw64
bcd7574bc9c3 Added support for MINGW64 for aspell detection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1446
diff changeset
    25
      ;;
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    26
    Linux)
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    27
      host_os=linux
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    28
      if [ -e /etc/debian_version ]; then
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    29
        host_distro=debian
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    30
      else
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    31
        host_distro=unknown
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    32
      fi
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    33
      ;;
622
596406094fd1 Port to Mac OS X console Emacs 22.1.1.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 604
diff changeset
    34
    Darwin)
596406094fd1 Port to Mac OS X console Emacs 22.1.1.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 604
diff changeset
    35
      host_os=darwin
596406094fd1 Port to Mac OS X console Emacs 22.1.1.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 604
diff changeset
    36
      ;;
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    37
    *)
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    38
      host_os=unknown
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    39
      ;;
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    40
  esac
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    41
}
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    42
694
9c9c558e8a92 Add 'print_header'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 693
diff changeset
    43
print_header() {
9c9c558e8a92 Add 'print_header'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 693
diff changeset
    44
  echo
9c9c558e8a92 Add 'print_header'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 693
diff changeset
    45
  echo ';; ================================================================'
9c9c558e8a92 Add 'print_header'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 693
diff changeset
    46
  echo ";; ${FUNCNAME[1]}."
9c9c558e8a92 Add 'print_header'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 693
diff changeset
    47
  echo
9c9c558e8a92 Add 'print_header'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 693
diff changeset
    48
}
9c9c558e8a92 Add 'print_header'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 693
diff changeset
    49
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    50
check_ispell() {
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    51
  command -v ispell >/dev/null && return 0 || return 1
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    52
}
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    53
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    54
check_aspell() {
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    55
  command -v aspell >/dev/null && return 0 || return 1
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    56
}
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    57
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    58
print_ispell() {
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    59
  echo '(setq-default ispell-program-name "ispell")'
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    60
  case $host_distro in
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    61
    debian)
1446
78d0fef31a4b Use American English variant for spell checking. Prefer aspell to ispell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
    62
      echo '(setq-default ispell-local-dictionary "american")'
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    63
      ;;
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    64
    unknown)
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    65
      echo '(setq-default ispell-local-dictionary "default")'
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    66
      ;;
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    67
  esac
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    68
}
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    69
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    70
print_aspell() {
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    71
  echo '(setq-default ispell-program-name "aspell")'
1764
a40a9f231aa0 Set dictionary name to american for aspell, this fixes MINGW64 env.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1763
diff changeset
    72
  echo '(setq-default ispell-local-dictionary "american")'
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    73
}
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    74
694
9c9c558e8a92 Add 'print_header'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 693
diff changeset
    75
print_speller() {
9c9c558e8a92 Add 'print_header'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 693
diff changeset
    76
  print_header
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    77
  check_ispell
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    78
  ispell_present=$?
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    79
  check_aspell
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    80
  aspell_present=$?
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    81
  case $host_os in
1446
78d0fef31a4b Use American English variant for spell checking. Prefer aspell to ispell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
    82
    windows|linux)
78d0fef31a4b Use American English variant for spell checking. Prefer aspell to ispell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
    83
      if [ $aspell_present = 0 ]; then
78d0fef31a4b Use American English variant for spell checking. Prefer aspell to ispell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
    84
          print_aspell
78d0fef31a4b Use American English variant for spell checking. Prefer aspell to ispell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
    85
      elif [ $ispell_present = 0 ]; then
78d0fef31a4b Use American English variant for spell checking. Prefer aspell to ispell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
    86
          print_ispell
78d0fef31a4b Use American English variant for spell checking. Prefer aspell to ispell.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1238
diff changeset
    87
      fi
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    88
      ;;
622
596406094fd1 Port to Mac OS X console Emacs 22.1.1.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 604
diff changeset
    89
    darwin)
596406094fd1 Port to Mac OS X console Emacs 22.1.1.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 604
diff changeset
    90
      print_aspell
596406094fd1 Port to Mac OS X console Emacs 22.1.1.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 604
diff changeset
    91
      ;;
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    92
    *)
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    93
      :
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    94
      ;;
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    95
  esac
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    96
}
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
    97
693
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
    98
print_man() {
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
    99
  print_header
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
   100
  if man -a man >/dev/null 2>&1; then
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
   101
    echo '(setq Man-switches "-a")'
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
   102
  else
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
   103
    echo '(setq Man-switches "")'
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
   104
  fi
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
   105
}
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
   106
1238
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   107
print_emacs_sources_dir() {
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   108
  print_header
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   109
  if [[ -d ~/devel/emacs/emacs/src ]]; then
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   110
    echo '(setq find-function-C-source-directory "~/devel/emacs/emacs/src")'
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   111
  else
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   112
    ls ~/devel/emacs/src/emacs.c ~/devel/emacs/emacs*/src/emacs.c 2>/dev/null | {
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   113
      read f
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   114
      printf '(setq find-function-C-source-directory "%s")' ${f%emacs.c}
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   115
    }
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   116
  fi
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   117
}
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   118
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   119
cat >$cfg <<EOF
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   120
;; -*- mode: emacs-lisp; coding: utf-8; fill-column: 78 -*-
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
   121
;;
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
   122
;; For load order see README.
1238
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   123
EOF
579
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
   124
b71e74cfe817 Improve checker architecture.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 575
diff changeset
   125
check_platform
1238
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   126
{
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   127
  print_speller
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   128
  print_man
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   129
  print_emacs_sources_dir
c9e507cde2b7 Detect Emacs sources for 'find-function-C-source-directory'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 702
diff changeset
   130
} >>$cfg
693
0462d1dcbe75 Add '-a' option to Man-switches.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 622
diff changeset
   131