hosts/README.md

149 lines
3.4 KiB
Markdown

__ __
/ /_ ____ _____/ /______
/ __ \/ __ \/ ___/ __/ ___/
/ / / / /_/ (__ ) /_(__ )
/_/ /_/\____/____/\__/____/
# 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
```
## Usage
```text
Usage:
hosts
hosts add <ip> <hostname> [<comment>]
hosts block <hostname>
hosts disable (<ip> | <hostname> | <search string>)
hosts disabled
hosts edit
hosts enable (<ip> | <hostname> | <search string>)
hosts enabled
hosts file
hosts list [enabled | disabled | <search string>]
hosts show (<ip> | <hostname> | <search string>)
hosts search <search string>
hosts remove (<ip> | <hostname> | <search string>) [--force]
hosts unblock <hostname>
```
For full usage, run:
```text
hosts help
```
For help with a particular command, try:
```text
hosts help <command name>
```
## Commands
###### `hosts add <ip> <hostname> [<comment>]`
Add a given IP address and hostname pair, along with an optional comment.
###### `hosts remove (<ip> | <hostname> | <search string>) [--force]`
Remove one or more records based on a given IP address, hostname, or search
string. When the `--force` option is used, the confirmation prompt is
suppressed.
###### `hosts list [enabled | disabled | <search string>]`
List the existing IP / hostname pairs, optionally limited to a specified
state. When provided with a search string, all matching enabled records will
be printed.
###### `hosts show (<ip> | <hostname> | <search string>)`
Print entries matching a given IP address, hostname, or search string.
###### `hosts disable (<ip> | <hostname> | <search string>)`
Disable one or more records based on a given ip address, hostname, or
search string.
###### `hosts disabled`
List all disabled records. This is an alias for `hosts list disabled`.
###### `hosts enable (<ip> | <hostname> | <search string>)`
Enable one or more disabled records based on a given ip address, hostname,
or search string.
###### `hosts enabled`
List all enabled records. This is an alias for `hosts list enabled`.
###### `hosts edit`
Open the hosts file (/etc/hosts) file in your editor.
###### `hosts file`
Print the entire contents of the /etc/hosts file.
###### `hosts search <search string>`
Search entries for a given search string.
###### `block <hostname>`
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.
###### `unblock <hostname>`
Unblock a given hostname by removing its entries from the hosts file.
## Tests
To run the test suite, install [Bats](https://github.com/sstephenson/bats) and
run `bats test` in the project root directory.
## Acknowledgements
Based on prior work by:
- https://github.com/nddrylliog
- https://gist.github.com/nddrylliog/1368532
- https://github.com/dfeyer
- https://gist.github.com/dfeyer/1369760
Original idea and interface (since changed) via:
https://github.com/macmade/host-manager