__ __ / /_ ____ _____/ /______ / __ \/ __ \/ ___/ __/ ___/ / / / / /_/ (__ ) /_(__ ) /_/ /_/\____/____/\__/____/ # Hosts A command line program for managing hosts file entries. ## Installation ### Homebrew To install with [Homebrew](http://brew.sh/): ```bash brew tap alphabetum/taps && brew install alphabetum/taps/hosts ``` ### bpkg To install with [bpkg](http://www.bpkg.io/): ```bash bpkg install alphabetum/hosts ``` ### Manual To install manually, simply add the `hosts` script to your `$PATH`. If you already have a `~/bin` directory, you can use the following command: ```bash curl -L https://raw.github.com/alphabetum/hosts/master/hosts \ -o ~/bin/hosts && chmod +x ~/bin/hosts ``` A package for Arch users is also [available in the AUR](https://aur.archlinux.org/packages/hosts/). ## Usage ```text Usage: hosts [] hosts add [] hosts block hosts disable ( | | ) hosts disabled hosts edit hosts enable ( | | ) hosts enabled hosts file hosts list [enabled | disabled | ] hosts search hosts show ( | | ) hosts remove ( | | ) [--force] hosts unblock hosts --auto-sudo hosts -h | --help hosts --version Options: --auto-sudo Run write commands with `sudo` automatically. -h --help Display this help information. --version Display version information. Help: hosts help [] ``` For full usage, run: ```text hosts help ``` For help with a particular command, try: ```text hosts help ``` ## Commands ### `hosts` ```text Usage: hosts [] Description: List the existing IP / hostname pairs, optionally limited to a specified state. When provided with a seach string, all matching enabled records will be printed. Alias for `hosts list` ``` ### `hosts add` ```text Usage: hosts add [] Description: Add a given IP address and hostname pair, along with an optional comment. ``` ### `hosts block` ```text Usage: hosts block Description: Block a given hostname by adding new entries assigning it to `127.0.0.1` for IPv4 and both `fe80::1%lo0` and `::1` for IPv6. ``` #### Blocklists - [jmdugan/blocklists](https://github.com/jmdugan/blocklists) - [notracking/hosts-blocklists](https://github.com/notracking/hosts-blocklists) ### `hosts commands` ```text Usage: hosts commands [--raw] Options: --raw Display the command list without formatting. Description: Display the list of available commands. ``` ### `hosts disable` ```text Usage: hosts disable ( | | ) Description: Disable one or more records based on a given ip address, hostname, or search string. ``` ### `hosts disabled` ```text Usage: hosts disabled Description: List all disabled records. This is an alias for `hosts list disabled`. ``` ### `hosts edit` ```text Usage: hosts edit Description: Open the /etc/hosts file in your $EDITOR. ``` ### `hosts enable` ```text Usage: hosts enable ( | | ) Description: Enable one or more disabled records based on a given ip address, hostname, or search string. ``` ### `hosts enabled` ```text Usage: hosts enabled Description: List all enabled records. This is an alias for `hosts list enabled`. ``` ### `hosts file` ```text Usage: hosts file Description: Print the entire contents of the /etc/hosts file. ``` ### `hosts help` ```text Usage: hosts help [] Description: Display help information for hosts or a specified command. ``` ### `hosts list` ```text Usage: hosts list [enabled | disabled | ] Description: List the existing IP / hostname pairs, optionally limited to a specified state. When provided with a seach string, all matching enabled records will be printed. ``` ### `hosts remove` ```text Usage: hosts remove ( | | ) [--force] hosts remove Options: --force Skip the confirmation prompt. Description: Remove one or more records based on a given IP address, hostname, or search string. If an IP and hostname are both provided, only records matching the IP and hostname pair will be removed. ``` ### `hosts search` ```text Usage: hosts search Description: Search entries for . ``` ### `hosts show` ```text Usage: hosts show ( | | ) Description: Print entries matching a given IP address, hostname, or search string. ``` ### `hosts unblock` ```text Usage: hosts unblock Description: Unblock a given hostname by removing its entries from the hosts file. ``` ### `hosts version` ```text Usage: hosts (version | --version) Description: Display the current program version. ``` ## Options ### `--auto-sudo` When specified, all write operations that require `sudo` will automatically rerun the command using `sudo` when the current user does not have write permissions for the hosts file. To have this option always enabled, add the following line to your shell configuration (`.bashrc`, `.zshrc`, or similar): ```bash alias hosts="hosts --auto-sudo" ``` ### `-h` `--help` Display help information. ### `--version` Display version information. ## Tests To run the test suite, install [Bats](https://github.com/sstephenson/bats) and run `bats test` in the project root directory. ## Acknowledgements - https://gist.github.com/nddrylliog/1368532 - https://gist.github.com/dfeyer/1369760 - https://github.com/macmade/host-manager