138 lines
3.7 KiB
Bash
Executable File
138 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
if [[ -a ".env" ]]; then
|
|
export $(cat .env | sed 's/^#.*//g' | xargs)
|
|
fi
|
|
|
|
function help() {
|
|
echo
|
|
echo "task <command> [options]"
|
|
echo
|
|
echo "commands:"
|
|
echo
|
|
|
|
CMD_WIDTH=20
|
|
OPT_WIDTH=6
|
|
DESC_WIDTH=45
|
|
COLUMN="| %-${CMD_WIDTH}s | %-${OPT_WIDTH}s | %-${DESC_WIDTH}s |\n"
|
|
|
|
printf "$COLUMN" "Command" "Option" "Description"
|
|
echo "|$(printf '%*s' $((CMD_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((OPT_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((DESC_WIDTH + 2)) '' | tr ' ' '-')|"
|
|
printf "$COLUMN" "install" "" "Install build dependencies."
|
|
printf "$COLUMN" "update" "" "Update build dependencies."
|
|
printf "$COLUMN" "dev-vuepress" "" "Start vuepress development server."
|
|
printf "$COLUMN" "build-vuepress" "" "Create vuepress build."
|
|
printf "$COLUMN" "serve-vuepress" "" "Serve vuepress build."
|
|
printf "$COLUMN" "convert-files" "" "Convert markdown wiki links to normal link."
|
|
printf "$COLUMN" "convert-canvas" "" "Convert canvas files to svg."
|
|
printf "$COLUMN" "generate-bases-view" "" "Generate markdown tables from bases."
|
|
printf "$COLUMN" "review-notes" "" "Open a random note reviewed note."
|
|
printf "$COLUMN" "lint" "" "Lint code with prettier."
|
|
}
|
|
|
|
if [ -d "$HOME/taskfile.build/bin" ]; then
|
|
for file in "$HOME/taskfile.build/bin/"*; do
|
|
if [ -f "$file" ]; then
|
|
source "$file"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
function review-notes() {
|
|
VAULT_PATH="$(pwd)"
|
|
REVIEW_LOG="$VAULT_PATH/review-note.csv"
|
|
|
|
if [[ ! -f "$REVIEW_LOG" ]]; then
|
|
echo "Init review log."
|
|
echo "note_name,timestamp" > "$REVIEW_LOG"
|
|
fi
|
|
|
|
echo "Get reviewed files."
|
|
REVIEWED_FILES=$(cut -d',' -f1 "$REVIEW_LOG" | tail -n +2)
|
|
|
|
echo "Find all markdown files."
|
|
MD_FILES=$(find . -type f -name "*.md" | grep -vFf <(git check-ignore -v $(find . -type d) | awk '{print $2}'))
|
|
|
|
echo "Filter unreviewed files."
|
|
UNREVIEWED_FILES=$(echo "$MD_FILES")
|
|
|
|
if [[ -z "$UNREVIEWED_FILES" ]]; then
|
|
echo "No new files to review!"
|
|
return
|
|
fi
|
|
|
|
echo "Pick a random file."
|
|
SELECTED_FILE=$(echo "$UNREVIEWED_FILES" | shuf -n 1)
|
|
|
|
NOTE_NAME=$(basename "$SELECTED_FILE" .md)
|
|
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
|
|
|
ENCODED_FILE=$(echo -n "$NOTE_NAME" | jq -sRr @uri)
|
|
echo "Encode '$NOTE_NAME' to '$ENCODED_FILE'"
|
|
echo "Opening obsidian://open?vault=$(basename "$PWD")&file=$ENCODED_FILE"
|
|
obsidian "obsidian://open?vault=$(basename "$PWD")&file=$ENCODED_FILE" &
|
|
|
|
echo "Log the review."
|
|
echo "\"$NOTE_NAME\",\"$TIMESTAMP\"" >> "$REVIEW_LOG"
|
|
}
|
|
|
|
function install() {
|
|
pnpm install
|
|
}
|
|
|
|
function update() {
|
|
pnpm install -D @vuepress/bundler-vite@next
|
|
pnpm install -D @vuepress/client@next
|
|
pnpm install -D @vuepress/plugin-docsearch@next
|
|
pnpm install -D @vuepress/plugin-search@next
|
|
pnpm install -D @vuepress/plugin-shiki@next
|
|
pnpm install -D @vuepress/theme-default@next
|
|
pnpm install -D @vuepress/utils@next
|
|
pnpm install -D vuepress@next
|
|
}
|
|
|
|
function dev-vuepress() {
|
|
pnpm run pre-build
|
|
open-url-with-delay 'http://localhost:8081/' & pnpm run dev
|
|
}
|
|
|
|
function build-vuepress() {
|
|
pnpm run build
|
|
}
|
|
|
|
function serve-vuepress() {
|
|
cd ./src/.vuepress/dist
|
|
pnpx serve
|
|
}
|
|
|
|
function generate-bases-view() {
|
|
node generate-bases-view.js
|
|
}
|
|
|
|
function convert-files() {
|
|
node build.js vuepress
|
|
node build.js convert
|
|
node build.js attachments
|
|
}
|
|
|
|
function convert-canvas() {
|
|
node build.js canvas
|
|
}
|
|
|
|
function lint() {
|
|
pnpm exec prettier . --write
|
|
}
|
|
|
|
if declare -f "$1" > /dev/null; then
|
|
"$1" "${@:2}"
|
|
else
|
|
case "$1" in
|
|
*)
|
|
echo "Unknown command: $1"
|
|
help task
|
|
exit 1
|
|
;;
|
|
esac
|
|
fi
|