[TxMt] Re: Call "Find in Project" window in a bundle command

feek feekdiv at gmail.com
Mon May 9 19:34:46 UTC 2016


Hi,

I've found a solution by using the code below. 

Regards,
Feek 

START CODE ======

#!/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"
output=''

# 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.'

END CODE ======




--
View this message in context: http://textmate.1073791.n5.nabble.com/Call-Find-in-Project-window-in-a-bundle-command-tp29977p29979.html
Sent from the textmate users mailing list archive at Nabble.com.


More information about the textmate mailing list