From 024dc54f750e0856350c2dce37440690481a76fb Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Mon, 22 Apr 2024 12:18:32 +0200 Subject: [PATCH] Split files in directories --- .gitignore | 1 + BUILD.md | 6 ++--- CONTRIBUTING.md | 8 +++--- install.md => cheat_sheets/install.md | 0 utilization.md => cheat_sheets/utilization.md | 0 personna.md => resources/personna.md | 0 convert.sh => scripts/convert.sh | 27 ++++++++++++------- .../generate_patch.sh | 16 ++++++++--- 8 files changed, 37 insertions(+), 21 deletions(-) rename install.md => cheat_sheets/install.md (100%) rename utilization.md => cheat_sheets/utilization.md (100%) rename personna.md => resources/personna.md (100%) rename convert.sh => scripts/convert.sh (75%) rename generate_patch.sh => scripts/generate_patch.sh (82%) diff --git a/.gitignore b/.gitignore index 7856998..3bdaa71 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.synctex.gz /*.pdf /*.tex +build/ diff --git a/BUILD.md b/BUILD.md index 7ea7db9..9bf0184 100644 --- a/BUILD.md +++ b/BUILD.md @@ -49,12 +49,12 @@ docker build -t kokkos_cheat_sheet . ## Generate LaTeX files -Call the `convert.sh` script which pre-processes the input Markdown file and converts it to standalone LaTeX sources: +Call the `scripts/convert.sh` script which pre-processes the input Markdown file and converts it to standalone LaTeX sources: ```sh -./convert.sh +./scripts/convert.sh # or -docker run --rm -v $PWD:/work docker_cheat_sheet ./convert.sh +docker run --rm -v $PWD:/work docker_cheat_sheet ./scripts/convert.sh ``` Note that an additional `--user $UID:$GID` can be required to produce a file with your ownership on some systems. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bb6f9c7..c092337 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -54,14 +54,14 @@ Namely, such changes include manual page breaks, abbreviations, etc. Large modification, however, such as the removal of an entire section, are better handled by the pre-processor discussed above. A patch is associated with a converted file in the form `name.ext.diff`, and is stored under `patches//name.ext.diff` (with `` being `print` for print mode). -If a patch file exists with the same name, then the patch is automatically applied when calling `convert.sh`. +If a patch file exists with the same name, then the patch is automatically applied when calling `scripts/convert.sh`. The creation of the patch uses the following workflow: ```sh -./generate_patch.sh start +./scripts/generate_patch.sh start # edit and perform specific adjustments -./generate_patch.sh end +./scripts/generate_patch.sh end ``` -Any consecutive call to `generate_patch.sh` will cumulate the modifications. +Any consecutive call to `scripts/generate_patch.sh` will cumulate the modifications. diff --git a/install.md b/cheat_sheets/install.md similarity index 100% rename from install.md rename to cheat_sheets/install.md diff --git a/utilization.md b/cheat_sheets/utilization.md similarity index 100% rename from utilization.md rename to cheat_sheets/utilization.md diff --git a/personna.md b/resources/personna.md similarity index 100% rename from personna.md rename to resources/personna.md diff --git a/convert.sh b/scripts/convert.sh similarity index 75% rename from convert.sh rename to scripts/convert.sh index 5823dce..202d00c 100755 --- a/convert.sh +++ b/scripts/convert.sh @@ -12,6 +12,13 @@ GPP_USERMODE_CHARACTER_UNSTACK=')' GPP_USERMODE_NUMBER='#' GPP_USERMODE_QUOTE='' +# Path of the script directory +# https://stackoverflow.com/a/246128 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# Path of the project directory +PROJECT_DIR=$(dirname "$SCRIPT_DIR") + convert () { local input_file="$1" local output_file="$2" @@ -37,12 +44,12 @@ convert () { "$input_file" \ | \ pandoc \ - --defaults "configs/print.yaml" \ - --include-in-header "styles/header/print.tex" \ - --include-before-body "styles/before_body/print.tex" \ - --include-after-body "styles/after_body/print.tex" \ - --filter "filters/print.py" \ - --output "$output_file" + --defaults "$PROJECT_DIR/configs/print.yaml" \ + --include-in-header "$PROJECT_DIR/styles/header/print.tex" \ + --include-before-body "$PROJECT_DIR/styles/before_body/print.tex" \ + --include-after-body "$PROJECT_DIR/styles/after_body/print.tex" \ + --filter "$PROJECT_DIR/filters/print.py" \ + --output "$PWD/$output_file" echo "Converted to $output_file" } @@ -50,7 +57,7 @@ convert () { patch_modifs () { local output_file_diff="$1" - patchfile="patches/print/$output_file_diff" + patchfile="$PROJECT_DIR/patches/print/$output_file_diff" if [[ ! -f "$patchfile" ]] then @@ -63,7 +70,7 @@ patch_modifs () { # command returns non-0 and stores them in a specific reject file. First, # the call is marked to never fail, and second, this reject file is # discarded. - patch --quiet --forward --reject-file - <"$patchfile" || true + patch --quiet --forward --reject-file - --no-backup-if-mismatch <"$patchfile" || true echo "Applied patch from $output_file_diff" } @@ -86,12 +93,12 @@ EOF get_out_file () { local input_file="$1" - echo "${input_file%.*}.tex" + echo "$(basename ${input_file%.*}.tex)" } get_out_file_diff () { local output_file="$1" - echo "$output_file.diff" + echo "$(basename $output_file.diff)" } main () { diff --git a/generate_patch.sh b/scripts/generate_patch.sh similarity index 82% rename from generate_patch.sh rename to scripts/generate_patch.sh index 9cb6c73..0ac7511 100755 --- a/generate_patch.sh +++ b/scripts/generate_patch.sh @@ -2,7 +2,14 @@ set -eu -source convert.sh +# Path of the script directory +# https://stackoverflow.com/a/246128 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# Path of the project directory +PROJECT_DIR=$(dirname "$SCRIPT_DIR") + +source "$SCRIPT_DIR/convert.sh" get_out_file_ref () { local output_file="$1" @@ -30,16 +37,17 @@ end_patch () { if [[ ! -f "$output_file_ref" ]] then - echo "Please call \"generate_patch.sh $input_file start\" first!" + relative_path=$(realpath --relative-to "$PWD" "$SCRIPT_DIR") + echo "Please call \"$relative_path/generate_patch.sh $input_file start\" first!" return 1 fi - mkdir -p "patches/print" + mkdir -p "$PROJECT_DIR/patches/print" # generate diff # Note: If there is an actual difference between the two files, the diff # command returns non-0. Consequently, the call is marked to never fail. - diff -au "$output_file_ref" "$output_file" >"patches/print/$output_file_diff" || true + diff -au "$output_file_ref" "$output_file" >"$PROJECT_DIR/patches/print/$output_file_diff" || true # remove reference file rm --force "$output_file_ref"