I have been searching for conditional aliases for the last time. F.e. if you have a LDAP server and a syslog server and each of this servcies is running on physically different hosts and each of them has scripts that can be executed only from that particular host it would be good if a failure message would be run while trying to run a command from a "wrong" host. Sometimes such error messages are included in that scritps that you run, but mostly they are not.

I have found a simple solution for this usecase, initally I thought it could be resolved only with a alias and a comparisson. I found out it could be solved for zsh (maybe for bash as well) using a simple function. Refering to the upper example with LDAP and syslog where f.e. LDAP service and its scripts is running on hostname auth1 and syslog service and its scripts is running on hostname log1 following function will display a error message if trying to run aliases on wrong hosts:

# grep in syslog (host log1)
function gacl(){
        if [ $(hostname -s) == "log1" ]; then
                grep $1 /var/log/syslog.log
        else
                echo "This function works only on log1"
        fi
}

# grep in auth.log (host auth1)
function syslog(){
        if [ $(hostname -s) == "auth1" ]; then
                grep $1 /var/log/auth.log
        else
                echo "This function works only on auth1"
        fi
}

Add this both functions to .zshrc file and each time if you try to run function on wrong hosts a hint will be displayed.