Here are a few techniques that I use, in various circumstances. To do all these things, I rely heavily on using a mirror, in which I am a firm believer.
The basic principals are first that you don't want to tempt a driver to make that too-close pass (whether out of ignorance or intent), and second, that the only way you can influence a driver's behavior is to communicate somehow..
Situation 1: enough shoulder for plenty of safe clearance if the car stays in the center of the lane. Technique: ride just far enough to the right so there will be safe clearance. I'm watching (glancing) in the mirror, and if a car seems to be cutting it too close, I communicate, either by hand gesture (push left hand out as if pushing the car away) or by "wobbling" to the left a little, so the driver thinks I might move over unexpectedly. If either of those moves gets the desired response (they usually do), I hold my line. If the driver still stays too far right, my position gives me some slack, and I move to the right just before they overtake.
Situation 2. Inadequate shoulder, so that there's not enough room for a safe pass unless the driver moves at least partly into the other lane. Safe pass distance IMO pretty well matches state law here (Ct) which mandates 3 feet clearance. In that situation, I take the center of the lane, forcing a car to move over if they want to pass. I'm watching, so if some totally oblivious bozo were about to hit me, I should have room to bail out to the right (and I try always to be aware of the conditions on the right). Sometimes I get the angry honk. If the left lane is clear, so they could pass safely by moving over, I wave them around. If the other lane has traffic, or it's a blind curve or hill, I put out the "don't pass" signal (left arm out with hand facing back). As soon as there's a good spot for passing, I try to wave them around.
If a driver in this second situation moves over but still tries to pass too close (some roar by a foot away to show their displeasure at my usurpation of their road), my position in the center of the lane gives me the ability to create clearance, by moving right just before they overtake. Again, the mirror is very helpful so I know exactly how close they are.
Sometimes the driver I force to move over will yell at me about riding to the right. I try (not always successfully) not to lose my cool, and to explain as calmly as possible that the lane was too narrow for a safe or legal pass without moving over, and that I wasn't trying to hold them up, but to ride safely for everyone.
I try to be reasonable and allow drivers to pass whenever it's safe. That includes not only the wave-arounds mentioned above, but pulling over at stop signs to let cars go by (sometimes a string of them).
The toughest situations are narrow country roads with inadequate shoulder, but speeds high enough to make taking the lane unreasonable. I try to pick routes that minimize time on such roads, but when I have to, it takes extra vigilance. I generally ride a little further left than I could (which may mean on or even a little to the left of the white line), with the mirror allowing me to take advantage of the bit of extra room on the right to create clearance when somebody looks like they're going to cut it close.
Like you, I hate having them buzz by a foot from my elbow.
Hope this is helpful.