mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 22:47:02 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
162 lines
4.7 KiB
Bash
Executable File
162 lines
4.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Cross-language lookup and content extraction.
|
|
#
|
|
# Sourced by lookup_docs.sh; split out to keep it under the 250-line
|
|
# cap. Sourced rather than run, so it inherits the caller's strict mode
|
|
# and the variables defined above the source line.
|
|
|
|
#==============================================================================
|
|
# Generic lookup (searches all languages)
|
|
#==============================================================================
|
|
lookup_all() {
|
|
local term="$1"
|
|
|
|
# Try each language
|
|
for lang in python cpp js rust go shell; do
|
|
local result
|
|
result=$(lookup_$lang "$term" 2>/dev/null)
|
|
if [ -n "$result" ]; then
|
|
echo "$lang: $result"
|
|
fi
|
|
done
|
|
}
|
|
|
|
#==============================================================================
|
|
# Parse Python import and lookup the actual imported item
|
|
#==============================================================================
|
|
parse_python_import() {
|
|
local import_line="$1"
|
|
|
|
# Handle "from X import Y" format
|
|
if [[ $import_line =~ ^from[[:space:]]+([^[:space:]]+)[[:space:]]+import[[:space:]]+(.+) ]]; then
|
|
local module="${BASH_REMATCH[1]}"
|
|
local items="${BASH_REMATCH[2]}"
|
|
|
|
# Clean up items (remove parentheses, commas, etc.)
|
|
items=$(echo "$items" | sed 's/[(),]//g' | awk '{print $1}')
|
|
|
|
# Output: module and first imported item
|
|
echo "$module|$items"
|
|
return 0
|
|
fi
|
|
|
|
# Handle "import X" format
|
|
if [[ $import_line =~ ^import[[:space:]]+([^[:space:],]+) ]]; then
|
|
local module="${BASH_REMATCH[1]}"
|
|
echo "$module|"
|
|
return 0
|
|
fi
|
|
|
|
return 1
|
|
}
|
|
|
|
#==============================================================================
|
|
# Smart lookup for imports
|
|
#==============================================================================
|
|
lookup_import() {
|
|
local import_line="$1"
|
|
local lang="$2"
|
|
|
|
case "$lang" in
|
|
python)
|
|
local parsed
|
|
parsed=$(parse_python_import "$import_line")
|
|
if [ -n "$parsed" ]; then
|
|
local module item
|
|
module=$(echo "$parsed" | cut -d'|' -f1)
|
|
item=$(echo "$parsed" | cut -d'|' -f2)
|
|
|
|
# For "from X import Y", look up Y within module X's documentation
|
|
if [ -n "$item" ] && [ -n "$module" ]; then
|
|
local result
|
|
# Pass both item and module to lookup_python
|
|
result=$(lookup_python "$item" "$module")
|
|
if [ -n "$result" ]; then
|
|
echo "$result"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
# Fall back to module documentation
|
|
lookup_python "$module"
|
|
fi
|
|
;;
|
|
|
|
c_cpp)
|
|
# Extract header name from #include <header> or #include "header"
|
|
local header
|
|
header=$(echo "$import_line" | sed -E 's/#include\s*[<"]([^">]+)[">]/\1/' | sed 's/\.h$//')
|
|
lookup_cpp "$header"
|
|
;;
|
|
|
|
javascript | typescript)
|
|
# Extract module from import/require
|
|
local module=""
|
|
# Match: from "module" or from 'module'
|
|
module=$(echo "$import_line" | grep -oP "from\s+['\"]\\K[^'\"]+")
|
|
if [ -z "$module" ]; then
|
|
# Match: require("module") or require('module')
|
|
module=$(echo "$import_line" | grep -oP "require\\(['\"]\\K[^'\"]+")
|
|
fi
|
|
[ -n "$module" ] && lookup_js "$module"
|
|
;;
|
|
|
|
*)
|
|
echo "Unknown language: $lang"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
#==============================================================================
|
|
# Extract documentation content
|
|
#==============================================================================
|
|
extract_doc_content() {
|
|
local file="$1"
|
|
local term="$2"
|
|
local max_lines="${3:-20}"
|
|
|
|
if [[ $file == *.html ]]; then
|
|
# Extract text from HTML, find section about term
|
|
if command -v html2text &>/dev/null; then
|
|
html2text "$file" 2>/dev/null | grep -A"$max_lines" -i "$term" | head -"$max_lines"
|
|
elif command -v lynx &>/dev/null; then
|
|
lynx -dump -nolist "$file" 2>/dev/null | grep -A"$max_lines" -i "$term" | head -"$max_lines"
|
|
else
|
|
# Basic extraction
|
|
sed 's/<[^>]*>//g' "$file" | grep -A"$max_lines" -i "$term" | head -"$max_lines"
|
|
fi
|
|
elif [[ $file == *.json ]]; then
|
|
# Pretty print JSON section
|
|
grep -A5 "\"$term\"" "$file" 2>/dev/null
|
|
else
|
|
# Plain text
|
|
grep -A"$max_lines" -i "$term" "$file" | head -"$max_lines"
|
|
fi
|
|
}
|
|
|
|
#==============================================================================
|
|
# Main
|
|
#==============================================================================
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $0 <term> [language] [options]
|
|
|
|
Search offline documentation for a term.
|
|
|
|
Languages: python, cpp, c_cpp, js, javascript, rust, go, shell, all
|
|
|
|
Options:
|
|
--open Open the documentation file (requires xdg-open)
|
|
--extract Extract and display relevant content
|
|
--import Parse and lookup an import statement
|
|
--batch Process multiple terms from a file
|
|
|
|
Examples:
|
|
$0 Path python # Find Path in Python docs
|
|
$0 vector cpp # Find vector in C++ docs
|
|
$0 map # Find map in all languages
|
|
$0 --import "from pathlib import Path" python
|
|
$0 --batch imports.txt python
|
|
EOF
|
|
}
|