aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ves-create.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/ves-create.sh b/ves-create.sh
index 1a24852..4b4cc0a 100644
--- a/ves-create.sh
+++ b/ves-create.sh
@@ -1 +1,63 @@
#!/bin/sh
+
+OVERRIDE_VARS="PATH LDPATH"
+
+if [ -z $XDG_DATA_HOME ]; then
+ ENV_DIR="$HOME/.local/share/ves/envs"
+else
+ ENV_DIR="$XDG_DATA_HOME/ves/envs"
+fi
+
+check_name() {
+ if [ -f "$ENV_DIR/$1" ]; then
+ printf "ERROR: Environment [%s] already exists.\n" $1 > /dev/stderr
+ exit 1
+ fi
+
+ if ! echo $1 | grep "^[[:alpha:][:digit:]_-]*$" > /dev/null; then
+ printf "ERROR: Environment [%s] is invalid. Name must contain only letters, -, and _\n" $1 > /dev/stderr
+ exit 1
+ fi
+}
+
+
+create_env() {
+ FILE="$ENV_DIR/$1"
+ printf "name: $1\n" > $FILE
+
+ if [ "$OVERRIDE" -eq "1" ]; then
+ for VAR in $OVERRIDE_VARS; do
+ printf "export_var:%s=%s\n" $VAR '""' >> $FILE
+ done
+ fi
+}
+
+OVERRIDE=0
+while :; do
+ case $1 in
+ --override)
+ OVERRIDE=1
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -?*)
+ printf "ERROR: Invalid option [%s]\n" $1 > /dev/stderr
+ exit 2
+ ;;
+ *)
+ break
+ esac
+ shift
+done
+ENV_NAME="$1"
+
+echo $ENV_NAME
+echo $OVERRIDE
+
+check_name "$1"
+create_env "$1" "$OVERRIDE"
+
+printf "Environment [%s] created successfully\n" $ENV_NAME
+printf "To activate, execute\nves activate %s\n" $ENV_NAME