Skip to content

Instantly share code, notes, and snippets.

@simonc
Created December 1, 2025 09:16
Show Gist options
  • Select an option

  • Save simonc/57c5e22190552644421ecb010ffcda6f to your computer and use it in GitHub Desktop.

Select an option

Save simonc/57c5e22190552644421ecb010ffcda6f to your computer and use it in GitHub Desktop.
Update default editor for all code files
#!/bin/bash
# Set default editor for code file extensions using duti
# Usage: ./duti.sh [bundle_id]
# Default bundle_id is com.microsoft.VSCode
EDITOR_BUNDLE_ID="${1:-com.microsoft.VSCode}"
# Common code file extensions
extensions=(
# Shell/Scripts
sh bash zsh fish
# Web
html htm css scss sass less
js mjs cjs jsx ts tsx
json jsonc json5
xml xsl xslt
yaml yml
toml
# Programming languages
c h cpp hpp cc cxx hxx
cs
go
java
kt kts
py pyw
rb
rs
swift
php
pl pm
lua
r
scala
clj cljs cljc edn
ex exs
erl hrl
hs lhs
ml mli
fs fsi fsx
nim
zig
v
d
dart
groovy
julia jl
# Config/Data
ini cfg conf config
env
properties
csv tsv
sql
# Documentation/Markup
md markdown
rst
txt
tex
# DevOps/Infra
dockerfile
tf tfvars
hcl
vagrantfile
# Other
log
diff patch
gitignore gitattributes gitconfig
editorconfig
prettierrc eslintrc
makefile
cmake
gradle
pom
gemfile rakefile
podfile
lock
)
for ext in "${extensions[@]}"; do
duti -s "$EDITOR_BUNDLE_ID" ".$ext" all 2>/dev/null
done
echo "Set $EDITOR_BUNDLE_ID as default editor for ${#extensions[@]} file extensions"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment