Skip to content

Instantly share code, notes, and snippets.

@solace
Created June 27, 2024 14:56
Show Gist options
  • Save solace/a67889ad3d594cf0f31a12e10de99b32 to your computer and use it in GitHub Desktop.
Save solace/a67889ad3d594cf0f31a12e10de99b32 to your computer and use it in GitHub Desktop.
Run yarle on nested stacks of Evernote enex notebooks
#!/bin/bash
# Source: https://www.baeldung.com/linux/bash-expand-relative-path
resolve_relative_path() (
# If the path is a directory, we just need to 'cd' into it and print the new path.
if [ -d "$1" ]; then
cd "$1" || return 1
pwd
# If the path points to anything else, like a file or FIFO
elif [ -e "$1" ]; then
# Strip '/file' from '/dir/file'
# We only change the directory if the name doesn't match for the cases where
# we were passed something like 'file' without './'
if [ ! "${1%/*}" = "$1" ]; then
cd "${1%/*}" || return 1
fi
# Strip all leading slashes upto the filename
echo "$(pwd)/${1##*/}"
else
return 1 # Failure, neither file nor directory exists.
fi
)
while getopts i:o:c: option
do
case "$option" in
i) in="$OPTARG";;
o) out="$OPTARG";;
c) config="$OPTARG";;
esac
done
if [ ! -d "$out" ]; then
echo "Output directory '${out}' does not exist";
exit 1
fi
if [ ! -f "$config" ]; then
echo "Config file '${config}' does not exist";
exit 1
fi
abs_in=$(resolve_relative_path "$in")
while read -r d; do
echo "$d"
jq --arg src "$d" --arg out "${out%/}${d#$abs_in}" '.enexSources = [$src] | .outputDir = $out' "${config}" > "${config%.*}.tmp.${config##*.}"
npx -p yarle-evernote-to-md@latest yarle --configFile "${config%.*}.tmp.${config##*.}"
done < <(find "$abs_in" -type d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment