Skip to content

Instantly share code, notes, and snippets.

@p-b-west
Last active September 5, 2016 02:44
Show Gist options
  • Save p-b-west/006b3fc72809ae8fe6f9eec7dc8683d9 to your computer and use it in GitHub Desktop.
Save p-b-west/006b3fc72809ae8fe6f9eec7dc8683d9 to your computer and use it in GitHub Desktop.
Generate bash env-var assignments from clojurescript project.clj :dependencies
#! /bin/bash
function upcase() {
echo "$1" | tr 'a-z' 'A-Z'
}
DEPS=$(sed -e '
/^[ \i]*:dependencies *\[/!d
/^[ \i]*:dependencies *\[/ {
s///
: continue
s/^[ \i]*//
n
/\]\]/s//]/
t finish
b continue
: finish
s/^[ \i]*//
q
}
')
DEPS=$(echo "$DEPS" | \
sed -e '
/\[[^/]*\/\([^ ]*\) *\("[^"]*"\).*\]/ {
s//\1_VER=\2/
: dots
s/\.\(.*=\)/_\1/
t dots
: hyphens
s/-\(.*=\)/_\1/
t hyphens
}
')
DEPS=$(echo "$DEPS" | \
while read line
do
var=$(expr "$line" : '\(.*\)=')
val=$(expr "$line" : '.*\(=.*\)')
uvar=$(upcase "$var")
echo "$uvar$val"
done
)
echo "$DEPS"
@p-b-west
Copy link
Author

p-b-west commented Sep 4, 2016

Written to generate bash environment variables corresponding to the :dependencies from the clojurescript project.clj file.
The scripts for building and testing clojurescript have the version numbers of dependencies defined in more than one place. This script provides definitions for version numbers that are derived from a single source - the project.clj file.

The script assumes that the elements of :dependencies vectors are separated by spaces only, and that there is only one set of :dependencies in the file. It depends on bash, sed and tr. sed is the wildcard. It is tested on OS X with the system sed and with MacPorts gsed, and on Ubuntu 16.04, but would benefit from testing with whatever other versions may be encountered in the wild.

Run the script this way:
$ cat project.clj | proj-deps
The bash assignments are written to stdout.

To set up the env-vars, do:
$ eval $(cat project.clj | proj-deps)

If it's found to be reliable, it can be used to set up vars in individual script directory files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment