How to change file icon based file's extension (.txt, .cpp, .docx, etc)
(note, this appears not to work as of MacOS Big Sur v11.1 )
I was able to hack together an app that does this.
I created a repo explaining it here
You can download the app using the download button on this page
You can change the icons for existing file types. The only code I had to write for it was the following applescript:
on open this_item
    tell application &quot;Visual Studio Code&quot;
        open this_item
    end tell
end open

Setup For yourself
Open script editor (a built-in Mac app)
Choose File -&gt; Open -&gt; where ever you downloaded the app
You will then be viewing the grand total of 5 lines of code I wrote. Change &quot;Visual Studio Code&quot; to whatever app you want to be your default.
Save the file (command + s).
Move the app to your applications folder.
Find a file you want to change the icon of (lets say a text file). Click the file once (highlight it), press command + i, go to the open with section. Choose DefaultOpener from the list, then click change all.
You will probably have to reboot and toggle the show icon preview button (found in Finder's View Options) a few times for the icons to refresh and get replaced.
I have a few default icons already loaded up ( Text files, cpp files, bash/shell files, python, and about 7 others), but if you want to add your own:

Open your applications folder
Right click on DefaultOpener
Choose show package content
Then open the content folder
Then open the resources folder
Then replace whatever icon with your own icon!
(Note your replacement icon will need to be a .icns file)
Restart and toggle the show icon preview button a few times
List item

Edit: All of the sublime code referenced in an earlier answer has been fully removed from the app