Skip to content

Instantly share code, notes, and snippets.

@benok
Last active November 28, 2024 10:11
Show Gist options
  • Save benok/3d5df30e74220d43d99a126c89e5724d to your computer and use it in GitHub Desktop.
Save benok/3d5df30e74220d43d99a126c89e5724d to your computer and use it in GitHub Desktop.
Install GitBash profile to Windows Terminal
#!/bin/sh
# Install GitBash profile to Windows Terminal
# (requires jq. (or sudo from latest Win11 & chocolatey))
set -eu
SET_AS_DEFAULT_PROFILE=1 # set as default profile
COPY_ON_SELECT=1 # enable copy on select
# check jq & install if not exists
if ! [ -x "$(command -v jq)" ]; then # https://stackoverflow.com/a/26759734/26736
echo "jq is required. installing jq..."
sudo choco install jq
fi
WTCONF_DIR=~/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState
SETTINGS_JSON=$WTCONF_DIR/settings.json
# check setting file exists
if ! [ -f "$SETTINGS_JSON" ]; then
echo "Settings file of Windows Terminal is missing."
exit 1
fi
# check already git bash is installed
cat $SETTINGS_JSON |
jq .profiles.list[].guid |
grep "{561d72a1-8e47-42de-be21-414fc9d790ee}">/dev/null &&
{ echo "GitBash already installed."; exit 0; }
# Add git bash profile to Windows Terminal
jq '.profiles.list += [{
"commandline": "C:\\Program Files\\Git\\bin\\bash.exe",
"guid": "{561d72a1-8e47-42de-be21-414fc9d790ee}",
"hidden": false,
"icon": "C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico",
"name": "Git Bash",
"startingDirectory": "%USERPROFILE%"
}]' $SETTINGS_JSON > tmp.json # https://stackoverflow.com/a/42257772/26736
if [ "$SET_AS_DEFAULT_PROFILE" = 1 ]; then
jq '.defaultProfile="{561d72a1-8e47-42de-be21-414fc9d790ee}"' tmp.json > tmp2.json &&
mv tmp2.json tmp.json
fi
if [ "$COPY_ON_SELECT" = 1 ]; then
jq '.copyOnSelect=true' tmp.json > tmp2.json &&
mv tmp2.json tmp.json
fi
# install modified setting.json
mv $SETTINGS_JSON ${SETTINGS_JSON}.bk
mv tmp.json ${SETTINGS_JSON}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment