Skip to content

Commit

Permalink
Filter Godot WakaTime plugin from project.godot.
Browse files Browse the repository at this point in the history
- When in the course of client projects, it becomes necessary for one
  developer to track the time spent thereof, without unnecessary
  additions to the remote repository, the aforementioned must resort to
  dire machinations that require much hackery to compel git to robustly
  ignore all such events, for all time, under all circumstances.

- Use a global git clean filter to ignore the Godot WakaTime plugin from
  project.godot for all projects globally.

- Additionally, symlink new git/git-filters/clean directory to
  ~/.git-filters/clean to provide a location for git clean filter
  scripts that can easily be specified in ~/.gitconfig using a relative
  path, without having to depend on the dotfiles project location.

Completely filter the following git diff from project.godot:

+[editor_plugins]
+
+enabled=PoolStringArray( "res://addons/wakatime/plugin.cfg" )
+

Completely Filter the following diff from project.godot:

 [editor_plugins]

-enabled=PoolStringArray( "res://addons/some-other-addon/plugin.cfg" )
+enabled=PoolStringArray( "res://addons/some-other-addon/plugin.cfg", "res://addons/wakatime/plugin.cfg" )

Partially filter the following diff in project.godot from:

 [editor_plugins]

-enabled=PoolStringArray( "res://addons/some-other-addon-1/plugin.cfg", "res://addons/wakatime/plugin.cfg" )
+enabled=PoolStringArray( "res://addons/some-other-addon-1/plugin.cfg", "res://addons/wakatime/plugin.cfg", "res://addons/some-other-addon-2/plugin.cfg" )

to:

 [editor_plugins]

-enabled=PoolStringArray( "res://addons/some-other-addon-1/plugin.cfg" )
+enabled=PoolStringArray( "res://addons/some-other-addon-1/plugin.cfg", "res://addons/some-other-addon-2/plugin.cfg" )

Partially filter the following diff in project.godot from:

 [editor_plugins]

-enabled=PoolStringArray( "res://addons/wakatime/plugin.cfg" )
+enabled=PoolStringArray( "res://addons/wakatime/plugin.cfg", "res://addons/some-other-addon-1/plugin.cfg" )

to:

+[editor_plugins]
+
+enabled=PoolStringArray( "res://addons/some-other-addon-1/plugin.cfg" )
+
  • Loading branch information
knightofiam committed Apr 25, 2023
1 parent 84bfa8d commit f5a1659
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
46 changes: 46 additions & 0 deletions git/git-filters/clean/git-filter-project-godot-wakatime-addon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# Remove the following diff from project.godot:
#
# +[editor_plugins]
# +
# +enabled=PoolStringArray( "res://addons/wakatime/plugin.cfg" )
# +

target_plugin="res://addons/wakatime/plugin.cfg"

# Read the input file content from stdin
file_content="$(cat)"

# Check if the [editor_plugins] section and the enabled=PoolStringArray line exist
section_exists=$(echo "$file_content" | ggrep -c '^\[editor_plugins\]')
pool_string_array_exists=$(echo "$file_content" | ggrep -c '^enabled=PoolStringArray')

if [[ $section_exists -gt 0 && $pool_string_array_exists -gt 0 ]]; then
# Remove the target plugin from the PoolStringArray
file_content=$(echo "$file_content" | gsed -E "s|(\"$target_plugin\", )||")

# Remove the target plugin from the PoolStringArray if it's the last item
file_content=$(echo "$file_content" | gsed -E "s|(, \"$target_plugin\")||")

# Remove trailing comma and space from the PoolStringArray if the target plugin was the last item
file_content=$(echo "$file_content" | gsed -E "s|(, )\)|\)|")

# Remove the entire enabled=PoolStringArray line and associated blank lines if the array is empty
empty_array_exists=$(echo "$file_content" | ggrep -c '^enabled=PoolStringArray\(\)$')
if [[ $empty_array_exists -gt 0 ]]; then
file_content=$(echo "$file_content" | gsed -E '/^\[editor_plugins\]/{N;N;d}')
fi

# Remove the entire [editor_plugins] section if the target plugin is the only item in the array
single_plugin_array_exists=$(echo "$file_content" | ggrep -c "^enabled=PoolStringArray( \"$target_plugin\" )\$")
if [[ $single_plugin_array_exists -gt 0 ]]; then
file_content=$(echo "$file_content" | gsed -E '/^\[editor_plugins\]/{N;N;N;d}')
fi

# Write the modified content to stdout
echo "$file_content"
else
# If the [editor_plugins] section or enabled=PoolStringArray line was not found, just output the original content
echo "$file_content"
fi
1 change: 1 addition & 0 deletions git/gitattributes_global
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project.godot filter=ignore_project_godot_wakatime_plugin
3 changes: 3 additions & 0 deletions git/gitconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[core]
editor = /usr/local/bin/vim
excludesfile = ~/.gitignore_global
attributesfile = ~/.gitattributes_global
commentchar = ";"
[commit]
gpgsign = true
Expand All @@ -27,3 +28,5 @@
sideband = false
[http]
postBuffer = 524288000
[filter "ignore_project_godot_wakatime_plugin"]
clean = ~/.git-filters/clean/git-filter-project-godot-wakatime-addon.sh
3 changes: 3 additions & 0 deletions git/gitignore_global
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ Desktop.ini
data_*/
mono_crash.*

# WakaTime addon
**/addons/wakatime

# ==========================================================================================
# End Godot section
# ==========================================================================================
Expand Down
1 change: 1 addition & 0 deletions install-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ source bash_profile
./duti.sh
./dock.sh
./gpg.sh
./git.sh
./iterm2.sh
./mvim.sh
./repos.sh
Expand Down
2 changes: 2 additions & 0 deletions symlinks
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ config
duti
git/gitconfig
git/gitignore_global
git/gitattributes_global
git/git-filters
ideavimrc
mackup.cfg
pandora
Expand Down

0 comments on commit f5a1659

Please sign in to comment.