stuff
This commit is contained in:
parent
9a2284b481
commit
2f73bbf945
5 changed files with 240 additions and 61 deletions
28
zsh/files/hosts.zsh
Normal file
28
zsh/files/hosts.zsh
Normal file
|
@ -0,0 +1,28 @@
|
|||
removehost() {
|
||||
hostname="$1"
|
||||
|
||||
if grep -qP "[[:space:]]$hostname" /etc/hosts; then
|
||||
echo "$hostname found in /etc/hosts. Removing now..."
|
||||
sudo sed -ie "/[[:space:]]$hostname/d" /etc/hosts || echo "cannot remove host from /etc/hosts" >&2
|
||||
else
|
||||
echo "$hostname was not found in /etc/hosts" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
addhost() {
|
||||
hostname="$1"
|
||||
|
||||
if grep -qP "[[:space:]]$hostname" /etc/hosts; then
|
||||
echo "$hostname already exists: $(grep "$hostname" /etc/hosts)" >&2
|
||||
else
|
||||
echo "Adding $hostname to /etc/hosts..."
|
||||
printf "%s\t%s\n" "127.0.0.1" "$hostname" | sudo tee -a /etc/hosts > /dev/null || echo "cannot add host to /etc/hosts" >&2
|
||||
|
||||
if grep -q "$hostname" /etc/hosts; then
|
||||
echo "$hostname was added succesfully:"
|
||||
grep "$hostname" /etc/hosts
|
||||
else
|
||||
echo "Failed to add $hostname" >&2
|
||||
fi
|
||||
fi
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue