Skip to content

Commit

Permalink
Added support for conditional var assignments.
Browse files Browse the repository at this point in the history
FOO?="BAR" will only assign "BAR" to $FOO if the $FOO variable is empty.
  • Loading branch information
Scott Gonyea committed Jun 24, 2012
1 parent 7c046cf commit 9a4c1de
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bin/rbenv-vars
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ find-rbenv-vars-files() {

sanitize-vars() {
sed \
-e "/^[ "$'\t'"]*[A-Za-z_][0-9A-Za-z_]*=/ !d" \
-e "/^[ "$'\t'"]*[A-Za-z_][0-9A-Za-z_]*?\{0,1\}=/ !d" \
-e "s/'/'\\\\''/g" \
-e "s/\(\\\\\\\$\)/'\\1'/g" \
-e "s/\\\\\\\\/\\\\/g" \
-e "s/\(\\\$[0-9A-Za-z_][0-9A-Za-z_]*\)/'\\1'/g" \
-e "s/\(\\\${[0-9A-Za-z_][0-9A-Za-z_]*}\)/'\\1'/g" \
-e "s/^[ "$'\t'"]*\([A-Za-z_][0-9A-Za-z_]*\)=\(.*\)$/export \\1='\\2'/"
-e "s/^[ "$'\t'"]*\([A-Za-z_][0-9A-Za-z_]*?\{0,1\}\)=\(.*\)$/export \\1='\\2'/" \
-e "s/export \([A-Za-z_][0-9A-Za-z_]*\)?=/[[ -z \"\$\\1\" ]] \\&\\& export \\1=/g"
}

while read file; do
Expand Down

0 comments on commit 9a4c1de

Please sign in to comment.