Skip to content

Commit

Permalink
Add SublimeMerge profile_helper hook (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamyGolden authored Dec 16, 2023
1 parent 5777bca commit 98078ba
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ Include `delta.gitconfig` in your Git config file i.e. `~/.gitconfig`:
> [!NOTE]
> You may need to restart your terminal/start a new shell for the changes to take effect.

#### Sublime Merge

[base16-sublime-merge] is required to be cloned or symlinked at
`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:

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

### Keeping your themes up to date

To update, just `git pull` wherever you've cloned `base16-shell`. The
Expand Down Expand Up @@ -325,3 +338,4 @@ instructions.
[12]: https://github.com/tinted-theming/base16-hexchat
[13]: https://github.com/tinted-theming/home/blob/main/styling.md
[XDG Base Directory Specification]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
[base16-sublime-merge]: https://github.com/tinted-theming/base16-sublime-merge
47 changes: 47 additions & 0 deletions hooks/base16-sublime-merge.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env fish

# ----------------------------------------------------------------------
# Setup config variables and env
# ----------------------------------------------------------------------

if test -z "$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH"
exit 1
end

if not test -f "$BASE16_SHELL_THEME_NAME_PATH"
exit 1
end

# The path/to/sublime-merge/Package must be set
if not test -d "$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH"
exit 1
end

# The base16-sublime-merge repo must be cloned at
if not test -d "$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH/base16-sublime-merge"
exit 1
end

set BASE16_SHELL_SUBLIMEMERGE_SETTINGS_PATH "$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH/User/Preferences.sublime-settings"

# The Sublime Merge settings path should exist
if not test -f "$BASE16_SHELL_SUBLIMEMERGE_SETTINGS_PATH"
exit 1
end

function find_replace_json_value_in_sublimemerge_settings
set property $argv[1]
set value $argv[2]
set 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
end

# ----------------------------------------------------------------------
# Execution
# ----------------------------------------------------------------------
set current_theme_name (cat "$BASE16_SHELL_THEME_NAME_PATH")

find_replace_json_value_in_sublimemerge_settings "theme" "base16-$current_theme_name.sublime-theme"
find_replace_json_value_in_sublimemerge_settings "color_scheme" "base16-$current_theme_name.sublime-color-scheme"
47 changes: 47 additions & 0 deletions hooks/base16-sublime-merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Setup config variables and env
# ----------------------------------------------------------------------

if [ -z "$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH" ]; then
exit 1
fi

if ! [ -f "$BASE16_SHELL_THEME_NAME_PATH" ]; then
exit 1
fi

# The path/to/sublime-merge/Package must be set
if ! [ -d "$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH" ]; then
exit 1
fi

# The base16-sublime-merge repo must be cloned at
if ! [ -d "$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH/base16-sublime-merge" ]; then
exit 1
fi

BASE16_SHELL_SUBLIMEMERGE_SETTINGS_PATH="$BASE16_SHELL_SUBLIMEMERGE_PACKAGE_PATH"/User/Preferences.sublime-settings

# The Sublime Merge settings path should exist
if ! [ -f "$BASE16_SHELL_SUBLIMEMERGE_SETTINGS_PATH" ]; then
exit 1
fi

find_replace_json_value_in_sublimemerge_settings() {
local property=$1
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
}

# ----------------------------------------------------------------------
# Execution
# ----------------------------------------------------------------------
read current_theme_name < "$BASE16_SHELL_THEME_NAME_PATH"

find_replace_json_value_in_sublimemerge_settings "theme" "base16-$current_theme_name.sublime-theme"
find_replace_json_value_in_sublimemerge_settings "color_scheme" "base16-$current_theme_name.sublime-color-scheme"

0 comments on commit 98078ba

Please sign in to comment.