How to cache a variable used inside a Bash Completion Script for the current session -


Inside my bass full file, I'm looking at full-wire with an external script, which takes a while (1-2 seconds). Since this string mostly runs for the rest of the current time, so I want to cache them and when the next time triggered the trigger to complete the bash, it should use the cache string rather than the expensive lookup, so that it can be completed immediately When it runs for the second time.

To feel about the complete file, here is an important part of the whole file:

  getdeployablefiles () {# how to present the time of the shell Can I cache the result of 'PBT Milling Affordable Fils'? Echo 'PBT getdeployablefiles`} in PBT & amp; _pbt_complete () {local cur goals COMPREPLY = () cur = $ {COMP_WORDS [COMP_CWORD}} target = $ (getdeployablefiles) COMPREPLEY = ($ (compgen -W "$ {targets}" - $ cur)) 0; & Amp; Full-F _pbt_complete pbt   

How can I cache the output of getdeployablefiles for the remaining shell session? I need some type of global variable, or some other move

Solution:

just make target non-local Ask for more about whether this is set. Last script:

  getdeployablefiles () {echo 'PBT getdeployablefiles`} is PBT & amp; _pbt_complete () {local process if [-z "$ _pbt_complete_goals"]; So _pbt_complete_goals = $ (getdeployablefiles) fi _pbt_complete_goals = $ (getdeployablefiles) COMPREPLY = () CUR = $ {COMP_WORDS [COMP_CWORD]} COMPREPLY = ($ (compgen W "$ {_ pbt_complete_goals}" - $ CUR)) return 0} & Amp; & Amp; Full F _pbt_complete PBT    

Why do not you leave the target out local statement and rename it to something with a low probability of name conflict, _pbt_complete_goals perhaps? Then you can see if it is zero or set and can set it to check if necessary.

Comments