Skip to content

Instantly share code, notes, and snippets.

@evansolomon
Created September 1, 2012 09:53
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evansolomon/3568555 to your computer and use it in GitHub Desktop.
Save evansolomon/3568555 to your computer and use it in GitHub Desktop.
Bash helpers for navigating WordPress code
# Alias ST2's command line tool for a shorter (easier-to-remember) name
alias st="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
# Search for an open Sublime Text to a function definition
function fx() {
ack "function &?$1\(" | awk {'print $1'} | sed 's/:$//g' | xargs st
}
# Example usage from the root of a WordPress repository
# fx wp_remote_get
# Automatically opens wp-includes/http.php to line 74 in Sublime Text 2
# If the function is defined multiple times (e.g. methods of classes) it will open all of the files
# ...but only the last one will be on the correct line
# Wildcard function search
function fxf() {
ack "function &?\S*$1\S*\("
}
#Example: fxf strip_
# Returns a list of function definitions containing the string
# Search for and open WordPress hooks
function action() {
ack "do_action(_ref_array)?\(\s*('|\")$1('|\")" | awk {'print $1'} | sed 's/:$//g' | xargs st
}
function filter() {
ack "apply_filters(_ref_array)?\(\s*('|\")$1('|\")" | awk {'print $1'} | sed 's/:$//g' | xargs st
}
# Example usage from the root of a WordPress repository
# action init
# Automatically opens wp-settings.php to line 305 in Sublime Text 2
# If the hook is fired multiple times (e.g. the_content) it will open all of the files
# ...but only the last one will be on the correct line
# filter map_meta_cap
# Automatically opens wp-includes/capabilities.php to line 1247 in Sublime Text 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment