mirror of
https://github.com/octoleo/hosts.git
synced 2024-11-22 04:45:11 +00:00
[TASK] Add list mode
This commit is contained in:
parent
d1edb3dd30
commit
ff7f431bd7
19
host-manager
Normal file → Executable file
19
host-manager
Normal file → Executable file
@ -2,10 +2,11 @@
|
||||
# Idea and interface taken from https://github.com/macmade/host-manager
|
||||
|
||||
path="/etc/hosts"
|
||||
addusage="Usage: `basename $0` -add host address"
|
||||
remusage="Usage: `basename $0` -remove host"
|
||||
addusage="Usage: `basename $0` --add host address"
|
||||
remusage="Usage: `basename $0` --remove host"
|
||||
listusage="Usage: `basename $0` --list [127.]"
|
||||
case "$1" in
|
||||
-add)
|
||||
--add)
|
||||
if [ $# -eq 3 ]; then
|
||||
if [[ -n $(grep "^$3.*[^A-Za-z0-9\.]$2$" ${path}) ]]; then
|
||||
echo "Duplicate address/host combination, ${path} unchanged."
|
||||
@ -16,14 +17,22 @@ case "$1" in
|
||||
echo $addusage;
|
||||
fi
|
||||
;;
|
||||
-remove)
|
||||
--remove)
|
||||
if [ $# -eq 2 ]; then
|
||||
sed -i '' -e "s/^[^#].*[^A-Za-z0-9\.]$2$//g" -e "/^$/ d" ${path}
|
||||
sed -i '' "s/^[^#].*[^A-Za-z0-9\.]$2$//g;/^$/d" ${path}
|
||||
else
|
||||
echo $remusage;
|
||||
fi
|
||||
;;
|
||||
--list)
|
||||
if [ $# -eq 2 ]; then
|
||||
grep "^$2" ${path}
|
||||
else
|
||||
cat ${path} | grep -v "^#"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo $addusage;
|
||||
echo $remusage;
|
||||
echo $listusage;
|
||||
esac
|
Loading…
Reference in New Issue
Block a user