-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbookmarks-dmenu.sh
More file actions
executable file
·88 lines (74 loc) · 2.22 KB
/
Copy pathbookmarks-dmenu.sh
File metadata and controls
executable file
·88 lines (74 loc) · 2.22 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
set -eu
# Files
# Put your files in .config/bookmarks/.
PERS_FILE="${PERS_FILE:-$HOME/.config/bookmarks/personal.txt}"
WORK_FILE="${WORK_FILE:-$HOME/.config/bookmarks/work.txt}"
# dmenu look
DMENU="dmenu -i -vi -c -bw 3 -W 900 -l 30 -h 40 -F -fn 'JetBrainsMono Nerd Font:size=16' -p 'Bookmarks:'"
# Browsers
# Choose your browsers accordingly
FIREFOX="$(command -v firefox || true)"
BRAVE="$(command -v brave || command -v brave-browser || true)"
FALLBACK="$(command -v xdg-open || echo firefox)"
# Ensure files exist
mkdir -p "$(dirname "$PERS_FILE")"
[ -f "$PERS_FILE" ] || cat >"$PERS_FILE" <<'EOF'
# personal
tonybtw :: https://tonybtw.com
https://youtube.com
EOF
[ -f "$WORK_FILE" ] || cat >"$WORK_FILE" <<'EOF'
# work
[docs] NixOS Manual :: https://nixos.org/manual/
EOF
emit() {
tag="$1"; file="$2"
[ -f "$file" ] || return 0
# Output: "[tag] <display> :: <url or raw>"
# We keep the whole line after '::' as the raw RHS, or the entire line if no '::'
grep -vE '^\s*(#|$)' "$file" | while IFS= read -r line; do
case "$line" in
*"::"*)
lhs="${line%%::*}"; rhs="${line#*::}"
lhs="$(printf '%s' "$lhs" | sed 's/[[:space:]]*$//')"
rhs="$(printf '%s' "$rhs" | sed 's/^[[:space:]]*//')"
printf '[%s] %s :: %s\n' "$tag" "$lhs" "$rhs"
;;
*)
printf '[%s] %s :: %s\n' "$tag" "$line" "$line"
;;
esac
done
}
# Build combined list
choice="$({
emit personal "$PERS_FILE"
emit work "$WORK_FILE"
} | sort | eval "$DMENU" || true)"
[ -n "$choice" ] || exit 0
# Parse tag and raw URL
tag="${choice%%]*}"; tag="${tag#\[}"
raw="${choice##* :: }"
# Strip inline comments and trim
raw="$(printf '%s' "$raw" \
| sed -e 's/[[:space:]]\+#.*$//' -e 's/[[:space:]]\/\/.*$//' \
-e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
# Ensure scheme
case "$raw" in
http://*|https://*|file://*|about:*|chrome:*) url="$raw" ;;
*) url="https://$raw" ;;
esac
# Pick browser by tag
open_with() {
cmd="$1"
if [ -n "$cmd" ]; then
nohup "$cmd" --new-tab "$url" >/dev/null 2>&1 & exit 0
fi
}
case "$tag" in
personal) open_with "$FIREFOX" ;;
work) open_with "$BRAVE" ;;
esac
# Fallback if specific browser not found
nohup $FALLBACK "$url" >/dev/null 2>&1 &