Sha256: c344edd817a5246f64c0203a121e9a028296f060cda830bfb212eb1c4b04a689
Contents?: true
Size: 721 Bytes
Versions: 12
Compression:
Stored size: 721 Bytes
Contents
# aia/lib/aia/dynamic_content.rb require 'erb' module AIA::DynamicContent # inserts environment variables (envars) and dynamic content into a prompt # replaces patterns like $HOME and ${HOME} with the value of ENV['HOME'] # replaces patterns like $(shell command) with the output of the shell command # def render_env(a_string) a_string.gsub(/\$(\w+|\{\w+\})/) do |match| ENV[match.tr('$', '').tr('{}', '')] end.gsub(/\$\((.*?)\)/) do |match| `#{match[2..-2]}`.chomp end end # Need to use instance variables in assignments # to maintain binding from one follow up prompt # to another. def render_erb(the_prompt_text) ERB.new(the_prompt_text).result(binding) end end
Version data entries
12 entries across 12 versions & 1 rubygems