No description
Find a file
Kumi 214c95dbad
All checks were successful
Python Package CI/CD / Publish to PyPI (push) Successful in 37s
feat: enhance hosts file generation
Refactored the hosts file generation logic to improve its functionality and readability. Introduced a more robust file reading system that recursively reads all text files in a given directory, excluding ones starting with a period, ending with `.disabled`, or containing the `HOSTSD IGNORE` marker. This enhancement helps in accommodating a broader range of file organizations and simplifying the exclusion of specific files from the hosts file generation process. Additionally, updated the version to 0.1.1 to mark this incremental improvement.

- Improved file reading by handling nested directories and providing options to ignore certain files.
- Added capability to prefix file paths in the generated content, enhancing traceability of file origins.
- Streamlined error handling for non-text files and introduced informative skip messages for ignored files or binary content.
2024-05-30 08:36:52 +02:00
.forgejo/workflows feat: Initialize hostsd project with PyPI CI/CD 2024-05-02 14:49:06 +02:00
src/hostsd feat: enhance hosts file generation 2024-05-30 08:36:52 +02:00
.gitignore feat: Initialize hostsd project with PyPI CI/CD 2024-05-02 14:49:06 +02:00
LICENSE feat: Initialize hostsd project with PyPI CI/CD 2024-05-02 14:49:06 +02:00
pyproject.toml feat: enhance hosts file generation 2024-05-30 08:36:52 +02:00
README.md fix: correct query parameter in Git Workflow badge URL 2024-05-03 13:37:19 +02:00

hostsd - A simple hosts file manager

Support Private.coffee! PyPI PyPI - Python Version PyPI - License Latest Git Commit

hostsd is a simple hosts file manager that allows you to separate your hosts file into multiple files and easily enable or disable them. It's useful for development environments where you need to manage lots of hosts entries, or for managing ad-blocking hosts files.

Dependencies

  • Python 3.8 or later (earlier versions may work but are untested)
  • Linux or macOS (should work on Windows too but is untested)

Installation

pip install hostsd

Usage

To write the contents of /etc/hosts.d/* to /etc/hosts:

sudo hostsd

You can also specify the input and output paths:

hostsd -i /etc/hosts.d -o /etc/hosts

You can disable a file by adding a .disabled extension:

mv /etc/hosts.d/10-my-file /etc/hosts.d/10-my-file.disabled

Hidden files (files starting with a dot) are ignored as well.

Running hostsd automatically

You can run hostsd automatically using a cron job or a systemd timer. Here's an example of a systemd timer (assuming you have installed hostsd globally, for simplicity):

# /etc/systemd/system/hostsd.timer
[Unit]
Description=Update hosts file every minute

[Timer]
OnBootSec=1min
OnUnitActiveSec=1min

[Install]
WantedBy=timers.target
# /etc/systemd/system/hostsd.service
[Unit]
Description=Update hosts file

[Service]
Type=oneshot
ExecStart=/usr/bin/hostsd
sudo systemctl enable hostsd.timer
sudo systemctl start hostsd.timer

This will run hostsd every minute. So you can just drop a new file in /etc/hosts.d and it will be picked up automatically.

You could even combine this with a git repository and you have a simple way to manage your hosts files across multiple machines or share them with others, without needing to set up and manage a full DNS server.

License

hostsd is licensed under the MIT license. See LICENSE for the full license text.