Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
    }
}
share|improve this question
add comment

1 Answer

Not the prettiest solution but I would use just a simple conditional inside the precmd function checking if the current directory is mounted or not. Now doing that depends on what kind of mount it is. If the directories are known, something like this should work.

slowdirs="/home/joe/slowdir1:/home/joe/slowdir2:/mnt/slowdir3"
precmd() {
  isslow=0
  echo $slowdirs | tr \: \\n |
    while read line; do
      if [[ $PWD == $line* ]]; then
        isslow=1
        break
      fi
    done
  if [[ $isslow == 0 ]] ; then
     # do slow stuff

  fi
  # do non slow stuff

}

What this does is test if the current directory starts with (is inside), or is, one of the directories listed in the slowdirs variable. If it isn't one of the "slow" directories, runs the "slow commands", otherwise it skips them.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.