Change file association in terminal?
You can edit ~/Library/Preferences/com.apple.LaunchServices.plist (~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist on Catalina) in a text editor after converting it to XML:
plutil -convert xml1 ~/Library/Preferences/com.apple.LaunchServices.plist
# Catalina: 
plutil -convert xml1 ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist -o output.xml

Then add entries like this to the LSHandlers array:
&lt;dict&gt;
  &lt;key&gt;LSHandlerContentType&lt;/key&gt;
  &lt;string&gt;com.adobe.pdf&lt;/string&gt;
  &lt;key&gt;LSHandlerRoleAll&lt;/key&gt;
  &lt;string&gt;net.sourceforge.skim-app.skim&lt;/string&gt;
&lt;/dict&gt;
&lt;dict&gt;
  &lt;key&gt;LSHandlerContentTag&lt;/key&gt;
  &lt;string&gt;mkv&lt;/string&gt;
  &lt;key&gt;LSHandlerContentTagClass&lt;/key&gt;
  &lt;string&gt;public.filename-extension&lt;/string&gt;
  &lt;key&gt;LSHandlerRoleAll&lt;/key&gt;
  &lt;string&gt;org.videolan.vlc&lt;/string&gt;
&lt;/dict&gt;

You can use mdls to see the UTIs of file types and something like osascript -e 'id of app &quot;AppName&quot;' to see the bundle identifiers of applications.
You can apply changes to com.apple.LaunchServices.plist by restarting. Logging out and back in isn't enough.


NOTE: duti is no longer in active development and has been labeled by its maintainers as &quot;unsupported&quot;. The project hasn't seen any major progress since 2012 aside from configuration updates. It has moved from Sourceforge to Github. This answer has been updated to include the new links.

I also use duti though. I have saved a file like this (with about 100 lines) as ~/.duti:
org.gnu.Emacs public.plain-text all # .txt, .text, plain text files without an extension
org.gnu.Emacs public.unix-executable all # executable scripts
com.SequentialX.Sequential .jpg all
org.videolan.vlc .mkv all

I have a launchd agent that runs duti ~/.duti automatically when ~/.duti is changed.
You can normally use filename extensions (like .jpg) instead of a UTIs (like public.jpg) to specify file types. duti converts the extensions to UTIs that also apply to other extensions (like .jpeg). For some extensions like .mkv and .tex, the UTI depends on what application registered the extension first.
The latest version of duti only includes source code, but 1.5.0 also includes an installer.