Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: lookup for a function inside project directory #71

Open
feekApp opened this issue May 9, 2016 · 0 comments
Open

Suggestion: lookup for a function inside project directory #71

feekApp opened this issue May 9, 2016 · 0 comments

Comments

@feekApp
Copy link

feekApp commented May 9, 2016

Hi,
herewith a bash script in order to lookup for a function definition inside a project folder.
Using this script you can directly jump to a function!
Regards,
Feek

#!/bin/bash
[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"

function_name="$TM_CURRENT_WORD"
project_dir="$TM_PROJECT_DIRECTORY"

# find php-related files in project directory, result is a string
files_string=`find "$project_dir" -type f | egrep '\.(module|inc|php|engine|install)$'`

# place multi-line sting in a array, works for file names with spaces!
files_array=()
while read -r line; do
   files_array+=("$line")
done <<< "$files_string"

#
# Lookup for a function declaration inside the file content.
# multi space allowed in function declaration
# <file> <function>
#
function lookup_function {
  local line=`nl -b a "$1" | grep 'function\\s\+'"$2"'\\s*(' | awk '{print $1}'`
  if [[ "$line" -gt 0 ]]; then
    mate "$1" -l "$line"
    exit 0
  fi
}

# Iterate the array with files, works for files with spaces!
for (( i=0; i < ${#files_array[*]}; i++)); do
  file="${files_array[${i}]}"
  lookup_function "$file" "$function_name"
done

# Nothing found
echo 'NOTE: Function '${function_name}' was not found within the current project directory.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant