/ .dev / move-dot-ignores.sh
move-dot-ignores.sh
 1  #!/usr/bin/env bash
 2  set -euo pipefail
 3  
 4  # Determine repo root (parent of this script's directory)
 5  SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
 6  REPO_ROOT="${SCRIPT_DIR%/.dev}"
 7  DEV_DIR="$SCRIPT_DIR"
 8  
 9  cd "$REPO_ROOT"
10  
11  shopt -s nullglob dotglob
12  
13  ensure_dev_dir() {
14    mkdir -p "$DEV_DIR"
15  }
16  
17  move_one_file() {
18    local f="$1"
19    local base="$(basename -- "$f")"
20    # Skip .gitignore as requested
21    if [[ "$base" == ".gitignore" ]]; then
22      return 0
23    fi
24    local dst="$DEV_DIR/$base"
25  
26    # If already a symlink at root that points into .dev, skip move
27    if [[ -L "$f" ]]; then
28      return 0
29    fi
30  
31    # If the destination exists and contents are identical, remove source
32    if [[ -e "$dst" && -f "$dst" && -f "$f" ]]; then
33      if cmp -s "$f" "$dst"; then
34        rm -f -- "$f"
35        return 0
36      else
37        echo "[WARN] Destination exists and differs: $dst (leaving $f in place)" >&2
38        return 0
39      fi
40    fi
41  
42    # Move the file into .dev
43    mv -n -- "$f" "$dst"
44    echo "Moved $f -> $dst"
45  }
46  
47  move_one_dir() {
48    local d="$1"
49    local base="$(basename -- "$d")"
50    local dst="$DEV_DIR/$base"
51  
52    # If already a symlink at root, skip move
53    if [[ -L "$d" ]]; then
54      return 0
55    fi
56  
57    # If destination exists, warn and skip to avoid destructive overwrite
58    if [[ -e "$dst" ]]; then
59      echo "[WARN] Destination dir exists: $dst (skipping move of $d)" >&2
60      return 0
61    fi
62  
63    mv -n -- "$d" "$dst"
64    echo "Moved $d -> $dst"
65  }
66  
67  main() {
68    ensure_dev_dir
69    # Find top-level .*ignore files
70    for f in ./*ignore; do
71      [[ -e "$f" ]] || continue
72      move_one_file "$f"
73    done
74  
75    # Also consider dot files explicitly (like .ignore without extra chars)
76    for f in ./.ignore ./.cursorignore ./.continueignore ./.dockerignore ./.supermavenignore; do
77      [[ -e "$f" ]] || continue
78      move_one_file "$f"
79    done
80  
81    # Move dev directories (.cursor, .windsurf, .kilo, .kiro, .kilocode, .agent) into .dev
82    for d in ./.cursor ./.windsurf ./.kilo ./.kiro ./.kilocode ./.agent; do
83      [[ -e "$d" ]] || continue
84      move_one_dir "$d"
85    done
86  
87    # Move mcp.json and pyrightconfig.json into .dev if present
88    for f in ./mcp.json ./pyrightconfig.json; do
89      [[ -e "$f" ]] || continue
90      move_one_file "$f"
91    done
92  
93    # Recreate symlinks
94    "$DEV_DIR/link-dot-ignores.sh"
95  }
96  
97  main "$@"