This document provides context, patterns, and guidelines for AI coding assistants working in this repository.
This project contains useful scripts that automate some personal and general Linux tasks via Python and Bash/Shell.
- Languages: Python 3.x and POSIX shell / Bash
- Purpose: Collection of small utilities and automation scripts for Linux system tasks
- Python: 3.12+ with type hints
- BASH: POSIX shell / Bash scripts for automation tasks
- Linting: ruff (linter + formatter) for python files
- Type Checking: mypy
- Testing: pytest, bats
install.sh
containers/
docs/
src
├── audio # Audio-related scripts
│ ├── mediaplayer.py
│ ├── mediaplayer.sh
│ ├── sink-change.sh
│ └── volume-control.sh
├── automation # General automation scripts
│ ├── add-missing-i18n-variables.js
│ ├── add-xml-missing-variables.py
│ ├── copy-repos-to-vm.sh
├── backup # Backup-related scripts
│ ├── borg-backup
│ │ ├── home-borgbackup.sh
│ ├── rsync-desktop-to-laptop.sh
│ └── rsync-laptop-to-desktop.sh
├── containers # Container-related scripts and configurations
│ ├── autopenguinsetup_container
│ │ ├── Dockerfile.arch
│ │ ├── Dockerfile.fedora
│ │ ├── manage.sh
│ │ ├── podman-compose.yml
├── display # Display configuration scripts
│ ├── laptop-xrandr.sh
├── games # Game-related scripts
│ └── fs_mod_move.sh
├── general # General utility scripts
│ ├── remove-html-tag.py
│ ├── sha512_sum.sh
├── github # GitHub-related scripts and data
│ ├── changelog.sh
│ ├── data
│ │ ├── AGENTS_bash.md
│ │ ├── AGENTS_python.md
│ │ ├── pyproject.toml
├── hardware # Hardware-related scripts
│ ├── bluetooth-menu.sh
├── network # Network-related scripts
│ ├── network_test.sh
│ └── wakeonlan.wol
├── package-management # Package management scripts for various distros
│ ├── arch-package-manager.sh
│ ├── fedora-package-manager.sh
├── power # Power management and related scripts
│ ├── brightness-control.sh
│ ├── check_battery.sh
│ ├── idle.sh
│ ├── power-menu.sh
│ ├── swaylock.sh
│ └── swaylock_sleep.sh
├── system # System information and maintenance scripts
│ ├── info
│ │ ├── cpu_mem_info.sh
│ ├── maintenance
│ │ └── gc_cache.sh
│ └── setup-tty.sh
├── web-scrapping # Web scraping scripts
│ └── scrap.py
└── website # Personal website-related scripts and configurations
└── stow.sh
- Clone the repository:
git clone https://github.com/cyber-syntax/linux-system-utils.git - Install dependencies: Ensure Python 3.12+ is installed. Use
uvto start python scripts. - Deploy scripts: Run
./install.shto install scripts to XDG base directories (e.g.,~/.local/share/linux-system-utils). - Environment setup: No additional environment variables required beyond standard XDG paths.
- Edit scripts in the
src/directory. - For Python scripts: Use
uv runfor commands like linting, type checking, and testing. - For Bash scripts: Use
shellcheckfor linting andshfmtfor formatting. - No development server needed; scripts are standalone utilities.
- After changes, redeploy using
./install.sh --forceto update installed scripts.
- Function Size: Keep functions small and focused (<20 lines when possible)
- KISS: Keep it simple, stupid. Aim for simplicity and clarity. Avoid unnecessary abstractions or metaprogramming.
- DRY Approach:
- Reuse existing abstractions; don't duplicate
- Refactor safely when duplication is found
- Check existing protocols before creating new ones
- Type Annotations: Always use built-in generic types instead of
typingequivalents:- Use
list[str]notList[str](from typing) - Use
X | NonenotOptional[X](from typing) - Only import from
typingwhen absolutely necessary (e.g.,Any,Unionfor complex cases)
- Use
- PEP 8: Enforced by ruff
- Datetime: Use
astimezone()for local time conversions - Variable Names: Use descriptive, self-explanatory names
- Functions: Use functions over classes when state management is not needed
- Pure Functions: Prefer pure functions without side effects when possible
- Prefer plain bash constructs and avoid unnecessary complexity.
- Use built-in bash features where appropriate, but avoid overusing them.
- Build: No build process required; scripts are interpreted directly.
- Deployment: Use
./install.shto deploy to user directories. Options include--mainfor installing from main branch,--forceto overwrite,--binaryto install select scripts globally to~/.local/bin. - CI/CD: No automated pipelines defined; manual testing and deployment.
CRITICAL: Always run ruff on modified python files before committing.
# 1. Make your changes to files in src/
# 2. Run linting (auto-fix issues)
ruff check --fix path/to/file.py
ruff check --fix . # or all Python files
# 3. Run formatting
ruff format path/to/file.py
ruff format . # or all Python files
# 4. Run type checking
uv run mypy src/
# 5. Run fast tests
uv run pytest /path/to/file.py# Format a file (in-place)
shfmt -w setup.sh
# Format all shell scripts
find . -name "*.sh" -type f -exec shfmt -w {} \;
# Format options used in this project:
# -i 2 : indent with 2 spaces
# -ci : indent switch cases
# -bn : binary ops like && and | may start a line
shfmt -i 2 -ci -bn -w setup.shtests/
├── py/ # Python tests
├── sh/ # Shell/Bash tests
├── custom/ # Custom tests (e.g., GitHub Action CI test, line count test)
CRITICAL: Every new feature or bugfix MUST be covered by unit tests.
# Example test structure
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
from my_unicorn.core.services import InstallWorkflow
from my_unicorn.exceptions import VerificationError
@pytest.mark.asyncio
async def test_install_workflow_success(tmp_path, mock_session):
"""Test successful installation workflow."""
# Arrange
workflow = InstallWorkflow(...)
# Act
result = await workflow.execute()
# Assert
assert result.success is True
assert result.app_name == "test-app"
def test_hash_verification_failure():
"""Test that verification fails with incorrect hash."""
# Arrange
expected_hash = "abc123"
actual_hash = "def456"
# Act & Assert
with pytest.raises(VerificationError):
verify_hash(actual_hash, expected_hash)#!/usr/bin/env bats
@test "addition using bc" {
result="$(echo 2+2 | bc)"
[ "$result" -eq 4 ]
}
@test "addition using dc" {
result="$(echo 2 2+p | dc)"
[ "$result" -eq 4 ]
}# Run fast tests only (excludes slow logger integration tests)
uv run pytest -m "not slow"
# Run all tests (including slow tests)
uv run pytest
# Run tests with coverage
uv run pytest --cov=my_unicorn --cov-report=html
# Run specific test file
uv run pytest tests/test_install.py
# Run specific test function
uv run pytest tests/test_install.py::test_install_success
# Run shell tests with bats
bats tests/sh/
# Run specific shell test file
bats tests/sh/test_network.sh
# Run subdirectory recursively via bats
bats -r tests/sh/network/Before committing, verify:
- Tests fail when your new logic is broken
- Happy path is covered
- Edge cases and error conditions are tested
- External dependencies are mocked (no real network calls in unit tests)
- Tests are deterministic (no flaky tests)
- Test names clearly describe what they test
# Problem: Ruff errors that can't be auto-fixed
# Solution: Review ruff output and fix manually
ruff check path/to/file.py
# Problem: Type checking errors
# Solution: Run mypy with verbose output
uv run mypy --show-error-codes src/my_unicorn/
# Problem: Shellcheck errors in bash scripts
# Solution: Run shellcheck and fix manually
shellcheck path/to/script.sh
# Common type error fixes:
# - Update type hints to match actual usage
# - Check for missing return type annotations
# - Ensure correct use of built-in types (list[str], dict[str, int], etc.)