diff --git a/bin/foamFind b/bin/foamFind index 7f99600e81..8d34800810 100755 --- a/bin/foamFind +++ b/bin/foamFind @@ -37,6 +37,7 @@ Usage: ${0##*/} [OPTIONS] options: -a | -applications search for the file from the \$FOAM_APP directory -d | -dir specify search directory + -e | -edit open the file in a file editor, see below for info -f | -files find wmake 'files' file associated with searched file -h | -help help -i | -isearch searches files for a , case insensitive @@ -48,8 +49,15 @@ options: -t | -tutorials search for the file from the \$FOAM_TUTORIALS directory Finds one or more files in OpenFOAM and optionally processes the contents by: -+ printing the file ('-print' option); -+ printing lines within the file matching a search string ('-search' option). ++ printing the file(s) ('-print' option); ++ printing lines within the file matching a search string ('-search' option); ++ opening a single (only) file in a text editor ('-edit' option). + +The '-edit' option required the user to specify their choice of text editor by +setting the EDITOR environment variable. For example, to set the 'gedit' editor, +they could add to their \$HOME/.bashrc file, the line: + +export EDITOR=gedit With source code files, can locate the 'files' and 'options' files associated with their compilation using 'wmake'. @@ -102,7 +110,7 @@ findWmakeFiles () { for _w in $_wmakeFiles do _files="$(echo "$_files" \ - "$(find "$_file" -name "$_w" -type f)" | xargs)" + "$(find "$_file" -name "$_w" -type f)" | xargs)" done [ "$_files" ] && break @@ -224,29 +232,42 @@ grepFile () { dirError () { cat< /dev/null || error "No file '$filename' found in '$dir'" files="$(selectFile "$filename" "$files")" || error # With '-files' and/or '-options', reuse file variable as the file -[ "$wmakeFiles" ] && \ +{ [ "$wmakeFiles" ] || [ "$edit" ] ; } && \ [ "$(nParams "$files")" -ne 1 ] && \ - error "With '-files' or '-options', a single must be specified" + error "With '-files', '-options' or '-edit', a single file must be selected" [ "$wmakeFiles" ] && ! files="$(findWmakeFiles "$files" "$wmakeFiles")" && error @@ -378,6 +405,9 @@ do { [ "$numbers" ] && cat -n "$f" || cat "$f" ; } && \ printf "<<<\n" + # Opening files in a editor + [ "$edit" ] && "$edit" "$f" + # Printing lines matching strings [ "$search" ] || continue ! grepFile "$search" "$f" "$insensitive" test && \ diff --git a/bin/tools/foamGenerateBashCompletion b/bin/tools/foamGenerateBashCompletion index f118913733..0d0aa61d17 100755 --- a/bin/tools/foamGenerateBashCompletion +++ b/bin/tools/foamGenerateBashCompletion @@ -208,6 +208,7 @@ $(declareLocals) opts="\\ -applications \\ -dir \\ + -edit \\ -files \\ -help \\ -isearch \\ @@ -220,8 +221,8 @@ $(declareLocals) for o in \$used ; do opts="\${opts/\$o/}" ; done - # use only one of '-isearch', '-search', '-print' - local actions="-isearch -search -print" + # use only one of '-edit', '-isearch', '-search', '-print' + local actions="-edit -isearch -search -print" _optSet "\$used" "\$actions" && opts="\$(_removeOpts "\$opts" "\$actions")" # use only one of '-applications', '-dir', '-modules', '-tutorials' diff --git a/etc/config.sh/bash_completion b/etc/config.sh/bash_completion index 8992712b10..6e55b07cd8 100644 --- a/etc/config.sh/bash_completion +++ b/etc/config.sh/bash_completion @@ -4470,6 +4470,7 @@ _foamFind_ () opts="\ -applications \ -dir \ + -edit \ -files \ -help \ -isearch \ @@ -4482,8 +4483,8 @@ _foamFind_ () for o in $used ; do opts="${opts/$o/}" ; done - # use only one of '-isearch', '-search', '-print' - local actions="-isearch -search -print" + # use only one of '-edit', '-isearch', '-search', '-print' + local actions="-edit -isearch -search -print" _optSet "$used" "$actions" && opts="$(_removeOpts "$opts" "$actions")" # use only one of '-applications', '-dir', '-modules', '-tutorials'