-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
hosts_export is fairly inefficient:
hosts_export() {
local grep_args=(-v -e '^#' -e '^$')
# Exclude all enabled hosts from the output.
IFS=$'\n' read -d '' -r -a enabled < "${ENABLED_HOSTS}"
for i in "${enabled[@]}"; do
grep_args+=(-e " ${i}")
done;
# Exclude all disabled hosts from the output to prevent duplicates.
IFS=$'\n' read -d '' -r -a disabled < "${DISABLED_HOSTS}"
for i in "${disabled[@]}"; do
grep_args+=(-e "^${i}$")
done;
remote="$(grep "${grep_args[@]}" "${REMOTE_HOSTS}")"
# Concatenate the users hosts file, disabled hosts, and the remote hosts
# stripped of any enabled hosts.
hosts="$(cat "${USER_HOSTS}" "${DISABLED_HOSTS}")"
echo "${hosts}"$'\n'"${remote}"
}This could be reduced in complexity with a single grep command piped to uniq.
Metadata
Metadata
Assignees
Labels
No labels