You are right that foot fungus is most commonly acquired through sharing personal items with someone else who has the infection, such as shoes, socks or towels. It is also commonly acquired through using public spaces like gym shower rooms. However, unfortunately, the fungi that cause foot fungus infections such as athletes foot and nail infections are actually found everywhere in the environment, including the soil. Therefore, even if you avoid locations like common shower stalls, it is still possible to pick up the infection.
Fortunately, if all you have is athlete's foot, which is a fungal infection of the skin of the foot characterized by redness, itching, cracking, and odor, this is almost always easily treated with good skin hygiene and an over the counter anti fungal cream.
If on the other hand, the infection is in your toe nails, you will need to see your primary care doctor
for help. The fungus lives very deep in the nail and therefore topical creams will not work. With nail infections, it is almost always necessary to use a more powerful oral anti fungal medication, which will require a prescription.
Please talk to your primary care doctor for more specific advice!