> I do something similar via a shell
> echo "masterpassword gmail" | md5
Please do not do this, md5 is not a cryptographic hash and is relatively trivial to reverse. Ie; is possible for someone to discover your 'masterpassword' given any one of your passwords generated via this method.
If one of your passwords is leaked then it is possible for an attacker to brute-force this to find out a list of possible 'masterpassword foo' combinations (although not knowing the length increases the search space).
If one of those foos is 'gmail' for your gmail password then it is game over.
Even if your foo is not similar to the service, if the attacker is able to get 2 of your passwords then the search-space is much smaller (looking only at the overlap of the reverse of both md5 functions).
This may not be relevant if you only take a 'random' sub-sequence from the generated md5, thus only disclosing part of the hash to the attacker.