dotfiles/packages/quick-zeal/quick-zeal
Christopher Mühl f49a9c8019
refactor: use active-window utility in scripts
Migrates quick-zeal and spawn-term from compositor-specific APIs
(hyprctl, kdotool, niri msg) to the unified active-window utility.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 01:25:46 +01:00

64 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Define a function to extract the major version and normalize version strings
extract_major_version() {
echo "$1" | grep -oP "\d+" | head -1
}
# Detects the focused window and checks if it's Kitty
WINDOW=$(active-window)
ACTIVE_WINDOW=$(printf '%s' "$WINDOW" | jq -r '.class // empty')
PID=$(printf '%s' "$WINDOW" | jq -r '.pid // empty')
# Check if the focused window is a Kitty terminal and if it's in a Git repository.
# If so, determine the project type and open Zeal with the appropriate argument
zeal_argument=""
if [[ $ACTIVE_WINDOW == "kitty" ]]; then
CHILD_PID=$(pgrep -P "$PID" | tail -1)
SHELL_CWD=$(readlink -f "/proc/${CHILD_PID}/cwd")
echo "Current path: $SHELL_CWD"
cd "$SHELL_CWD" || exit
echo "Kitty terminal is focused."
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo " - This is a Git repository."
if [[ -f "Gemfile" ]]; then
echo " - Detected a Ruby project."
# Check for ActiveSupport or Rails
if grep -q "activesupport\|rails" Gemfile.lock; then
framework_version=$(grep -oP "(activesupport|rails) \(\K=[^)]+" Gemfile.lock | head -1 | tr -d ' =' | cut -d '.' -f1)
echo " - Framework major version: $framework_version"
zeal_argument="ror$framework_version,"
fi
ruby_version=$(ruby -v | grep -oP "\d+\.\d+\.\d+" | cut -d '.' -f1)
echo " - Ruby major version: $ruby_version"
zeal_argument+="ruby$ruby_version:"
elif [[ -f "Cargo.toml" ]]; then
echo " - Detected a Rust project."
zeal_argument="rust:"
elif [[ -f "package.json" ]]; then
if grep -q '"typescript":' package.json; then
echo " - Detected a TypeScript project."
zeal_argument="typescript:"
else
echo " - Detected a JavaScript or Node project."
zeal_argument="javascript:"
fi
else
echo " - Project type could not be determined."
fi
else
echo " - Not a Git repository."
fi
fi
# Launch Zeal with or without arguments based on detection
(&>/dev/null zeal "$zeal_argument" &)