diff --git a/bookmarks-dmenu.sh b/bookmarks-dmenu.sh new file mode 100755 index 0000000..116032c --- /dev/null +++ b/bookmarks-dmenu.sh @@ -0,0 +1,86 @@ +#!/bin/sh +set -eu + +# Files +PERS_FILE="${PERS_FILE:-$HOME/.config/bookmarks/personal.txt}" +WORK_FILE="${WORK_FILE:-$HOME/.config/bookmarks/work.txt}" + +# dmenu look +DMENU="dmenu -i -c -bw 3 -W 900 -l 30 -h 40 -F -fn 'JetBrainsMono Nerd Font:size=16' -p 'Bookmarks:'" + +# Browsers +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] :: " + # 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 & + diff --git a/repos-dmenu.sh b/repos-dmenu.sh index 1624bf1..ebe02a6 100755 --- a/repos-dmenu.sh +++ b/repos-dmenu.sh @@ -1,44 +1,18 @@ #!/bin/sh set -eu -# Grab only directories inside ~/debian-dotfiles -configs="$(ls -1d ~/tonybtw/repos/*/ 2>/dev/null | xargs -n1 basename)" +# Pick repo +configs="$(ls -1d "$HOME"/repos/*/ 2>/dev/null | xargs -n1 basename)" [ -n "$configs" ] || exit 0 - -chosen="$(printf '%s\n' $configs | dmenu -i -c -vi -bw 3 -W 600 -l 30 -h 40 -F -fn "JetBrainsMono Nerd Font:size=16" -p 'repos:')" +chosen="$(printf '%s\n' $configs | dmenu -i -c -bw 3 -W 600 -l 30 -h 40 -F -fn 'JetBrainsMono Nerd Font:size=16' -p 'Projects:')" [ -n "$chosen" ] || exit 0 +dir="$HOME/repos/$chosen" -dir="$HOME/tonybtw/repos/$chosen" - -# If inside tmux: switch or create -if [ "${TMUX-}" ]; then - if tmux has-session -t "$chosen" 2>/dev/null; then - exec tmux switch-client -t "$chosen" - else - exec tmux new-session -s "$chosen" -c "$dir" "nvim ." - fi -fi - -# If there's an st client running tmux, switch that instead of opening a new one -client_tty="$( - tmux list-clients -F '#{client_tty} #{client_termname}' 2>/dev/null \ - | awk '$2 ~ /^st/ { print $1; exit }' || true -)" - -if [ -n "${client_tty}" ]; then - if tmux has-session -t "$chosen" 2>/dev/null; then - tmux switch-client -c "${client_tty}" -t "$chosen" - else - tmux new-session -s "$chosen" -c "$dir" "nvim ." - fi - exit 0 -fi - -# Otherwise, spawn a new st terminal -if tmux has-session -t "$chosen" 2>/dev/null; then - exec st -e tmux attach -t "$chosen" -else - exec st -e tmux new-session -s "$chosen" -c "$dir" "nvim ." -fi +# Nuke any existing st (since you only use one terminal) +pkill -x st 2>/dev/null || true +sleep 0.1 +# Launch a clean terminal: attach if exists, else create +# exec st -e tmux new-session -As "$chosen" -c "$dir" "nvim ." +exec st -e tmux new-session -As "$chosen" -c "$dir"