Following up on the excellent answer from aantia, I note that Nathan Bailey seems to have drawn the example of the proverb cited in his 1736 dictionary from the great John Ray, A Collection of English Proverbs: Digested Into a Convenient Method for the Speedy Finding Any One upon Occasion (1670):
Wish in one hand and sh--- in the other, and see which will be full first.
There is also an early Scottish version of the saying. From James Kelly, A Complete Collection of Scotish Proverbs Explained and Made Intelligible to the English Reader (1721):
Wish in one Hand and drite in another, and see which will be first full.
In both of these expression, it appears that wish and shit/drite are acting as verbs.
Alexander Warrack, Chamber's Scots Dictionary (1911) reports that drite can function as either a verb or a noun:
Drite, v. to void excrement.—n. excrement.
However, John Jameson, Supplement to the Etymological Dictionary of the Scottish Language (1825) treats drite exclusively as a verb:
To DRITE, v. n. [that is, verb neuter, an intransitive verb; see tchrist's very helpful answer at What is the meaning and usage of the abbreviation "v. a."? ] Exonerare ventrem [that is, "to empty the stomach"]; pret. drate, dret, S.
[First cited example:] "The Earl of Moray asked the Kyng [James V of Scotland] where hys menyon Sir James [Hamilton] was, that he cam not with hym : the Kyng said he had fawttid sore to him, and shuld never have hys favor agayne : Na, said the Erle, by ——— he cannot fawt to you, thought he shuld dryte in your hands." Penman's Intercepted Letters to Sir George Douglas [circa 1536], [in] Pinkerton's [The] Hist[ory of] Scot[land Under the House of Stuart, volume] ii. [1797]
Jameson's original edition of The Etymological Dictionary of the Scottish Language (1808) contains no entry for drite (or dryte).
Bailey's gloss on the proverbial saying in Dictionarium Britannicum; Or, A More Compleat Universal Etymological English Dictionary (1736) is worth citing as well:
A homely proverb applicable to those who are ever wishing for what they have little reason to hope. We have a more decent proverb to express the same thing, viz. If Wishes were Horses, Beggars would ride.
One early instance in which the expression appears in the wild, as it were, is in "A Catalogue of Choice and Valuable Books, &c.," in A Person of Quality, Essays Serious and Comical: Viz. On the Readers of This Book (1707), which contains the following entry for a (spurious) catalogued title:
Wish in one Hand and Sh——t in t'other. Or, a Question soon resolv'd ; by the profound Astrologer Mr. Fl——d, with the Regulation of the Stars ; an Essay. By the same Author.
It also makes a discreetly partial appearance in Jonathan Swift, Tittle Tattle; Or, Taste A-la-mode: A New Farce (1749):
Col. Witling. Well! I am like the Butcher that was looking for his Knife, and he had it in his Mouth ; I have been searching my Pocket for my Snuff-Box,—and, egad, here 'tis in my Hand.
Miss Notable. Had it been a Bear, it would have bit you, Colonel:—Well, I wish I had such a Snuff-Box.—
Tom Modish. You'll be long enough before you'll wish your Skin full of Eyelet-holes.
Col. Witling. Wish in one Hand-
Miss Notable. Out upon you! Lord! what can the dirty Man mean?
The editor of The Works of Jonathan Swift, D.D., volume 6, Part 1 (1755) remarks on this exchange:
This sentence is remarkably characteristic and beautiful ; by the first it appears that miss [Notable] knew the rest, and by the latter, that in the same breath she laboured to conceal her knowledge.
The euphemistic substitution of spit for shit appears at least as early as Thomas Bridges & Francis Grose, A Burlesque Translation of Homer (1772):
I wish to god we'd both been drown'd / When first we cross'd the herring-pond; / But I may wish and make a pother. / Wish in one hand and spit in t'other / Then ev'ry leather-headed cull / Can guess which hand will first be full.