Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
howto:collapsing_functions [2010/04/21 04:36]
127.0.0.1 external edit
howto:collapsing_functions [2015/08/08 20:26] (current)
bill_thomson
Line 34: Line 34:
  
 ===== How does it work? ===== ===== How does it work? =====
-The first time you run chatter(), the function redefines itself based on the value of verbose. Thereafter chatter doesn'​t check $verbose ​anymore, it simply is. Further calls to the function reflect its collapsed nature. If verbose is unset, chatter will echo nothing, with no extra effort from the developer.+The first time you run chatter(), the function redefines itself based on the value of verbose. Thereafterchatter doesn'​t check $verbose, it simply is. Further calls to the function reflect its collapsed nature. If verbose is unset, chatter will echo nothing, with no extra effort from the developer.
 ===== More examples ===== ===== More examples =====
 FIXME Add more examples! FIXME Add more examples!
Line 49: Line 49:
   elif [[ $(command find "​$0"​ -perm /u+x 2> /dev/null) ]]; then   elif [[ $(command find "​$0"​ -perm /u+x 2> /dev/null) ]]; then
     find() {     find() {
-      ​command find "${@//-executable/-perm \/u+x}"+      ​typeset arg args 
 +      for arg do 
 +        [[ $arg = -executable ​]] && args+=(-perm /u+x) || args+=("​$arg"​) 
 +      done 
 +      command find "​${args[@]}"
     }     }
   elif [[ $(command find "​$0"​ -perm +u+x 2> /dev/null) ]]; then   elif [[ $(command find "​$0"​ -perm +u+x 2> /dev/null) ]]; then
     find() {     find() {
-      ​command find "${@//-executable/-perm +u+x}"+      ​typeset arg args 
 +      for arg do 
 +        [[ $arg = -executable ​]] && args+=(-perm +u+x) || args+=("​$arg"​) 
 +      done 
 +      command find "​${args[@]}"
     }     }
   else # Last resort   else # Last resort
     find() {     find() {
-      ​command find "${@//-executable/-exec test -x '{}' ​\; -print}"​+      ​typeset arg args 
 +      for arg do 
 +        [[ $arg = -executable ​]] && args+=(-exec test -x {} \; -print) || args+=("​$arg"​) 
 +      done 
 +      command find "​${args[@]}"
     }     }
   fi   fi
Line 71: Line 83:
  
  
-# From now on if you use $dbg instead of echo you can select if messages will be shown+# From now on if you use $dbg instead of echoyou can select if messages will be shown
  
 $dbg "This message will only be displayed if --debug is specified at the command line $dbg "This message will only be displayed if --debug is specified at the command line
  
 </​code>​ </​code>​
  • howto/collapsing_functions.1271824580.txt
  • Last modified: 2015/07/20 17:16
  • (external edit)