analyze-code.sh

Created about 13 hours ago

attributes
source_urlhttps://github.com/mohi-devhub/antivibe/blob/9991d12ec52bc0b90eeab893fef27398be1ef616/scripts/analyze-code.sh
#!/bin/bash
# analyze-code.sh - Parse code structure and identify patterns
# Usage: ./analyze-code.sh [file-path]

FILE_PATH="$1"

if [ -z "$FILE_PATH" ]; then
    echo "Usage: ./analyze-code.sh <file-path>"
    exit 1
fi

if [ ! -f "$FILE_PATH" ]; then
    echo "File not found: $FILE_PATH"
    exit 1
fi

echo "=== Analyzing: $FILE_PATH ==="
echo ""

# Get file extension
EXTENSION="${FILE_PATH##*.}"

echo "--- File Info ---"
echo "Extension: $EXTENSION"
echo "Lines: $(wc -l < "$FILE_PATH")"
echo ""

# Basic structure analysis based on language
case "$EXTENSION" in
    ts|js)
        echo "--- JavaScript/TypeScript Structure ---"
        echo "Functions:"
        grep -E "^(export )?(function|const|class|interface|type) " "$FILE_PATH" 2>/dev/null | head -20
        echo ""
        echo "Imports:"
        grep -E "^import " "$FILE_PATH" 2>/dev/null | head -10
        echo ""
        echo "Exports:"
        grep -E "^export " "$FILE_PATH" 2>/dev/null | head -10
        ;;
    py)
        echo "--- Python Structure ---"
        echo "Classes:"
        grep -E "^class " "$FILE_PATH" 2>/dev/null | head -20
        echo ""
        echo "Functions:"
        grep -E "^def " "$FILE_PATH" 2>/dev/null | head -20
        echo ""
        echo "Imports:"
        grep -E "^import |^from " "$FILE_PATH" 2>/dev/null | head -10
        ;;
    go)
        echo "--- Go Structure ---"
        echo "Functions:"
        grep -E "^func " "$FILE_PATH" 2>/dev/null | head -20
        echo ""
        echo "Structs:"
        grep -E "^type .* struct " "$FILE_PATH" 2>/dev/null | head -10
        echo ""
        echo "Interfaces:"
        grep -E "^type .* interface " "$FILE_PATH" 2>/dev/null | head -10
        ;;
    rs)
        echo "--- Rust Structure ---"
        echo "Functions:"
        grep -E "^fn " "$FILE_PATH" 2>/dev/null | head -20
        echo ""
        echo "Structs:"
        grep -E "^struct " "$FILE_PATH" 2>/dev/null | head -10
        echo ""
        echo "Traits:"
        grep -E "^trait " "$FILE_PATH" 2>/dev/null | head -10
        ;;
    java)
        echo "--- Java Structure ---"
        echo "Classes:"
        grep -E "^public (class|interface|enum) " "$FILE_PATH" 2>/dev/null | head -20
        echo ""
        echo "Methods:"
        grep -E " (public|private|protected) .*\(.*\) " "$FILE_PATH" 2>/dev/null | head -20
        ;;
    *)
        echo "--- Generic Analysis ---"
        echo "First 30 lines (overview):"
        head -30 "$FILE_PATH"
        ;;
esac

echo ""
echo "=== Analysis Complete ==="

Copyright (c) 2026 M Mohith License files are attached. MIT

MIT notice

MIT License

Copyright (c) 2026 M Mohith

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Children

No children yet.

Like how this is organised?

Build your own Memory tree on knowen.md: notes, decisions and tasks in one connected markdown graph, shared with your team and your AI agents.