-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqmd
More file actions
executable file
·55 lines (47 loc) · 1.42 KB
/
Copy pathqmd
File metadata and controls
executable file
·55 lines (47 loc) · 1.42 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
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
# qmd - Quick Markdown Search
set -euo pipefail
# Find bun - prefer PATH, fallback to known locations
find_bun() {
# First: check if bun is in PATH and modern enough
if command -v bun &>/dev/null; then
local ver=$(bun --version 2>/dev/null || echo "0")
if [[ "$ver" =~ ^1\. ]]; then
command -v bun
return 0
fi
fi
# Fallback: derive paths (need HOME)
: "${HOME:=$(eval echo ~)}"
# If running from .bun tree, use that bun
if [[ "${BASH_SOURCE[0]}" == */.bun/* ]]; then
local bun_home="${BASH_SOURCE[0]%%/.bun/*}/.bun"
if [[ -x "$bun_home/bin/bun" ]]; then
echo "$bun_home/bin/bun"
return 0
fi
fi
# Check known locations
local candidates=(
"$HOME/.local/share/mise/installs/bun/latest/bin/bun"
"$HOME/.local/share/mise/shims/bun"
"$HOME/.asdf/shims/bun"
"/opt/homebrew/bin/bun"
"/usr/local/bin/bun"
"$HOME/.bun/bin/bun"
)
for c in "${candidates[@]}"; do
[[ -x "$c" ]] && { echo "$c"; return 0; }
done
return 1
}
BUN=$(find_bun) || { echo "Error: bun not found. Install from https://bun.sh" >&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 "$BUN" "$SCRIPT_DIR/src/qmd.ts" "$@"