I'm using an improved version of the on() function in my .mrconfig,
which handles usernames, etc. Maybe you'd like to include it in the
defaults for mr, so people don't have to reinvent the wheel. Here it is:
# Checks whether the given host basename is one of the listed
# values. A value can also have a username in it, ie
"joey@dodo".
on() {
for host in $@; do
# Handle username specfication.
if [ "${host%@*}" != "${host#*@}" ]; then
if [ "$whoami" != "${host%@*}" ];
then
continue
fi
# Now strip username from host
variable.
host="${host#*@}"
fi
# Check hostname
if [ "$shorthostname" = "$host" -o
"$fullhostname" = "$host" -o \
"$domainname" = "$host" ]; then
return 0
fi
done
return 1
}
Christian Hudon wrote: None of these variables seem to be defined in your patch.
Le 2014-9-28 13:04, Joey Hess a écrit :
Doh! This should be the full thing.
# 'Handy 'on' alias.
whoami="$(whoami)"
shorthostname="$(hostname -s)"
fullhostname="$(hostname -f)"
domainname="${fullhostname#*.}"
# Checks whether the given host basename is one of the
listed
# values. A value can also have a username in it, ie
"joey@dodo".
on() {
for host in $@; do
# Handle username specfication.
if [ "${host%@*}" != "${host#*@}" ]; then
if [ "$whoami" != "${host%@*}"
]; then
continue
fi
# Now strip username from host
variable.
host="${host#*@}"
fi
# Check hostname
if [ "$shorthostname" = "$host" -o
"$fullhostname" = "$host" -o \
"$domainname" = "$host" ]; then
return 0
fi
done
return 1
}
Christian Hudon wrote: These commands would run every time myrepos is run, even if `on` is not used. I think it would probably be better to put the function in a lib/ file.
Le 2014-9-28 14:47, Joey Hess a écrit : That was a not a problem for me, because in my .mrconfig file, the on() function is run every time. But good point in general. Anyways, I guess the initial version of this on() function in this bug report was more of a "Would you potentially be interested in this?" thing. If you are interested and give me a list of things to fix, I have no problems reworking this function to fix them. Let me know. Christian
Christian Hudon wrote: I am definitely interested -- perhaps it would make sense for it to get and cache the hostname values only when on() is used. It also needs to be documented.