exic
exic

Reputation: 2668

Rename selfdefined function

Having a precmd() that does quite a lot, like checking for VCS information, I want to disable it when I'm navigating on slow mounted network drives.

I came up with the following with which I can say slow before changing to a slow drive and fast to change it back, I'm wondering if there is something easier?

precmd_slow() {
    not_much
}
precmd_fast() {
    precmd_slow
    somemore1
    somemore2
}

precmd() {
    precmd_fast
}

slow() {
    precmd() {
        precmd_slow
    }
}

fast() {
    precmd() {
        precmd_fast
    }
}

Upvotes: 3

Views: 351

Answers (1)

chepner
chepner

Reputation: 531175

In addition to the precmd function, there is also an array called precmd that contains a list of functions to call at the same time. You can manipulate it yourself, but zshcontrib has a function add-zsh-hook to simplify matters.

# precmd_slow and precmd_fast defined as before

autoload add-zsh-hook
add-zsh-hook precmd precmd_fast

fast () {
    add-zsh-hook -d precmd precmd_slow
    add-zsh-hook precmd precmd_fast
}

slow () {
    add-zsh-hook -d precmd precmd_fast
    add-zsh-hook precmd precmd_slow
}

Upvotes: 4

Related Questions