Skip to content

Commit 069508f

Browse files
jdeveraclaude
andcommitted
Bashmarks: Migrate to XDG layout with dotfiles/local split
Move bashmarks from ~/.bashmarks to ~/.config/bashmarks/ with two files: - dotfiles.bashmarks: tracked standard bookmarks - local.bashmarks: includes dotfiles + machine-specific entries Add migration scripts: - run_once_before_ moves existing ~/.bashmarks to new location - run_onchange_after_ deduplicates local entries when dotfiles change Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 43f7f92 commit 069508f

File tree

5 files changed

+120
-1
lines changed

5 files changed

+120
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
# {{ template "dotfiles_bashlib.sh" . }}
4+
5+
# Help shellcheck identify the above include
6+
true || source ../.chezmoitemplates/dotfiles_bashlib.sh
7+
8+
# This script migrates ~/.bashmarks to the new XDG-style location
9+
# It only moves the file; deduplication happens in a separate run_onchange_after_ script
10+
11+
dot::chezmoi_script_start "migrate bashmarks to XDG location"
12+
13+
OLD_FILE="$HOME/.bashmarks"
14+
NEW_DIR="$HOME/.config/bashmarks"
15+
NEW_FILE="$NEW_DIR/local.bashmarks"
16+
17+
if [[ ! -f "$OLD_FILE" ]]; then
18+
dot::chezmoi_script_skipped "no ~/.bashmarks file to migrate"
19+
fi
20+
21+
if [[ -f "$NEW_FILE" ]]; then
22+
dot::chezmoi_script_skipped "local.bashmarks already exists, migration already done"
23+
fi
24+
25+
dot::step::start "create bashmarks config directory"
26+
mkdir -p "$NEW_DIR" || dot::step::fatal
27+
dot::step::done
28+
29+
dot::step::start "move ~/.bashmarks to new location"
30+
mv "$OLD_FILE" "$NEW_FILE" || dot::step::fatal
31+
dot::step::done
32+
33+
dot::success "migrated ~/.bashmarks to $NEW_FILE"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
# dotfiles.bashmarks hash: {{ include "dot_config/bashmarks/dotfiles.bashmarks.tmpl" | sha256sum }}
4+
5+
# {{ template "dotfiles_bashlib.sh" . }}
6+
7+
# Help shellcheck identify the above include
8+
true || source ../.chezmoitemplates/dotfiles_bashlib.sh
9+
10+
# This script removes duplicate entries from local.bashmarks that already exist
11+
# in dotfiles.bashmarks. It runs whenever dotfiles.bashmarks changes.
12+
13+
dot::chezmoi_script_start "deduplicate bashmarks"
14+
15+
DOTFILES="$HOME/.config/bashmarks/dotfiles.bashmarks"
16+
LOCAL="$HOME/.config/bashmarks/local.bashmarks"
17+
18+
if [[ ! -f "$LOCAL" ]]; then
19+
dot::chezmoi_script_skipped "no local.bashmarks file"
20+
fi
21+
22+
if [[ ! -f "$DOTFILES" ]]; then
23+
dot::chezmoi_script_skipped "no dotfiles.bashmarks file"
24+
fi
25+
26+
# Build list of bookmark names from dotfiles (second field after |)
27+
dotfiles_names=$(grep -v '^#' "$DOTFILES" 2>/dev/null | grep -v '^$' | cut -d'|' -f2)
28+
29+
if [[ -z "$dotfiles_names" ]]; then
30+
dot::chezmoi_script_skipped "no bookmarks in dotfiles.bashmarks"
31+
fi
32+
33+
# Process line by line, preserving order and context
34+
dot::step::start "remove duplicates from local.bashmarks"
35+
tmpfile=$(mktemp)
36+
removed=0
37+
38+
while IFS= read -r line || [[ -n "$line" ]]; do
39+
# Keep empty lines
40+
if [[ -z "$line" ]]; then
41+
echo "$line" >> "$tmpfile"
42+
continue
43+
fi
44+
# Keep comments and #include lines
45+
if [[ "$line" == \#* ]]; then
46+
echo "$line" >> "$tmpfile"
47+
continue
48+
fi
49+
# Check if bookmark name exists in dotfiles
50+
name=$(echo "$line" | cut -d'|' -f2)
51+
if echo "$dotfiles_names" | grep -qx "$name"; then
52+
((removed++)) # Skip this line (duplicate)
53+
else
54+
echo "$line" >> "$tmpfile" # Keep unique entries
55+
fi
56+
done < "$LOCAL"
57+
58+
mv "$tmpfile" "$LOCAL"
59+
dot::step::done
60+
61+
dot::success "removed $removed duplicate entries from local.bashmarks"

home/dot_bashmarks.tmpl renamed to home/dot_config/bashmarks/dotfiles.bashmarks.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Bashmarks managed by dotfiles
2+
# Add bookmarks here that should be synced across machines
3+
14
$HOME/devel/projects|proj
25
$HOME/devel/checkout|co
36
$HOME/devel/sandbox|sb
@@ -11,4 +14,3 @@ $HOME/Library/Application Support|las
1114
{{- if eq .chezmoi.os "linux" }}
1215
$HOME/comms/downloads|dow
1316
{{- end }}
14-
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Ensure local.bashmarks includes dotfiles.bashmarks
3+
4+
INCLUDE_LINE='#include ~/.config/bashmarks/dotfiles.bashmarks'
5+
6+
# Read current contents (empty if file doesn't exist)
7+
current=$(cat)
8+
9+
# Check if include line already exists
10+
if echo "$current" | grep -qF "$INCLUDE_LINE"; then
11+
# Already has the include, output as-is
12+
echo "$current"
13+
else
14+
# Add include at the top
15+
echo "$INCLUDE_LINE"
16+
if [ -n "$current" ]; then
17+
echo "$current"
18+
fi
19+
fi
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Bashmarks configuration
2+
# Set before bashmarks.sh is sourced (200_tool_bashmarks.sh)
3+
4+
export BASHMARKS_FILE="$HOME/.config/bashmarks/local.bashmarks"

0 commit comments

Comments
 (0)