I setup an ad hoc network between my computer and a pi for a project which works perfectly but when I have the ad-hoc on I have no access to the internet on the pi. There are times I am going to need internet to download code so I will have to switch it off so that I can connect to Wi-Fi. I could write a python script to manually edit the interfaces file each time I want to toggle it but I'm thinking there is a better way. Does anyone know a command of some type I can use to toggle on and off ad-hoc when I want?
As noted in a comment You also agree with a permanent uplink connection to an internet router. For this you can use the unused eth0 interface or an additional USB/WiFi dongle. With the latter you can use the onboard WiFi device for a protected uplink and the dongle for a RSN protected ad hoc connection if supported. You are always free to use an unprotected connection. Look at How to setup an unprotected Ad Hoc (IBSS) Network and if possible with WPA encryption? and use section ♦ Setup ad-hoc interface with additional USB/WiFi dongle for uplink to internet router.