Skip to content

Instantly share code, notes, and snippets.

@michaelvickersuk
Last active November 17, 2022 11:05
Show Gist options
  • Save michaelvickersuk/f90f02523405d9c6c278023147b5b720 to your computer and use it in GitHub Desktop.
Save michaelvickersuk/f90f02523405d9c6c278023147b5b720 to your computer and use it in GitHub Desktop.
Post process Universal Ctags for Laravel projects
#!/usr/bin/env bash
ctags
# Convert magic methods first character to lower case, as Universal Ctags regex doesn't support \l
perl -i -p -e 's/_FIRST_CHAR_TO_LOWER_(.)([a-z|A-Z|0-9]+)\t/\l\1\2\t/g;' tags
# Add all blade templates to the tags, amending their tag to represent the strings used with the view helper
# (remove path prefix, remove extension suffix, replace forward slash with dots).
# This requires the editor to not treat dots as word seperators, an alternative is to add "--extras=f" in ctags config
# and remove the extension suffix with "-e 's/.blade.php\tresources/\tresources/g;'"
find resources/views -type f -printf '%h/%f\t%h/%f\t1;"\tF\n' \
| perl -p \
-e 's/^resources\/views\///g;' \
-e 's/.blade.php\tresources/\tresources/g;' \
-e 's/\/(?=.*\tresources)/./g;' \
>> tags
# Place tags in ascending order to allow binary search
sort tags --output=tags
@michaelvickersuk
Copy link
Author

Previously used with Atom, gist now retained for legacy purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment