mirror of
https://github.com/kuhyx/scripts.git
synced 2026-07-04 14:23:08 +02:00
fix: format shell scripts with shfmt (convert tabs to 2 spaces)
Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>
This commit is contained in:
parent
64b3116a5c
commit
2888c0b53d
@ -15,7 +15,7 @@ show_error() {
|
||||
}
|
||||
|
||||
# Validate and load config file
|
||||
if [[ ! -f "$SHUTDOWN_CONFIG" ]]; then
|
||||
if [[ ! -f $SHUTDOWN_CONFIG ]]; then
|
||||
show_error "NO CONFIG"
|
||||
fi
|
||||
|
||||
@ -26,12 +26,12 @@ if ! source "$SHUTDOWN_CONFIG" 2>/dev/null; then
|
||||
fi
|
||||
|
||||
# Validate that required variables are set
|
||||
if [[ -z "${MON_WED_HOUR:-}" ]] || [[ -z "${THU_SUN_HOUR:-}" ]]; then
|
||||
if [[ -z ${MON_WED_HOUR:-} ]] || [[ -z ${THU_SUN_HOUR:-} ]]; then
|
||||
show_error "MISSING VARS"
|
||||
fi
|
||||
|
||||
# Validate that values are numbers
|
||||
if ! [[ "$MON_WED_HOUR" =~ ^[0-9]+$ ]] || ! [[ "$THU_SUN_HOUR" =~ ^[0-9]+$ ]]; then
|
||||
if ! [[ $MON_WED_HOUR =~ ^[0-9]+$ ]] || ! [[ $THU_SUN_HOUR =~ ^[0-9]+$ ]]; then
|
||||
show_error "INVALID HOURS"
|
||||
fi
|
||||
|
||||
|
||||
@ -299,7 +299,7 @@ HOOK_EOF
|
||||
# Uninstall pacman hook
|
||||
uninstall_pacman_hook() {
|
||||
local hook_file="/etc/pacman.d/hooks/95-compulsive-block-rewrap.hook"
|
||||
if [[ -f "$hook_file" ]]; then
|
||||
if [[ -f $hook_file ]]; then
|
||||
rm -f "$hook_file"
|
||||
echo "✓ Pacman hook removed"
|
||||
fi
|
||||
@ -313,7 +313,7 @@ rewrap_quiet() {
|
||||
local wrapper_path="${APPS[$app]}"
|
||||
|
||||
# Check if wrapper was overwritten (no longer our wrapper script)
|
||||
if [[ -f "$wrapper_path" ]] && ! grep -q "block-compulsive-opening" "$wrapper_path" 2>/dev/null; then
|
||||
if [[ -f $wrapper_path ]] && ! grep -q "block-compulsive-opening" "$wrapper_path" 2> /dev/null; then
|
||||
# Wrapper was overwritten by package update
|
||||
log_message "REWRAP: $app wrapper was overwritten, re-installing"
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ CANONICAL_CONFIG="/usr/local/share/locked-shutdown-schedule.conf"
|
||||
# Check if trying to make schedule more lenient (later shutdown / earlier morning end)
|
||||
check_schedule_protection() {
|
||||
# Skip check if no canonical config exists (first install)
|
||||
if [[ ! -f "$CANONICAL_CONFIG" ]]; then
|
||||
if [[ ! -f $CANONICAL_CONFIG ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
@ -45,7 +45,7 @@ check_schedule_protection() {
|
||||
canonical_morning_end="${MORNING_END_HOUR:-}"
|
||||
|
||||
# If canonical values are empty, skip check
|
||||
if [[ -z "$canonical_mon_wed" ]] || [[ -z "$canonical_thu_sun" ]] || [[ -z "$canonical_morning_end" ]]; then
|
||||
if [[ -z $canonical_mon_wed ]] || [[ -z $canonical_thu_sun ]] || [[ -z $canonical_morning_end ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
@ -228,7 +228,7 @@ show_current_status() {
|
||||
local config_file="/etc/shutdown-schedule.conf"
|
||||
local canonical_file="/usr/local/share/locked-shutdown-schedule.conf"
|
||||
|
||||
if [[ -f "$config_file" ]]; then
|
||||
if [[ -f $config_file ]]; then
|
||||
echo "✓ Config file exists"
|
||||
# Check immutable attribute
|
||||
if lsattr "$config_file" 2> /dev/null | grep -q '^....i'; then
|
||||
@ -240,7 +240,7 @@ show_current_status() {
|
||||
echo "✗ Config file missing"
|
||||
fi
|
||||
|
||||
if [[ -f "$canonical_file" ]]; then
|
||||
if [[ -f $canonical_file ]]; then
|
||||
echo "✓ Canonical copy exists"
|
||||
else
|
||||
echo "✗ Canonical copy missing"
|
||||
@ -1162,7 +1162,7 @@ test_setup() {
|
||||
local config_file="/etc/shutdown-schedule.conf"
|
||||
local canonical_file="/usr/local/share/locked-shutdown-schedule.conf"
|
||||
|
||||
if [[ -f "$config_file" ]]; then
|
||||
if [[ -f $config_file ]]; then
|
||||
echo "✓ Config file exists"
|
||||
if lsattr "$config_file" 2> /dev/null | grep -q '^....i'; then
|
||||
echo "✓ Config file is immutable"
|
||||
@ -1173,7 +1173,7 @@ test_setup() {
|
||||
echo "✗ Config file missing"
|
||||
fi
|
||||
|
||||
if [[ -f "$canonical_file" ]]; then
|
||||
if [[ -f $canonical_file ]]; then
|
||||
echo "✓ Canonical copy exists"
|
||||
else
|
||||
echo "✗ Canonical copy missing"
|
||||
|
||||
@ -74,7 +74,7 @@ check_aqt_conflict() {
|
||||
local sys_python="$1"
|
||||
local aqt_path="/usr/lib/python${sys_python}/site-packages/aqt/__init__.py"
|
||||
|
||||
if [[ -f "$aqt_path" ]]; then
|
||||
if [[ -f $aqt_path ]]; then
|
||||
if grep -q "aqtinstall" "$aqt_path" 2> /dev/null; then
|
||||
echo "aqtinstall"
|
||||
elif grep -q "anki" "$aqt_path" 2> /dev/null; then
|
||||
@ -112,7 +112,7 @@ main() {
|
||||
# Check which Anki package is installed
|
||||
local anki_pkg
|
||||
anki_pkg=$(check_anki_installed)
|
||||
if [[ -z "$anki_pkg" ]]; then
|
||||
if [[ -z $anki_pkg ]]; then
|
||||
log_error "Anki is not installed"
|
||||
exit 1
|
||||
fi
|
||||
@ -129,7 +129,7 @@ main() {
|
||||
local issues_found=false
|
||||
|
||||
# Check for Python version mismatch
|
||||
if [[ -n "$anki_python" && "$sys_python" != "$anki_python" ]]; then
|
||||
if [[ -n $anki_python && $sys_python != "$anki_python" ]]; then
|
||||
log_warn "Python version mismatch detected!"
|
||||
log_warn " Anki was built for Python $anki_python but system runs Python $sys_python"
|
||||
issues_found=true
|
||||
@ -149,7 +149,7 @@ main() {
|
||||
log_success "aqt module belongs to Anki (correct)"
|
||||
;;
|
||||
none)
|
||||
if [[ "$sys_python" != "$anki_python" ]]; then
|
||||
if [[ $sys_python != "$anki_python" ]]; then
|
||||
log_warn "No aqt module found for Python $sys_python"
|
||||
fi
|
||||
;;
|
||||
@ -162,7 +162,7 @@ main() {
|
||||
log_info "Testing Anki startup..."
|
||||
if python -c "from aqt import run" 2> /dev/null; then
|
||||
log_success "Anki imports work correctly"
|
||||
if [[ "$issues_found" == "false" ]]; then
|
||||
if [[ $issues_found == "false" ]]; then
|
||||
log_success "No issues found with Anki installation"
|
||||
exit 0
|
||||
fi
|
||||
@ -171,8 +171,8 @@ main() {
|
||||
issues_found=true
|
||||
fi
|
||||
|
||||
if [[ "$CHECK_ONLY" == "true" ]]; then
|
||||
if [[ "$issues_found" == "true" ]]; then
|
||||
if [[ $CHECK_ONLY == "true" ]]; then
|
||||
if [[ $issues_found == "true" ]]; then
|
||||
echo ""
|
||||
log_info "Issues detected. Run without --check to fix."
|
||||
exit 1
|
||||
@ -188,7 +188,7 @@ main() {
|
||||
if pacman -Qi python-aqtinstall &> /dev/null; then
|
||||
local required_by
|
||||
required_by=$(pacman -Qi python-aqtinstall | grep "Required By" | cut -d: -f2 | xargs)
|
||||
if [[ "$required_by" == "None" ]]; then
|
||||
if [[ $required_by == "None" ]]; then
|
||||
log_info "Removing python-aqtinstall (conflicts with Anki)..."
|
||||
sudo pacman -R --noconfirm python-aqtinstall
|
||||
else
|
||||
@ -198,10 +198,10 @@ main() {
|
||||
fi
|
||||
|
||||
# Rebuild anki package
|
||||
if [[ "$anki_pkg" == "anki-git" ]]; then
|
||||
if [[ $anki_pkg == "anki-git" ]]; then
|
||||
log_info "Rebuilding anki-git for Python $sys_python..."
|
||||
yay -S anki-git --rebuild --noconfirm
|
||||
elif [[ "$anki_pkg" == "anki" ]]; then
|
||||
elif [[ $anki_pkg == "anki" ]]; then
|
||||
log_info "Reinstalling anki..."
|
||||
sudo pacman -S anki --noconfirm
|
||||
else
|
||||
|
||||
@ -97,7 +97,7 @@ check_thorium_installed() {
|
||||
|
||||
# Check if config directory exists
|
||||
check_config_exists() {
|
||||
if [[ ! -d "$THORIUM_CONFIG_DIR" ]]; then
|
||||
if [[ ! -d $THORIUM_CONFIG_DIR ]]; then
|
||||
log_warn "Thorium config directory not found: $THORIUM_CONFIG_DIR"
|
||||
log_info "This may be a fresh install - try running thorium-browser directly"
|
||||
exit 0
|
||||
@ -127,7 +127,7 @@ backup_if_exists() {
|
||||
local name
|
||||
name=$(basename "$path")
|
||||
|
||||
if [[ -e "$path" ]]; then
|
||||
if [[ -e $path ]]; then
|
||||
local backup_path="${path}${BACKUP_SUFFIX}"
|
||||
if [[ $DRY_RUN == true ]]; then
|
||||
echo " [dry-run] Would backup: $name"
|
||||
@ -146,7 +146,7 @@ remove_if_exists() {
|
||||
local name
|
||||
name=$(basename "$path")
|
||||
|
||||
if [[ -e "$path" ]]; then
|
||||
if [[ -e $path ]]; then
|
||||
if [[ $DRY_RUN == true ]]; then
|
||||
echo " [dry-run] Would remove: $name"
|
||||
else
|
||||
@ -163,7 +163,7 @@ fix_local_state() {
|
||||
log_info "Checking Local State file..."
|
||||
local local_state="$THORIUM_CONFIG_DIR/Local State"
|
||||
|
||||
if [[ -f "$local_state" ]]; then
|
||||
if [[ -f $local_state ]]; then
|
||||
# Check if it's valid JSON
|
||||
if ! python3 -c "import json; json.load(open('$local_state'))" 2> /dev/null; then
|
||||
log_warn "Local State file appears corrupted"
|
||||
@ -226,7 +226,7 @@ fix_crash_reports() {
|
||||
log_info "Clearing old crash reports..."
|
||||
local crash_dir="$THORIUM_CONFIG_DIR/Crash Reports"
|
||||
|
||||
if [[ -d "$crash_dir" ]]; then
|
||||
if [[ -d $crash_dir ]]; then
|
||||
local crash_count
|
||||
crash_count=$(find "$crash_dir" -type f 2> /dev/null | wc -l)
|
||||
if [[ $crash_count -gt 0 ]]; then
|
||||
@ -268,7 +268,7 @@ fix_aggressive() {
|
||||
)
|
||||
|
||||
for db in "${db_files[@]}"; do
|
||||
if [[ -f "$db" ]]; then
|
||||
if [[ -f $db ]]; then
|
||||
log_info "Checking database: $(basename "$db")"
|
||||
# Simple corruption check - if sqlite3 can't open it, back it up
|
||||
if command -v sqlite3 &> /dev/null; then
|
||||
|
||||
@ -14,7 +14,7 @@ if pacman -Qi yay-git &>/dev/null; then
|
||||
echo "The 'database AUR not found' error is a known bug in some yay-git versions."
|
||||
echo ""
|
||||
read -rp "Switch to stable yay? [Y/n] " response
|
||||
if [[ "${response,,}" != "n" ]]; then
|
||||
if [[ ${response,,} != "n" ]]; then
|
||||
echo "Switching to stable yay..."
|
||||
|
||||
# Build and install stable yay from AUR
|
||||
@ -42,21 +42,21 @@ fi
|
||||
|
||||
# Remove yay's cache directory
|
||||
YAY_CACHE_DIR="${HOME}/.cache/yay"
|
||||
if [[ -d "$YAY_CACHE_DIR" ]]; then
|
||||
if [[ -d $YAY_CACHE_DIR ]]; then
|
||||
echo "Removing yay cache directory: $YAY_CACHE_DIR"
|
||||
rm -rf "$YAY_CACHE_DIR"
|
||||
fi
|
||||
|
||||
# Remove yay's local database directory (stores AUR package info)
|
||||
YAY_DB_DIR="${HOME}/.local/share/yay"
|
||||
if [[ -d "$YAY_DB_DIR" ]]; then
|
||||
if [[ -d $YAY_DB_DIR ]]; then
|
||||
echo "Removing yay database directory: $YAY_DB_DIR"
|
||||
rm -rf "$YAY_DB_DIR"
|
||||
fi
|
||||
|
||||
# Remove yay state directory
|
||||
YAY_STATE_DIR="${HOME}/.local/state/yay"
|
||||
if [[ -d "$YAY_STATE_DIR" ]]; then
|
||||
if [[ -d $YAY_STATE_DIR ]]; then
|
||||
echo "Removing yay state directory: $YAY_STATE_DIR"
|
||||
rm -rf "$YAY_STATE_DIR"
|
||||
fi
|
||||
|
||||
@ -39,7 +39,7 @@ EXCLUDE_DIRS="node_modules|\.git|vendor|\.venv|venv|__pycache__|\.cache|build|di
|
||||
|
||||
# Detect if input is a URL or local path
|
||||
is_url() {
|
||||
[[ "$1" =~ ^https?:// ]] || [[ "$1" =~ ^git@ ]] || [[ "$1" =~ ^ssh:// ]]
|
||||
[[ $1 =~ ^https?:// ]] || [[ $1 =~ ^git@ ]] || [[ $1 =~ ^ssh:// ]]
|
||||
}
|
||||
|
||||
IS_LOCAL=false
|
||||
@ -292,7 +292,10 @@ echo "Location: $REPO_DIR"
|
||||
echo "Repository size: $(du -sh . | cut -f1)"
|
||||
if [ "$RESPECT_GITIGNORE" = true ] && is_git_repo; then
|
||||
# Count files respecting .gitignore
|
||||
FILE_COUNT=$({ git ls-files 2>/dev/null; git ls-files --others --exclude-standard 2>/dev/null; } | sort -u | wc -l)
|
||||
FILE_COUNT=$({
|
||||
git ls-files 2> /dev/null
|
||||
git ls-files --others --exclude-standard 2> /dev/null
|
||||
} | sort -u | wc -l)
|
||||
echo "Files: $FILE_COUNT (respecting .gitignore)"
|
||||
elif [ "$RESPECT_GITIGNORE" = true ]; then
|
||||
echo "Files: $(find . -type f 2> /dev/null | grep -Ev "/($EXCLUDE_DIRS)/" | wc -l) (excluding common dirs)"
|
||||
@ -559,9 +562,9 @@ for lang in "${!LANG_CODE_FILES[@]}"; do
|
||||
if [ -f "$code_file" ] && [ -s "$code_file" ] && [ -n "$keywords" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== $lang Keywords ===${NC}"
|
||||
ugrep -o "\b($keywords)\b" "$code_file" 2>/dev/null \
|
||||
| fast_count 50 \
|
||||
| tee "$output_file"
|
||||
ugrep -o "\b($keywords)\b" "$code_file" 2> /dev/null |
|
||||
fast_count 50 |
|
||||
tee "$output_file"
|
||||
fi
|
||||
done
|
||||
|
||||
@ -577,11 +580,11 @@ for lang in "${!LANG_CODE_FILES[@]}"; do
|
||||
if [ -f "$code_file" ] && [ -s "$code_file" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== $lang Functions ===${NC}"
|
||||
ugrep -o '\b[a-zA-Z_][a-zA-Z0-9_]*\s*\(' "$code_file" 2>/dev/null \
|
||||
| sed 's/\s*(//' \
|
||||
| grep -vE '^(if|for|while|switch|catch|elif)$' \
|
||||
| fast_count 30 \
|
||||
| tee "$output_file"
|
||||
ugrep -o '\b[a-zA-Z_][a-zA-Z0-9_]*\s*\(' "$code_file" 2> /dev/null |
|
||||
sed 's/\s*(//' |
|
||||
grep -vE '^(if|for|while|switch|catch|elif)$' |
|
||||
fast_count 30 |
|
||||
tee "$output_file"
|
||||
fi
|
||||
done
|
||||
|
||||
@ -593,84 +596,84 @@ print_subheader "Per-Language Imports/Includes"
|
||||
# C/C++ includes
|
||||
if [ -n "${LANG_CODE_FILES[c_cpp]}" ] && [ -s "${LANG_CODE_FILES[c_cpp]}" ]; then
|
||||
echo -e "${YELLOW}=== C/C++ Includes ===${NC}"
|
||||
ugrep -o '#include\s*[<"][^>"]+[>"]' "${LANG_CODE_FILES[c_cpp]}" 2>/dev/null \
|
||||
| fast_count 30 \
|
||||
| tee "$RESULTS_DIR/per_language/imports_c_cpp.txt"
|
||||
ugrep -o '#include\s*[<"][^>"]+[>"]' "${LANG_CODE_FILES[c_cpp]}" 2> /dev/null |
|
||||
fast_count 30 |
|
||||
tee "$RESULTS_DIR/per_language/imports_c_cpp.txt"
|
||||
fi
|
||||
|
||||
# Python imports
|
||||
if [ -n "${LANG_CODE_FILES[python]}" ] && [ -s "${LANG_CODE_FILES[python]}" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== Python Imports ===${NC}"
|
||||
ugrep -o '^\s*(from\s+\S+\s+import\s+\S+|import\s+\S+)' "${LANG_CODE_FILES[python]}" 2>/dev/null \
|
||||
| sed 's/^\s*//' \
|
||||
| fast_count 30 \
|
||||
| tee "$RESULTS_DIR/per_language/imports_python.txt"
|
||||
ugrep -o '^\s*(from\s+\S+\s+import\s+\S+|import\s+\S+)' "${LANG_CODE_FILES[python]}" 2> /dev/null |
|
||||
sed 's/^\s*//' |
|
||||
fast_count 30 |
|
||||
tee "$RESULTS_DIR/per_language/imports_python.txt"
|
||||
fi
|
||||
|
||||
# JavaScript imports
|
||||
if [ -n "${LANG_CODE_FILES[javascript]}" ] && [ -s "${LANG_CODE_FILES[javascript]}" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== JavaScript Imports ===${NC}"
|
||||
ugrep -o "(import\s+.*\s+from\s+['\"][^'\"]+['\"]|require\s*\(['\"][^'\"]+['\"]\))" "${LANG_CODE_FILES[javascript]}" 2>/dev/null \
|
||||
| fast_count 30 \
|
||||
| tee "$RESULTS_DIR/per_language/imports_javascript.txt"
|
||||
ugrep -o "(import\s+.*\s+from\s+['\"][^'\"]+['\"]|require\s*\(['\"][^'\"]+['\"]\))" "${LANG_CODE_FILES[javascript]}" 2> /dev/null |
|
||||
fast_count 30 |
|
||||
tee "$RESULTS_DIR/per_language/imports_javascript.txt"
|
||||
fi
|
||||
|
||||
# TypeScript imports
|
||||
if [ -n "${LANG_CODE_FILES[typescript]}" ] && [ -s "${LANG_CODE_FILES[typescript]}" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== TypeScript Imports ===${NC}"
|
||||
ugrep -o "(import\s+.*\s+from\s+['\"][^'\"]+['\"]|require\s*\(['\"][^'\"]+['\"]\))" "${LANG_CODE_FILES[typescript]}" 2>/dev/null \
|
||||
| fast_count 30 \
|
||||
| tee "$RESULTS_DIR/per_language/imports_typescript.txt"
|
||||
ugrep -o "(import\s+.*\s+from\s+['\"][^'\"]+['\"]|require\s*\(['\"][^'\"]+['\"]\))" "${LANG_CODE_FILES[typescript]}" 2> /dev/null |
|
||||
fast_count 30 |
|
||||
tee "$RESULTS_DIR/per_language/imports_typescript.txt"
|
||||
fi
|
||||
|
||||
# Go imports
|
||||
if [ -n "${LANG_CODE_FILES[go]}" ] && [ -s "${LANG_CODE_FILES[go]}" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== Go Imports ===${NC}"
|
||||
ugrep -o '"[^"]+/[^"]+"' "${LANG_CODE_FILES[go]}" 2>/dev/null \
|
||||
| fast_count 30 \
|
||||
| tee "$RESULTS_DIR/per_language/imports_go.txt"
|
||||
ugrep -o '"[^"]+/[^"]+"' "${LANG_CODE_FILES[go]}" 2> /dev/null |
|
||||
fast_count 30 |
|
||||
tee "$RESULTS_DIR/per_language/imports_go.txt"
|
||||
fi
|
||||
|
||||
# Rust use statements
|
||||
if [ -n "${LANG_CODE_FILES[rust]}" ] && [ -s "${LANG_CODE_FILES[rust]}" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== Rust Use Statements ===${NC}"
|
||||
ugrep -o '^\s*use\s+[^;]+' "${LANG_CODE_FILES[rust]}" 2>/dev/null \
|
||||
| sed 's/^\s*//' \
|
||||
| fast_count 30 \
|
||||
| tee "$RESULTS_DIR/per_language/imports_rust.txt"
|
||||
ugrep -o '^\s*use\s+[^;]+' "${LANG_CODE_FILES[rust]}" 2> /dev/null |
|
||||
sed 's/^\s*//' |
|
||||
fast_count 30 |
|
||||
tee "$RESULTS_DIR/per_language/imports_rust.txt"
|
||||
fi
|
||||
|
||||
# Java imports
|
||||
if [ -n "${LANG_CODE_FILES[java]}" ] && [ -s "${LANG_CODE_FILES[java]}" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== Java Imports ===${NC}"
|
||||
ugrep -o '^\s*import\s+[^;]+' "${LANG_CODE_FILES[java]}" 2>/dev/null \
|
||||
| sed 's/^\s*//' \
|
||||
| fast_count 30 \
|
||||
| tee "$RESULTS_DIR/per_language/imports_java.txt"
|
||||
ugrep -o '^\s*import\s+[^;]+' "${LANG_CODE_FILES[java]}" 2> /dev/null |
|
||||
sed 's/^\s*//' |
|
||||
fast_count 30 |
|
||||
tee "$RESULTS_DIR/per_language/imports_java.txt"
|
||||
fi
|
||||
|
||||
# Ruby requires
|
||||
if [ -n "${LANG_CODE_FILES[ruby]}" ] && [ -s "${LANG_CODE_FILES[ruby]}" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== Ruby Requires ===${NC}"
|
||||
ugrep -o "(require\s+['\"][^'\"]+['\"]|require_relative\s+['\"][^'\"]+['\"])" "${LANG_CODE_FILES[ruby]}" 2>/dev/null \
|
||||
| fast_count 30 \
|
||||
| tee "$RESULTS_DIR/per_language/imports_ruby.txt"
|
||||
ugrep -o "(require\s+['\"][^'\"]+['\"]|require_relative\s+['\"][^'\"]+['\"])" "${LANG_CODE_FILES[ruby]}" 2> /dev/null |
|
||||
fast_count 30 |
|
||||
tee "$RESULTS_DIR/per_language/imports_ruby.txt"
|
||||
fi
|
||||
|
||||
# Shell sources
|
||||
if [ -n "${LANG_CODE_FILES[shell]}" ] && [ -s "${LANG_CODE_FILES[shell]}" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}=== Shell Sources ===${NC}"
|
||||
ugrep -o '(source\s+[^\s]+|\.\s+[^\s]+)' "${LANG_CODE_FILES[shell]}" 2>/dev/null \
|
||||
| fast_count 30 \
|
||||
| tee "$RESULTS_DIR/per_language/imports_shell.txt"
|
||||
ugrep -o '(source\s+[^\s]+|\.\s+[^\s]+)' "${LANG_CODE_FILES[shell]}" 2> /dev/null |
|
||||
fast_count 30 |
|
||||
tee "$RESULTS_DIR/per_language/imports_shell.txt"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
@ -684,14 +687,14 @@ for lang_file in "${LANG_CODE_FILES[@]}"; do
|
||||
[ -f "$lang_file" ] && cat "$lang_file" >> "$CODE_TEMP"
|
||||
done
|
||||
|
||||
ugrep -o '\b[a-zA-Z_][a-zA-Z0-9_]*\b' "$CODE_TEMP" 2>/dev/null \
|
||||
| fast_count $TOP_N \
|
||||
| tee "$RESULTS_DIR/code_identifiers.txt"
|
||||
ugrep -o '\b[a-zA-Z_][a-zA-Z0-9_]*\b' "$CODE_TEMP" 2> /dev/null |
|
||||
fast_count $TOP_N |
|
||||
tee "$RESULTS_DIR/code_identifiers.txt"
|
||||
|
||||
print_subheader "Most Used Words in COMMENTS"
|
||||
ugrep -o '\b[a-zA-Z_][a-zA-Z0-9_]*\b' "$COMMENTS_TEMP" 2>/dev/null \
|
||||
| fast_count $TOP_N \
|
||||
| tee "$RESULTS_DIR/comment_words.txt"
|
||||
ugrep -o '\b[a-zA-Z_][a-zA-Z0-9_]*\b' "$COMMENTS_TEMP" 2> /dev/null |
|
||||
fast_count $TOP_N |
|
||||
tee "$RESULTS_DIR/comment_words.txt"
|
||||
|
||||
# Create combined files from per-language analysis (for backward compatibility)
|
||||
{
|
||||
@ -717,7 +720,6 @@ echo ""
|
||||
echo "Per-language analysis files created:"
|
||||
ls -la "$RESULTS_DIR/per_language/" 2> /dev/null | grep -v '^total' | awk '{print " " $NF}'
|
||||
|
||||
|
||||
print_subheader "Generating tags (this may take a while)..."
|
||||
|
||||
# Generate tags for different kinds
|
||||
@ -730,8 +732,8 @@ if [ -f "$RESULTS_DIR/tags" ]; then
|
||||
print_subheader "Most Common Symbol Names"
|
||||
# Fast: use cut + counts instead of awk + sort | uniq
|
||||
# -a flag treats tags file as text (may contain binary-like patterns)
|
||||
grep -a '^[^!]' "$RESULTS_DIR/tags" | cut -f1 | fast_count $TOP_N \
|
||||
| tee "$RESULTS_DIR/ctags_symbols.txt"
|
||||
grep -a '^[^!]' "$RESULTS_DIR/tags" | cut -f1 | fast_count $TOP_N |
|
||||
tee "$RESULTS_DIR/ctags_symbols.txt"
|
||||
|
||||
print_subheader "Symbol Types Distribution"
|
||||
# Fast: extract single-letter kind code after ;" and count
|
||||
@ -763,7 +765,10 @@ print_subheader "Building cscope database..."
|
||||
|
||||
# Find all C source files (respecting .gitignore if available)
|
||||
if [ "$RESPECT_GITIGNORE" = true ] && is_git_repo; then
|
||||
{ git ls-files -- '*.c' '*.h' 2>/dev/null; git ls-files --others --exclude-standard -- '*.c' '*.h' 2>/dev/null; } | sort -u > "$RESULTS_DIR/cscope.files"
|
||||
{
|
||||
git ls-files -- '*.c' '*.h' 2> /dev/null
|
||||
git ls-files --others --exclude-standard -- '*.c' '*.h' 2> /dev/null
|
||||
} | sort -u > "$RESULTS_DIR/cscope.files"
|
||||
elif [ "$RESPECT_GITIGNORE" = true ]; then
|
||||
find . \( -name "*.c" -o -name "*.h" \) -type f 2> /dev/null | grep -Ev "/($EXCLUDE_DIRS)/" > "$RESULTS_DIR/cscope.files"
|
||||
else
|
||||
@ -809,11 +814,11 @@ if [ -n "$SAMPLE_FILE" ]; then
|
||||
echo "Sample file: $SAMPLE_FILE"
|
||||
echo ""
|
||||
echo "Function declarations in this file:"
|
||||
clang -Xclang -ast-dump -fsyntax-only "$SAMPLE_FILE" 2>/dev/null \
|
||||
| grep -E "FunctionDecl.*<.*>" \
|
||||
| head -20 \
|
||||
| sed 's/.*FunctionDecl.*<[^>]*> / /' \
|
||||
| tee "$RESULTS_DIR/clang_sample_functions.txt" || echo "Analysis failed (missing headers)"
|
||||
clang -Xclang -ast-dump -fsyntax-only "$SAMPLE_FILE" 2> /dev/null |
|
||||
grep -E "FunctionDecl.*<.*>" |
|
||||
head -20 |
|
||||
sed 's/.*FunctionDecl.*<[^>]*> / /' |
|
||||
tee "$RESULTS_DIR/clang_sample_functions.txt" || echo "Analysis failed (missing headers)"
|
||||
fi
|
||||
|
||||
print_subheader "Note: Full clang analysis requires compile_commands.json"
|
||||
|
||||
@ -54,7 +54,7 @@ echo ""
|
||||
for track in "${!TRACKS[@]}"; do
|
||||
url="${TRACKS[$track]}"
|
||||
|
||||
if [[ -d "$track" ]]; then
|
||||
if [[ -d $track ]]; then
|
||||
info "Updating $track..."
|
||||
(cd "$track" && git pull --quiet) && success "$track updated"
|
||||
else
|
||||
|
||||
@ -56,7 +56,7 @@ FOUND_FILES=$(timeout "$TIMEOUT_SECONDS" fd \
|
||||
--exclude '/lost+found' \
|
||||
. "$SEARCH_ROOT" 2> /dev/null || true)
|
||||
|
||||
if [[ -z "$FOUND_FILES" ]]; then
|
||||
if [[ -z $FOUND_FILES ]]; then
|
||||
log "No .kdbx files found."
|
||||
exit 0
|
||||
fi
|
||||
@ -74,7 +74,7 @@ MOVED_COUNT=0
|
||||
SKIPPED_COUNT=0
|
||||
|
||||
while IFS= read -r src_file; do
|
||||
[[ -z "$src_file" ]] && continue
|
||||
[[ -z $src_file ]] && continue
|
||||
|
||||
# Skip if file is already in destination
|
||||
if [[ "$(dirname "$src_file")" == "$DEST_DIR" ]]; then
|
||||
@ -88,7 +88,7 @@ while IFS= read -r src_file; do
|
||||
dest_file="$DEST_DIR/$base_name"
|
||||
|
||||
# Handle filename conflicts by adding a number suffix
|
||||
if [[ -f "$dest_file" ]]; then
|
||||
if [[ -f $dest_file ]]; then
|
||||
# Check if it's the exact same file (by content)
|
||||
if cmp -s "$src_file" "$dest_file"; then
|
||||
log "Skipping (identical file exists): $src_file"
|
||||
@ -101,7 +101,7 @@ while IFS= read -r src_file; do
|
||||
# Different file with same name - add suffix
|
||||
counter=1
|
||||
name_without_ext="${base_name%.kdbx}"
|
||||
while [[ -f "$dest_file" ]]; do
|
||||
while [[ -f $dest_file ]]; do
|
||||
dest_file="$DEST_DIR/${name_without_ext} ($counter).kdbx"
|
||||
((counter++))
|
||||
done
|
||||
|
||||
@ -366,7 +366,7 @@ get_doc_url() {
|
||||
fi
|
||||
|
||||
# For TypeScript, also try JavaScript offline docs (most TS keywords are JS)
|
||||
if [[ "$lang" == "typescript" || "$lang" == "ts" || "$lang" == "tsx" ]]; then
|
||||
if [[ $lang == "typescript" || $lang == "ts" || $lang == "tsx" ]]; then
|
||||
offline_result=$(lookup_offline "$term" "js" "$import_line")
|
||||
if [ -n "$offline_result" ]; then
|
||||
echo "$offline_result"
|
||||
@ -427,10 +427,10 @@ get_doc_url() {
|
||||
detect_language() {
|
||||
if [ -f "$RESULTS_DIR/tokei_stats.txt" ]; then
|
||||
# Parse tokei output to find most used language
|
||||
grep -E "^\s+(Python|JavaScript|TypeScript|C\+\+|C |Rust|Go|Ruby|Java|Shell)" "$RESULTS_DIR/tokei_stats.txt" 2>/dev/null \
|
||||
| head -1 \
|
||||
| awk '{print tolower($1)}' \
|
||||
| sed 's/c++/cpp/'
|
||||
grep -E "^\s+(Python|JavaScript|TypeScript|C\+\+|C |Rust|Go|Ruby|Java|Shell)" "$RESULTS_DIR/tokei_stats.txt" 2> /dev/null |
|
||||
head -1 |
|
||||
awk '{print tolower($1)}' |
|
||||
sed 's/c++/cpp/'
|
||||
else
|
||||
echo "unknown"
|
||||
fi
|
||||
@ -530,7 +530,7 @@ if [ -d "$PER_LANG_DIR" ]; then
|
||||
|
||||
head -$TOP_N "$keyword_file" | while read -r count term; do
|
||||
[ -z "$term" ] && continue
|
||||
[[ "$term" =~ ^[#] ]] && continue # Skip comment lines
|
||||
[[ $term =~ ^[#] ]] && continue # Skip comment lines
|
||||
url=$(get_doc_url "$term" "$doc_lang")
|
||||
echo "| \`$term\` | $count | [docs]($url) |" >> "$DOCS_FILE"
|
||||
done
|
||||
@ -568,7 +568,7 @@ if [ -d "$PER_LANG_DIR" ]; then
|
||||
|
||||
head -$TOP_N "$func_file" | while read -r count term; do
|
||||
[ -z "$term" ] && continue
|
||||
[[ "$term" =~ ^(if|for|while|switch|catch|elif)$ ]] && continue
|
||||
[[ $term =~ ^(if|for|while|switch|catch|elif)$ ]] && continue
|
||||
url=$(get_doc_url "$term" "$doc_lang")
|
||||
echo "| \`$term()\` | $count | [docs]($url) |" >> "$DOCS_FILE"
|
||||
done
|
||||
@ -608,7 +608,7 @@ if [ -d "$PER_LANG_DIR" ]; then
|
||||
[ -z "$import" ] && continue
|
||||
# For offline lookup, pass the full import line for better context
|
||||
url=$(get_doc_url "" "$doc_lang" "$import")
|
||||
if [ -z "$url" ] || [[ "$url" == *"search.html"* ]]; then
|
||||
if [ -z "$url" ] || [[ $url == *"search.html"* ]]; then
|
||||
# Fallback: extract module and try again
|
||||
module=$(echo "$import" | sed -E 's/.*[<"]([^">]+)[">].*/\1/' | sed 's|.*/||' | sed 's/\..*$//')
|
||||
url=$(get_doc_url "$module" "$doc_lang")
|
||||
@ -645,7 +645,7 @@ else
|
||||
|
||||
head -$TOP_N "$RESULTS_DIR/grep_function_calls.txt" | while read -r count term; do
|
||||
[ -z "$term" ] && continue
|
||||
[[ "$term" =~ ^(if|for|while|switch|catch)$ ]] && continue
|
||||
[[ $term =~ ^(if|for|while|switch|catch)$ ]] && continue
|
||||
url=$(get_doc_url "$term" "$PRIMARY_LANG")
|
||||
echo "| \`$term()\` | $count | [docs]($url) |" >> "$DOCS_FILE"
|
||||
done
|
||||
@ -734,7 +734,7 @@ if [ -f "$RESULTS_DIR/grep_function_calls.txt" ]; then
|
||||
echo "# Functions" >> "$ANKI_FILE"
|
||||
head -$TOP_N "$RESULTS_DIR/grep_function_calls.txt" | while read -r count term; do
|
||||
[ -z "$term" ] && continue
|
||||
[[ "$term" =~ ^(if|for|while|switch|catch)$ ]] && continue
|
||||
[[ $term =~ ^(if|for|while|switch|catch)$ ]] && continue
|
||||
url=$(get_doc_url "$term" "$PRIMARY_LANG")
|
||||
|
||||
echo -e "What does \`$term()\` do in $PRIMARY_LANG? (Used $count times)\t[FILL: Look up at $url]\t${PRIMARY_LANG}::functions" >> "$ANKI_FILE"
|
||||
@ -755,7 +755,7 @@ get_llm_doc_link() {
|
||||
local is_import="$3" # "true" if it's an import line
|
||||
|
||||
# Check if it's an internal/project-specific item
|
||||
if [[ "$term" =~ ^@/ ]] || [[ "$term" =~ ^\./ ]] || [[ "$term" =~ ^app\. ]] || [[ "$term" =~ ^src/ ]] || [[ "$term" =~ from\ \'@/ ]] || [[ "$term" =~ from\ \'\./ ]]; then
|
||||
if [[ $term =~ ^@/ ]] || [[ $term =~ ^\./ ]] || [[ $term =~ ^app\. ]] || [[ $term =~ ^src/ ]] || [[ $term =~ from\ \'@/ ]] || [[ $term =~ from\ \'\./ ]]; then
|
||||
echo "[INTERNAL - SKIP]"
|
||||
return
|
||||
fi
|
||||
@ -819,7 +819,7 @@ generate_imports_with_docs() {
|
||||
[ -z "$import_stmt" ] && continue
|
||||
|
||||
# Check if internal import
|
||||
if [[ "$import_stmt" =~ @/ ]] || [[ "$import_stmt" =~ \'\./ ]] || [[ "$import_stmt" =~ from\ app\. ]] || [[ "$import_stmt" =~ from\ src\. ]]; then
|
||||
if [[ $import_stmt =~ @/ ]] || [[ $import_stmt =~ \'\./ ]] || [[ $import_stmt =~ from\ app\. ]] || [[ $import_stmt =~ from\ src\. ]]; then
|
||||
echo "$count $import_stmt → [INTERNAL - SKIP]"
|
||||
else
|
||||
local doc_link=$(get_llm_doc_link "$import_stmt" "$PRIMARY_LANG" "true")
|
||||
@ -962,7 +962,6 @@ PROMPT_FOOTER
|
||||
|
||||
echo -e "${GREEN}Created: $LLM_PROMPT_FILE${NC}"
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# Summary
|
||||
#==============================================================================
|
||||
|
||||
@ -85,7 +85,7 @@ install_exercism_cli() {
|
||||
|
||||
download_url=$(curl -fsSL "$latest_url" | grep "browser_download_url.*${os}-${arch}" | head -1 | cut -d '"' -f 4)
|
||||
|
||||
if [[ -z "$download_url" ]]; then
|
||||
if [[ -z $download_url ]]; then
|
||||
error "Could not find download URL for your system"
|
||||
echo "Please install manually from: https://exercism.org/docs/using/solving-exercises/working-locally"
|
||||
return 1
|
||||
@ -203,7 +203,7 @@ download_track() {
|
||||
exercises=$(curl -fsSL "https://exercism.org/api/v2/tracks/${track}/exercises" 2> /dev/null |
|
||||
grep -oP '"slug":"\K[^"]+' | head -n "$count")
|
||||
|
||||
if [[ -z "$exercises" ]]; then
|
||||
if [[ -z $exercises ]]; then
|
||||
warn "Could not fetch exercise list for $track"
|
||||
return 1
|
||||
fi
|
||||
@ -211,7 +211,7 @@ download_track() {
|
||||
local downloaded=0
|
||||
for exercise in $exercises; do
|
||||
local exercise_dir="$EXERCISM_DIR/$track/$exercise"
|
||||
if [[ -d "$exercise_dir" ]]; then
|
||||
if [[ -d $exercise_dir ]]; then
|
||||
echo " [exists] $exercise"
|
||||
else
|
||||
if exercism download --track="$track" --exercise="$exercise" 2> /dev/null; then
|
||||
@ -256,8 +256,8 @@ show_usage() {
|
||||
echo ""
|
||||
echo -e "${CYAN}Batch download (requires API token):${NC}"
|
||||
echo " # Download first 20 Python exercises:"
|
||||
echo " for ex in \$(exercism download --track=python 2>&1 | head -20); do"
|
||||
echo " exercism download --track=python --exercise=\$ex"
|
||||
echo ' for ex in $(exercism download --track=python 2>&1 | head -20); do'
|
||||
echo ' exercism download --track=python --exercise=$ex'
|
||||
echo " done"
|
||||
echo ""
|
||||
echo "Exercises are in: $EXERCISM_DIR"
|
||||
@ -291,7 +291,7 @@ main() {
|
||||
|
||||
for track in "${tracks[@]}"; do
|
||||
local exercise_dir="$EXERCISM_DIR/$track/hello-world"
|
||||
if [[ -d "$exercise_dir" ]]; then
|
||||
if [[ -d $exercise_dir ]]; then
|
||||
echo " [$track] hello-world already exists"
|
||||
else
|
||||
if exercism download --track="$track" --exercise="hello-world" 2> /dev/null; then
|
||||
|
||||
@ -184,7 +184,7 @@ main() {
|
||||
# Ask about extras
|
||||
echo ""
|
||||
read -r -p "Install additional docsets (Bash, HTML, CSS, NodeJS)? [Y/n] " response
|
||||
if [[ ! "$response" =~ ^[Nn]$ ]]; then
|
||||
if [[ ! $response =~ ^[Nn]$ ]]; then
|
||||
for docset in "${extras[@]}"; do
|
||||
download_docset "$docset" "$docsets_dir"
|
||||
done
|
||||
@ -198,7 +198,7 @@ main() {
|
||||
echo ""
|
||||
echo "Installed documentation:"
|
||||
for f in "$docsets_dir"/*.docset; do
|
||||
if [[ -d "$f" ]]; then
|
||||
if [[ -d $f ]]; then
|
||||
echo " ✓ $(basename "$f" .docset)"
|
||||
fi
|
||||
done
|
||||
@ -219,7 +219,7 @@ main() {
|
||||
|
||||
# Offer to launch Zeal
|
||||
read -r -p "Launch Zeal now? [y/N] " response
|
||||
if [[ "$response" =~ ^[Yy]$ ]]; then
|
||||
if [[ $response =~ ^[Yy]$ ]]; then
|
||||
nohup zeal &> /dev/null &
|
||||
success "Zeal launched"
|
||||
fi
|
||||
|
||||
@ -691,7 +691,7 @@ parse_python_import() {
|
||||
local import_line="$1"
|
||||
|
||||
# Handle "from X import Y" format
|
||||
if [[ "$import_line" =~ ^from[[:space:]]+([^[:space:]]+)[[:space:]]+import[[:space:]]+(.+) ]]; then
|
||||
if [[ $import_line =~ ^from[[:space:]]+([^[:space:]]+)[[:space:]]+import[[:space:]]+(.+) ]]; then
|
||||
local module="${BASH_REMATCH[1]}"
|
||||
local items="${BASH_REMATCH[2]}"
|
||||
|
||||
@ -704,7 +704,7 @@ parse_python_import() {
|
||||
fi
|
||||
|
||||
# Handle "import X" format
|
||||
if [[ "$import_line" =~ ^import[[:space:]]+([^[:space:],]+) ]]; then
|
||||
if [[ $import_line =~ ^import[[:space:]]+([^[:space:],]+) ]]; then
|
||||
local module="${BASH_REMATCH[1]}"
|
||||
echo "$module|"
|
||||
return 0
|
||||
@ -778,7 +778,7 @@ extract_doc_content() {
|
||||
local term="$2"
|
||||
local max_lines="${3:-20}"
|
||||
|
||||
if [[ "$file" == *.html ]]; then
|
||||
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"
|
||||
@ -788,7 +788,7 @@ extract_doc_content() {
|
||||
# Basic extraction
|
||||
sed 's/<[^>]*>//g' "$file" | grep -A"$max_lines" -i "$term" | head -"$max_lines"
|
||||
fi
|
||||
elif [[ "$file" == *.json ]]; then
|
||||
elif [[ $file == *.json ]]; then
|
||||
# Pretty print JSON section
|
||||
grep -A5 "\"$term\"" "$file" 2> /dev/null
|
||||
else
|
||||
@ -929,7 +929,7 @@ main() {
|
||||
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
[ -z "$line" ] && continue
|
||||
[[ "$line" =~ ^# ]] && continue
|
||||
[[ $line =~ ^# ]] && continue
|
||||
|
||||
echo -e "${CYAN}Looking up:${NC} $line"
|
||||
lookup_import "$line" "$lang"
|
||||
|
||||
@ -160,7 +160,7 @@ get_repo() {
|
||||
local repo_dir=""
|
||||
|
||||
# Check if it's a URL (git clone needed)
|
||||
if [[ "$input" =~ ^https?:// ]] || [[ "$input" =~ ^git@ ]]; then
|
||||
if [[ $input =~ ^https?:// ]] || [[ $input =~ ^git@ ]]; then
|
||||
print_step "Cloning repository..."
|
||||
|
||||
# Extract repo name from URL
|
||||
@ -293,8 +293,8 @@ show_summary() {
|
||||
echo ""
|
||||
echo -e "${BOLD}Quick preview of imports with offline docs:${NC}"
|
||||
if [ -f "$output_dir/documentation_links.md" ]; then
|
||||
grep -A20 "import/from" "$output_dir/documentation_links.md" 2>/dev/null | \
|
||||
grep "^\| \`" | head -5 | \
|
||||
grep -A20 "import/from" "$output_dir/documentation_links.md" 2> /dev/null |
|
||||
grep "^\| \`" | head -5 |
|
||||
sed 's/|/│/g'
|
||||
fi
|
||||
|
||||
@ -339,7 +339,7 @@ main() {
|
||||
# Set default output dir based on repo name
|
||||
if [ -z "$output_dir" ]; then
|
||||
output_dir="$STUDY_MATERIALS_BASE/$REPO_NAME"
|
||||
elif [[ "$output_dir" != /* ]]; then
|
||||
elif [[ $output_dir != /* ]]; then
|
||||
# Convert relative to absolute
|
||||
output_dir="$(pwd)/$output_dir"
|
||||
fi
|
||||
|
||||
@ -99,8 +99,8 @@ build_python_index() {
|
||||
|
||||
# Index from general index
|
||||
if [ -f "$dest/genindex.html" ]; then
|
||||
grep -oP 'href="([^"]+)"[^>]*>([^<]+)' "$dest/genindex.html" 2>/dev/null | \
|
||||
sed -E 's/href="([^"]+)"[^>]*>([^<]+)/\2 \1/' | \
|
||||
grep -oP 'href="([^"]+)"[^>]*>([^<]+)' "$dest/genindex.html" 2> /dev/null |
|
||||
sed -E 's/href="([^"]+)"[^>]*>([^<]+)/\2 \1/' |
|
||||
head -5000
|
||||
fi
|
||||
} | sort -u > "$index"
|
||||
@ -202,7 +202,7 @@ build_cpp_index() {
|
||||
local term
|
||||
term=$(basename "$file" .html)
|
||||
# Skip index files and overly generic names
|
||||
[[ "$term" == "index" ]] && continue
|
||||
[[ $term == "index" ]] && continue
|
||||
echo "${term}|${file}"
|
||||
done
|
||||
|
||||
@ -215,7 +215,7 @@ build_cpp_index() {
|
||||
# Get the last component as primary term
|
||||
local term
|
||||
term=$(basename "$relpath")
|
||||
[[ "$term" == "index" ]] && continue
|
||||
[[ $term == "index" ]] && continue
|
||||
# Also add the full path as a searchable term (cpp/vector, c/stdlib/malloc)
|
||||
echo "${relpath}|${file}"
|
||||
done
|
||||
|
||||
@ -31,7 +31,7 @@ if ! command -v keepassxc-cli &>/dev/null; then
|
||||
fi
|
||||
|
||||
# Check if directory exists
|
||||
if [[ ! -d "$KEEPASS_DIR" ]]; then
|
||||
if [[ ! -d $KEEPASS_DIR ]]; then
|
||||
log "ERROR: Directory does not exist: $KEEPASS_DIR"
|
||||
exit 1
|
||||
fi
|
||||
@ -74,7 +74,7 @@ echo "Backups are stored in: $BACKUP_DIR"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
read -rp "Do you want to continue? (yes/no): " CONFIRM
|
||||
if [[ "$CONFIRM" != "yes" ]]; then
|
||||
if [[ $CONFIRM != "yes" ]]; then
|
||||
log "Aborted by user."
|
||||
exit 1
|
||||
fi
|
||||
@ -112,7 +112,7 @@ for ((i = 1; i < ${#KDBX_FILES[@]}; i++)); do
|
||||
log "Merging $(basename "$SOURCE_DB") into $(basename "$TARGET_DB")..."
|
||||
|
||||
# Reuse target password if user confirmed all are the same
|
||||
if [[ "$SAME_PASSWORD" == "y" || "$SAME_PASSWORD" == "yes" ]]; then
|
||||
if [[ $SAME_PASSWORD == "y" || $SAME_PASSWORD == "yes" ]]; then
|
||||
SOURCE_PASSWORD="$TARGET_PASSWORD"
|
||||
else
|
||||
# Ask for source password (might be different)
|
||||
@ -161,9 +161,9 @@ FINAL_COUNT=$(find "$KEEPASS_DIR" -maxdepth 1 -name "*.kdbx" -type f | wc -l)
|
||||
if [[ $FINAL_COUNT -eq 1 ]]; then
|
||||
log ""
|
||||
FINAL_NAME="$KEEPASS_DIR/Passwords.kdbx"
|
||||
if [[ "$TARGET_DB" != "$FINAL_NAME" ]]; then
|
||||
if [[ $TARGET_DB != "$FINAL_NAME" ]]; then
|
||||
read -rp "Rename final database to 'Passwords.kdbx'? (y/n): " RENAME_CONFIRM
|
||||
if [[ "$RENAME_CONFIRM" == "y" ]]; then
|
||||
if [[ $RENAME_CONFIRM == "y" ]]; then
|
||||
mv -v "$TARGET_DB" "$FINAL_NAME"
|
||||
log "Final database: $FINAL_NAME"
|
||||
fi
|
||||
|
||||
@ -101,13 +101,13 @@ discover_android_device() {
|
||||
local discovery_result
|
||||
discovery_result=$(timeout 5 avahi-browse -rpt _adb-tls-connect._tcp 2> /dev/null | grep "^=" | head -1)
|
||||
|
||||
if [[ -n "$discovery_result" ]]; then
|
||||
if [[ -n $discovery_result ]]; then
|
||||
# Parse: =;eth0;IPv4;adb-...;_adb-tls-connect._tcp;local;hostname.local;192.168.x.x;port;...
|
||||
local ip port
|
||||
ip=$(echo "$discovery_result" | cut -d';' -f8)
|
||||
port=$(echo "$discovery_result" | cut -d';' -f9)
|
||||
|
||||
if [[ -n "$ip" && -n "$port" ]]; then
|
||||
if [[ -n $ip && -n $port ]]; then
|
||||
found_address="$ip:$port"
|
||||
echo "✓ Found device: $found_address" >&2
|
||||
fi
|
||||
@ -115,18 +115,18 @@ discover_android_device() {
|
||||
fi
|
||||
|
||||
# Fallback: try adb's mdns discovery
|
||||
if [[ -z "$found_address" ]]; then
|
||||
if [[ -z $found_address ]]; then
|
||||
echo "Trying adb mdns discovery..." >&2
|
||||
|
||||
# adb can discover devices via mdns
|
||||
local mdns_result
|
||||
mdns_result=$(timeout 5 adb mdns services 2> /dev/null | grep -E "adb-tls-connect|_adb\._tcp" | head -1)
|
||||
|
||||
if [[ -n "$mdns_result" ]]; then
|
||||
if [[ -n $mdns_result ]]; then
|
||||
# Try to extract IP:port from the result
|
||||
local service_name
|
||||
service_name=$(echo "$mdns_result" | awk '{print $1}')
|
||||
if [[ -n "$service_name" ]]; then
|
||||
if [[ -n $service_name ]]; then
|
||||
# Try connecting via service name
|
||||
echo "Found service: $service_name" >&2
|
||||
fi
|
||||
@ -154,7 +154,7 @@ cmd_pair() {
|
||||
read -rp "Enter pairing IP:port (e.g., 192.168.1.100:37123): " pair_address
|
||||
read -rp "Enter pairing code: " pair_code
|
||||
|
||||
if [[ -z "$pair_address" || -z "$pair_code" ]]; then
|
||||
if [[ -z $pair_address || -z $pair_code ]]; then
|
||||
die "Pairing address and code are required"
|
||||
fi
|
||||
|
||||
@ -169,7 +169,7 @@ cmd_pair() {
|
||||
echo ""
|
||||
read -rp "Enter connection IP:port (e.g., 192.168.1.100:41567): " connect_address
|
||||
|
||||
if [[ -n "$connect_address" ]]; then
|
||||
if [[ -n $connect_address ]]; then
|
||||
# Save for future connections
|
||||
mkdir -p "$(dirname "$WIRELESS_CONFIG")"
|
||||
echo "$connect_address" > "$WIRELESS_CONFIG"
|
||||
@ -190,20 +190,20 @@ cmd_connect() {
|
||||
local connect_address=""
|
||||
|
||||
# Check for saved address
|
||||
if [[ -f "$WIRELESS_CONFIG" ]]; then
|
||||
if [[ -f $WIRELESS_CONFIG ]]; then
|
||||
connect_address=$(cat "$WIRELESS_CONFIG")
|
||||
log "Using saved address: $connect_address"
|
||||
fi
|
||||
|
||||
# Try auto-discovery if no saved address
|
||||
if [[ -z "$connect_address" ]]; then
|
||||
if [[ -z $connect_address ]]; then
|
||||
echo ""
|
||||
log "Searching for Android devices on network..."
|
||||
connect_address=$(discover_android_device)
|
||||
fi
|
||||
|
||||
# Manual fallback
|
||||
if [[ -z "$connect_address" ]]; then
|
||||
if [[ -z $connect_address ]]; then
|
||||
echo ""
|
||||
echo "Auto-discovery failed. Enter address manually."
|
||||
echo "On phone: Settings > Developer Options > Wireless debugging"
|
||||
@ -211,7 +211,7 @@ cmd_connect() {
|
||||
echo ""
|
||||
read -rp "Enter connection IP:port (e.g., 192.168.1.100:41567): " connect_address
|
||||
|
||||
if [[ -z "$connect_address" ]]; then
|
||||
if [[ -z $connect_address ]]; then
|
||||
die "Connection address is required"
|
||||
fi
|
||||
fi
|
||||
@ -268,9 +268,9 @@ ensure_device_ready() {
|
||||
echo ""
|
||||
|
||||
# Check if we have a saved wireless config
|
||||
if [[ -f "$WIRELESS_CONFIG" ]]; then
|
||||
if [[ -f $WIRELESS_CONFIG ]]; then
|
||||
read -rp "Try connecting to saved wireless device? [Y/n]: " try_wireless
|
||||
if [[ "${try_wireless,,}" != "n" ]]; then
|
||||
if [[ ${try_wireless,,} != "n" ]]; then
|
||||
cmd_connect
|
||||
else
|
||||
exit 1
|
||||
@ -548,7 +548,7 @@ cmd_uninstall() {
|
||||
local status
|
||||
status=$(adb shell "su -c 'cat $GUARDIAN_DATA_DIR/control 2>/dev/null || echo ENABLED'" | tr -d '\r')
|
||||
|
||||
if [[ "$status" != "DISABLED" ]]; then
|
||||
if [[ $status != "DISABLED" ]]; then
|
||||
echo ""
|
||||
echo "⚠️ Guardian must be disabled before uninstalling!"
|
||||
echo " Run: $0 disable"
|
||||
@ -579,7 +579,7 @@ cmd_logs() {
|
||||
cmd_block_app() {
|
||||
local package="${1:-}"
|
||||
|
||||
if [[ -z "$package" ]]; then
|
||||
if [[ -z $package ]]; then
|
||||
echo "Usage: $0 block-app <package.name>"
|
||||
echo "Example: $0 block-app com.ubercab.eats"
|
||||
exit 1
|
||||
@ -606,7 +606,7 @@ cmd_block_app() {
|
||||
cmd_unblock_app() {
|
||||
local package="${1:-}"
|
||||
|
||||
if [[ -z "$package" ]]; then
|
||||
if [[ -z $package ]]; then
|
||||
echo "Usage: $0 unblock-app <package.name>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Loading…
Reference in New Issue
Block a user