dev: automated commit - 2025-11-11 11:58:51

This commit is contained in:
Mariano Z. 2025-11-11 10:31:04 -03:00
parent 9181cfeb83
commit 7dbe7f4685
Signed by: marianozunino
GPG key ID: 4C73BAD25156DACE
3 changed files with 121 additions and 15 deletions

View file

@ -5,12 +5,21 @@ set -euo pipefail
CACHE_MAX_AGE=300
MRU_SIZE=20
# Debug logging (set DEBUG=1 to enable)
DEBUG="${DEBUG:-0}"
debug() {
[ "$DEBUG" = "1" ] && echo "[DEBUG] $*" >&2 || true
}
# Parse arguments - flags first, then DEV_DIR
NO_CACHE=false
CLEAR_CACHE=false
EDITOR="${EDITOR:-nvim}"
DEV_DIR=""
debug "Starting dev-launcher with args: $*"
for arg in "$@"; do
case "$arg" in
--help | -h)
@ -37,11 +46,16 @@ EOF
done
DEV_DIR="${DEV_DIR:-$HOME/Dev}"
debug "DEV_DIR: $DEV_DIR"
debug "NO_CACHE: $NO_CACHE"
debug "CLEAR_CACHE: $CLEAR_CACHE"
# Setup cache files (unique per dev directory)
DEV_DIR_HASH=$(echo -n "$DEV_DIR" | sha256sum | cut -d' ' -f1 | head -c 16)
CACHE_FILE="$HOME/.cache/dev-launcher-cache-${DEV_DIR_HASH}"
MRU_FILE="$HOME/.cache/dev-launcher-mru-${DEV_DIR_HASH}"
debug "CACHE_FILE: $CACHE_FILE"
debug "MRU_FILE: $MRU_FILE"
# Handle --clear-cache
if [ "$CLEAR_CACHE" = true ]; then
@ -52,17 +66,29 @@ fi
# Find git repositories
find_git_repos() {
debug "find_git_repos: checking cache..."
if [ "$NO_CACHE" = false ] && [ -f "$CACHE_FILE" ]; then
local cache_age=$(($(date +%s) - $(stat -c %Y "$CACHE_FILE" 2>/dev/null || echo 0)))
[ $cache_age -lt $CACHE_MAX_AGE ] && cat "$CACHE_FILE" && return
debug "Cache age: ${cache_age}s (max: ${CACHE_MAX_AGE}s)"
if [ $cache_age -lt $CACHE_MAX_AGE ]; then
debug "Using cached repos"
cat "$CACHE_FILE"
return
fi
debug "Cache expired, rescanning..."
fi
debug "Scanning for git repositories in $DEV_DIR..."
if command -v fd >/dev/null 2>&1; then
debug "Using fd for scanning"
fd -H -t d "^\.git$" "$DEV_DIR" -d 3 -0 | xargs -0 -n1 dirname | sort -u >"$CACHE_FILE"
else
debug "Using find for scanning"
find "$DEV_DIR" -maxdepth 3 -type d -name ".git" -print0 |
xargs -0 -n1 dirname | sort -u >"$CACHE_FILE"
fi
local repo_count=$(wc -l < "$CACHE_FILE")
debug "Found $repo_count repositories"
cat "$CACHE_FILE"
}
@ -106,18 +132,27 @@ sort_by_mru() {
# Main execution
REPOS=$(find_git_repos)
[ -z "$REPOS" ] && notify-send "Dev Launcher" "No git repositories found in $DEV_DIR" 2>/dev/null && exit 1
if [ -z "$REPOS" ]; then
debug "No repositories found!"
notify-send "Dev Launcher" "No git repositories found in $DEV_DIR" 2>/dev/null || true
exit 1
fi
debug "Found repositories, proceeding..."
# Build display list (relative paths) and mapping
DISPLAY_LIST=$(echo "$REPOS" | sed "s|^${DEV_DIR}/||")
declare -A DISPLAY_TO_PATH
debug "Building display mapping..."
while IFS=$'\t' read -r repo display; do
DISPLAY_TO_PATH["$display"]="$repo"
done < <(paste <(echo "$REPOS") <(echo "$DISPLAY_LIST"))
debug "Mapped ${#DISPLAY_TO_PATH[@]} projects"
# Sort by MRU and present in tofi
debug "Sorting by MRU..."
SORTED_LIST=$(sort_by_mru "$DISPLAY_LIST")
debug "Presenting in tofi..."
SELECTED_DISPLAY=$(echo "$SORTED_LIST" | tofi \
--prompt-text "💀 Poison: " \
--fuzzy-match true \
@ -139,21 +174,31 @@ SELECTED_DISPLAY=$(echo "$SORTED_LIST" | tofi \
--border-color '#31748f' \
--prompt-color '#f6c177')
[ -z "$SELECTED_DISPLAY" ] && exit 0
debug "Selected display: '$SELECTED_DISPLAY'"
[ -z "$SELECTED_DISPLAY" ] && debug "No selection, exiting" && exit 0
# Remove star indicator and lookup path
SELECTED_DISPLAY_CLEAN=$(echo "$SELECTED_DISPLAY" | sed 's/^⭐ //')
SELECTED="${DISPLAY_TO_PATH[$SELECTED_DISPLAY_CLEAN]:-}"
[ -z "$SELECTED" ] || [ ! -d "$SELECTED" ] && exit 0
debug "Selected display (clean): '$SELECTED_DISPLAY_CLEAN'"
debug "Selected path: '$SELECTED'"
[ -z "$SELECTED" ] || [ ! -d "$SELECTED" ] && debug "Invalid selection, exiting" && exit 0
# Update MRU and launch
debug "Updating MRU..."
update_mru "$SELECTED_DISPLAY_CLEAN"
PROJECT_NAME=$(get_project_name "$SELECTED")
SESSION_NAME="dev-${PROJECT_NAME}"
CLASS_NAME="com.mzunino.dev.${PROJECT_NAME}"
debug "Project name: $PROJECT_NAME"
debug "Session name: $SESSION_NAME"
debug "Class name: $CLASS_NAME"
debug "Launching ghostty with launch-or-focus..."
launch-or-focus ghostty \
--working-directory="$SELECTED" \
--title="$PROJECT_NAME" \