mirror of
https://github.com/octoleo/hosts.git
synced 2024-05-30 05:00:48 +00:00
Add disable
and enable
commands
These commands make it possible to disable records without fully removing them. To 'disable' a record, it simply is commented out with the following pattern `#disabled: ` prepended to the line.
This commit is contained in:
parent
124520efc4
commit
9de0edda07
|
@ -9,6 +9,8 @@ A command line program with shortcuts for managing hosts file entries.
|
||||||
hosts remove <hostname>
|
hosts remove <hostname>
|
||||||
hosts list [<search string>]
|
hosts list [<search string>]
|
||||||
hosts show ( <ip> | <hostname> | <search string> )
|
hosts show ( <ip> | <hostname> | <search string> )
|
||||||
|
hosts disable ( <ip> | <hostname> | <search term> )
|
||||||
|
hosts enable ( <ip> | <hostname> | <search term> )
|
||||||
hosts edit
|
hosts edit
|
||||||
hosts file
|
hosts file
|
||||||
|
|
||||||
|
|
49
hosts
49
hosts
|
@ -660,6 +660,30 @@ add() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------- disable
|
||||||
|
|
||||||
|
desc disable <<EOM
|
||||||
|
Usage:
|
||||||
|
$_me disable (<ip>|<hostname>|<search term>)
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Disable one or more records based on a given ip address, hostname, or
|
||||||
|
search term.
|
||||||
|
EOM
|
||||||
|
disable() {
|
||||||
|
local search_term=$1
|
||||||
|
if [[ -z "${search_term}" ]]; then
|
||||||
|
$_me help disable
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
|
||||||
|
targets=$(sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" /etc/hosts)
|
||||||
|
printf "Disabling:\n%s\n" "${targets}"
|
||||||
|
|
||||||
|
sed -i "s/^\([^#]*${search_term}.*\)$/\#disabled: \1/g" /etc/hosts
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------ edit
|
# ------------------------------------------------------------------------ edit
|
||||||
|
|
||||||
desc edit <<EOM
|
desc edit <<EOM
|
||||||
|
@ -677,6 +701,31 @@ edit() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------- enable
|
||||||
|
|
||||||
|
desc enable <<EOM
|
||||||
|
Usage:
|
||||||
|
$_me enable (<ip>|<hostname>|<search term>)
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Enable one or more disabled records based on a given ip address, hostname,
|
||||||
|
or search term.
|
||||||
|
EOM
|
||||||
|
enable() {
|
||||||
|
local search_term=$1
|
||||||
|
if [[ -z "${search_term}" ]]; then
|
||||||
|
$_me help enable
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
target_regex="s/^\#disabled: \(.*${search_term}.*\)$/\1/"
|
||||||
|
|
||||||
|
targets=$(sed -n "${target_regex}p" /etc/hosts)
|
||||||
|
printf "Enabling:\n%s\n" "${targets}"
|
||||||
|
|
||||||
|
sed -i "${target_regex}g" /etc/hosts
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------ file
|
# ------------------------------------------------------------------------ file
|
||||||
|
|
||||||
desc file <<EOM
|
desc file <<EOM
|
||||||
|
|
Loading…
Reference in New Issue
Block a user