Skip to content

Commit

Permalink
Add sublime-merge hook support for MacOS (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamyGolden authored Jan 14, 2024
1 parent 9ed4181 commit 1010453
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,29 @@ Include `delta.gitconfig` in your Git config file i.e. `~/.gitconfig`:
`path/to/sublimemerge/Packages/base16-sublime-merge`.

The Sublime Merge package path must be added to your shell `.*rc` file.
You find find this value by opening `Sublime Merge -> Preferences ->
Browse Packages...`. Add this directory path to your shell `.*rc` file:
You find find this value in Linux by opening `Sublime Merge ->
Preferences -> Browse Packages...` or on MacOS with `Sublime Merge ->
Settings... -> Browse Packages...`. Add this directory path to your
shell `.*rc` file:

```shell
export BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH="path/to/sublime-merge/Packages"
```

Make sure
`$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH/User/Preferences.sublime-settings`
exists and contains the `theme` and `color_scheme` json properties. If
they don't exist, make sure the file contains them:

```json
{
"theme": "Merge Dark.sublime-theme",
"color_scheme": "Merge Dark.sublime-color-scheme"
}
```
This is necessary because the hook finds those properties and replaces
the values.

### Keeping your themes up to date

To update, just `git pull` wherever you've cloned `base16-shell`. The
Expand Down
19 changes: 17 additions & 2 deletions hooks/base16-sublime-merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,23 @@ find_replace_json_value_in_sublimemerge_settings() {
local value=$2
local json_file="$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH"/User/Preferences.sublime-settings

# Use sed to find the property and change its value
sed -i "s/\"$property\": \".*\"/\"$property\": \"$value\"/" $BASE16_SHELL_SUBLIMEMERGE_SETTINGS_PATH
# Determine the operating system
OS="$(uname)"

# Define the sed command based on the operating system
case "$OS" in
Darwin|FreeBSD)
# macOS system (BSD sed)
SED_COMMAND=(sed -i '')
;;
*)
# Assume Linux or other (GNU sed)
SED_COMMAND=(sed -i)
;;
esac

# Use the determined sed command in your script
"${SED_COMMAND[@]}" "s/\"$property\": \".*\"/\"$property\": \"$value\"/" "$BASE16_SHELL_SUBLIMEMERGE_SETTINGS_PATH"
}

# ----------------------------------------------------------------------
Expand Down

0 comments on commit 1010453

Please sign in to comment.