-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqmd
More file actions
executable file
·46 lines (39 loc) · 1.21 KB
/
Copy pathqmd
File metadata and controls
executable file
·46 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
# qmd - Quick Markdown Search
set -euo pipefail
# Find node - prefer PATH, fallback to known locations
find_node() {
if command -v node &>/dev/null; then
local ver=$(node --version 2>/dev/null | sed 's/^v//' || echo "0")
local major="${ver%%.*}"
if [[ "$major" -ge 22 ]]; then
command -v node
return 0
fi
fi
# Fallback: derive paths (need HOME)
: "${HOME:=$(eval echo ~)}"
# Check known locations
local candidates=(
"$HOME/.local/share/mise/installs/node/latest/bin/node"
"$HOME/.local/share/mise/shims/node"
"$HOME/.asdf/shims/node"
"/opt/homebrew/bin/node"
"/usr/local/bin/node"
"$HOME/.nvm/current/bin/node"
)
for c in "${candidates[@]}"; do
[[ -x "$c" ]] && { echo "$c"; return 0; }
done
return 1
}
NODE=$(find_node) || { echo "Error: node (>=22) not found. Install from https://nodejs.org" >&2; exit 1; }
# Resolve symlinks to find script location
SOURCE="${BASH_SOURCE[0]}"
while [[ -L "$SOURCE" ]]; do
DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
exec "$NODE" "$SCRIPT_DIR/dist/qmd.js" "$@"