Skip to content

Centralized Configuration System for MLH #28

@melihcelenk

Description

@melihcelenk

Issue: Centralized Configuration System for MLH

Title

Implement centralized configuration system (mlh.conf) for all plugins

Labels

enhancement, configuration, refactoring

Description

Problem

Currently, each plugin has its own configuration approach:

  • bookmark-alias.conf exists only for bookmark alias configuration
  • Future plugins will need their own config files
  • No standardized configuration pattern across the project

Proposal

Create a unified configuration system using a single mlh.conf file in ~/.mylinuxhelper/ that all plugins can read.

Benefits

  1. Single source of truth: All MLH configuration in one place
  2. User-friendly: Users only need to edit one file
  3. Maintainable: Easier to document and support
  4. Extensible: Easy to add new configuration options
  5. Consistent: All plugins use the same config reading pattern

Proposed Structure

File location: ~/.mylinuxhelper/mlh.conf

Format (Bash-sourceable):

# MyLinuxHelper Configuration
# This file is sourced by MLH scripts to read configuration

# === Bookmark Configuration ===
# Alias/shortcut for bookmark command (default: none)
# Valid values: alphanumeric and underscore only (e.g., bm, b, fav)
BOOKMARK_ALIAS="bm"

# === History Configuration ===
# Maximum number of history entries to display (default: 1000)
HISTORY_MAX_ENTRIES=1000

# === Docker Configuration ===
# Default container image (default: ubuntu:22.04)
DOCKER_DEFAULT_IMAGE="ubuntu:22.04"

# === Future configurations ===
# More options can be added here as new features are developed

Implementation Plan

Phase 1: Create Config Infrastructure

  1. Create mlh.conf.example in repository root with documented examples
  2. Update .gitignore to exclude ~/.mylinuxhelper/mlh.conf (user-specific)
  3. Create helper function in install.sh or a new lib/config.sh:
    # Load MLH configuration
    load_mlh_config() {
        local config_file="${HOME}/.mylinuxhelper/mlh.conf"
        if [ -f "$config_file" ]; then
            # shellcheck source=/dev/null
            source "$config_file" 2>/dev/null || true
        fi
    }

Phase 2: Migrate Existing Configs

  1. Update mlh-bookmark.sh to use mlh.conf instead of bookmark-alias.conf
  2. Add backward compatibility: check both files, prefer new format
  3. Update setup.sh to:
    • Read from mlh.conf
    • Generate mlh.conf from mlh.conf.example on first setup
    • Show migration notice if old config files exist

Phase 3: Documentation

  1. Update docs/CONFIGURATION.md (new file) with:
    • All available configuration options
    • Default values
    • Examples for common use cases
  2. Update README.md to reference configuration guide
  3. Update CLAUDE.md with config system architecture

Phase 4: Testing

  1. Add tests for config loading (tests/test-mlh-config.sh)
  2. Test backward compatibility with old config files
  3. Test config validation (invalid values, syntax errors)

Migration Path

For existing users with bookmark-alias.conf:

Option A: Automatic migration in setup.sh

# If old config exists and new doesn't
if [ -f "$HOME/.mylinuxhelper/bookmark-alias.conf" ] && [ ! -f "$HOME/.mylinuxhelper/mlh.conf" ]; then
    echo "Migrating bookmark-alias.conf to mlh.conf..."
    # Read old config and create new one
fi

Option B: Show warning and instructions

if [ -f "$HOME/.mylinuxhelper/bookmark-alias.conf" ]; then
    echo "⚠️  Notice: bookmark-alias.conf is deprecated"
    echo "   Please migrate to mlh.conf (see docs/CONFIGURATION.md)"
fi

Recommendation: Option A (automatic migration) for better UX

File Organization

Before:

~/.mylinuxhelper/
├── bookmarks.json
├── bookmark-alias.conf      # Plugin-specific
├── .update-config           # Another config format
└── .history-timestamp       # Yet another format

After:

~/.mylinuxhelper/
├── bookmarks.json           # Data (JSON)
├── mlh.conf                 # Unified config (Bash-sourceable)
├── .update-config           # Internal state (keep separate)
└── .history-timestamp       # Internal state (keep separate)

Note: Internal state files (.update-config, .history-timestamp) are automatically managed and should remain separate from user-editable config.

Security Considerations

  1. Config file validation: Add basic validation for critical settings
  2. Sourcing safety: Use set -u to catch undefined variables
  3. Permissions: Ensure config file is user-readable only (chmod 600)
  4. Injection prevention: Don't eval arbitrary code, only source config

Alternative Considered

INI-style config (e.g., using crudini or custom parser):

[bookmark]
alias = bm

[history]
max_entries = 1000

Rejected because:

  • Requires additional parsing logic or dependencies
  • Bash-sourceable format is simpler and native to shell scripts
  • Most system config files in Linux use shell-sourceable format (e.g., /etc/default/*)

Breaking Changes

None if backward compatibility is implemented. Old config files will continue to work.

Example Config File

See attached: mlh.conf.example

# MyLinuxHelper Configuration
# Location: ~/.mylinuxhelper/mlh.conf
# 
# This file is sourced by MLH scripts to read user preferences.
# Edit values below and run './setup.sh' to apply changes.

# ============================================================================
# BOOKMARK CONFIGURATION
# ============================================================================

# Bookmark command alias (shortcut)
# Set this to create a shorter command alias (e.g., 'bm' instead of 'bookmark')
# Valid values: alphanumeric and underscore only [a-zA-Z0-9_]
# Examples: bm, b, fav, goto, marks
# Default: "" (no alias)
BOOKMARK_ALIAS="bm"

# ============================================================================
# HISTORY CONFIGURATION (Future)
# ============================================================================

# Maximum number of history entries to display
# Default: 1000
# HISTORY_MAX_ENTRIES=1000

# Show timestamps in history output
# Default: true
# HISTORY_SHOW_TIMESTAMPS=true

# ============================================================================
# DOCKER CONFIGURATION (Future)
# ============================================================================

# Default container image for 'linux' command
# Default: ubuntu:22.04
# DOCKER_DEFAULT_IMAGE="ubuntu:22.04"

# Mount current directory in containers
# Default: true
# DOCKER_MOUNT_CWD=true

Success Criteria

  1. Single mlh.conf file works for all current and future plugins
  2. Backward compatibility maintained (old configs still work)
  3. Documentation is clear and comprehensive
  4. Tests cover config loading and validation
  5. User experience improved (one config file, clear structure)

Timeline Estimate

  • Phase 1 (Infrastructure): 2-3 hours
  • Phase 2 (Migration): 2-3 hours
  • Phase 3 (Documentation): 1-2 hours
  • Phase 4 (Testing): 1-2 hours
  • Total: 6-10 hours

Dependencies

None. This is a standalone enhancement.

References

  • Current implementation: bookmark-alias.conf.example
  • Similar systems: systemd environment files, /etc/default/* configs

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status
Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions