From 7c3c76bd6ead7bee4953bf279c88114c2ff00c54 Mon Sep 17 00:00:00 2001 From: Maxim Likhachev Date: Sun, 16 Feb 2020 15:20:56 +0300 Subject: [PATCH] Generate README with Linux and MacOS applications --- scripts/doc.sh | 103 +++++++++++++++++++++++++++++++++----------------------- scripts/doc.tpl | 51 ++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 42 deletions(-) create mode 100644 scripts/doc.tpl diff --git a/scripts/doc.sh b/scripts/doc.sh index 02f2ad1..79b1a0a 100755 --- a/scripts/doc.sh +++ b/scripts/doc.sh @@ -1,6 +1,24 @@ #!/bin/bash -MACOS_FILE=roles/macos/vars/main.yml +CWD=$(dirname "$0") + +source "$CWD/doc.tpl" + +MACOS_FILE=$CWD/../roles/macos/vars/main.yml +LINUX_FILE=$CWD/../roles/linux-gentoo/vars/applications.yml + +APP_ALIASES=$(cat <<-EOF + haskell-stack:stack-bin + ghostscript:ghostscript-gpl + ntfs-3g:ntfs3g + firefox:firefox-bin + shellcheck:shellcheck-bin + EOF +) + +get_alias() { + grep -E ":?${1}:?" <<<"${APP_ALIASES[*]}" | sed -E "s/:?${1}:?//" +} description() { application=$1 @@ -17,64 +35,65 @@ description() { printf -- "- %s[%s](%s) - %s%s\n" "$marks" "$app_name" "$app_page" "$app_dscr" "$marks" } -MACOS_APPS=$(grep -E '^\s*(#\s)?-\s+[^:]+\s+#\s*http.+$' "$MACOS_FILE" \ +get_apps() { + grep -E '^\s*(#\s)?-\s+[^:]+\s+#\s*http.+$' "$1" \ | expand \ | sort \ | sed -E 's/[[:space:]]+/ /g; s/^[[:space:]]*//' -) - -apps_macos="" - -while read -r app; do - disabled= - if [ "${app:0:1}" == '#' ]; then - app=$(cut -d ' ' -f 2- <<<"$app") - disabled=1 - fi - - apps_macos+=$(description "$app" "$disabled") - apps_macos+='\n' -done <<<"$MACOS_APPS" - -# ------------------------------------------------------------------------------ - -echo -e "\ -# OS Configuration +} -Ansible roles for configuring Linux and MacOS environments. +get_app_names() { + grep -E -o -- "^-[[:space:]]+[^[:space:]]+[[:space:]]" <<<"${1}" | cut -d ' ' -f 2- +} -## License +drop() { + eval "${2}=\$(grep -v -E \"^- ${1}\s+.*$\" <<<\"\$${2}\")" +} -[GNU General Public License v3.](https://www.gnu.org/licenses/gpl-3.0.html) +to_md() { + md="" -## Usage + while read -r app; do + disabled= + if [ "${app:0:1}" == '#' ]; then + app=$(cut -d ' ' -f 2- <<<"$app") + disabled=1 + fi -\`\`\` -# Create README.md: -$ make doc + md="${md}$(description "$app" "$disabled")\n" + done <<<"$1" -# Configure local OS: -$ make -\`\`\` + echo -e "$md" +} ----- +MACOS_APPS=$(get_apps "$MACOS_FILE") +LINUX_APPS=$(get_apps "$LINUX_FILE" | sed -E 's!- [^/]+/!- !') -## Configuration files and scripts +LINUX_APPS_NAMES=($(get_app_names "$LINUX_APPS")) +MACOS_APPS_NAMES=($(get_app_names "$MACOS_APPS")) -- [shellrc](https://code.envrm.info/src/shellrc) - Configuration files for shells (bash, tclsh, etc), X, WM and applications. -- [scripts-linux](https://code.envrm.info/src/scripts-linux) - Various cli scripts. +COMMON_APPS="" +for app in "${MACOS_APPS_NAMES[@]}"; do + alias="$(get_alias $app)" + alias="${alias:-NO_ALIAS}" ----- + if [[ "${LINUX_APPS_NAMES[*]}" =~ $app ]] || [[ "${LINUX_APPS_NAMES[*]}" =~ $alias ]]; then + COMMON_APPS="${COMMON_APPS}$(grep -E -- "^-\s+${app}\s+" <<<"$MACOS_APPS")\n" -## MacOS + [[ "${LINUX_APPS_NAMES[*]}" =~ $alias ]] && drop "$alias" LINUX_APPS -### Applications + drop "$app" MACOS_APPS + drop "$app" LINUX_APPS + fi +done -$apps_macos +COMMON_APPS=$(echo -e "$COMMON_APPS") -### Other +apps_common=$(to_md "$COMMON_APPS") +apps_macos=$(to_md "$MACOS_APPS") +apps_linux=$(to_md "$LINUX_APPS") -- [Keyman](https://keyman.com/mac/download) - Input method and screen keyboard for more than 1000 languages. +# ------------------------------------------------------------------------------ -" +doc diff --git a/scripts/doc.tpl b/scripts/doc.tpl new file mode 100644 index 0000000..4601bdc --- /dev/null +++ b/scripts/doc.tpl @@ -0,0 +1,51 @@ +doc() { +cat <<-EOF + # OS Configuration + + Ansible roles for configuring Linux and MacOS environments. + + ## License + + [GNU General Public License v3.](https://www.gnu.org/licenses/gpl-3.0.html) + + ## Usage + + \`\`\` + # Create README.md: + $ make doc + + # Configure local OS: + $ make + \`\`\` + + ---- + + ## Configuration files and scripts + + - [shellrc](https://code.envrm.info/src/shellrc) - Configuration files for shells (bash, tclsh, etc), X, WM and applications. + - [scripts-linux](https://code.envrm.info/src/scripts-linux) - Various cli scripts. + + ---- + + ## Common Applications + + $apps_common + + ## Linux + + ### Applications + + $apps_linux + + ## MacOS + + ### Applications + + $apps_macos + + ### Other + + - [Keyman](https://keyman.com/mac/download) - Input method and screen keyboard for more than 1000 languages. + +EOF +}