Sha256: 8a2101531eb3063fd9e3bc29fdb9c25d5aec44f864fa76203ec016ae8c648328

Contents?: true

Size: 830 Bytes

Versions: 4

Compression:

Stored size: 830 Bytes

Contents

#!/usr/bin/env bash

if [[ -f "$1" ]] ; then
  database_file="$1" ; shift
  if [[ ! -f "$database_file" ]] ; then
    mkdir -p $(dirname $database_file)
    touch $database_file
  fi
else
  echo "Database file $1 does not exist." >&2
  exit 1
fi

key="$1" ; shift
if [[ -z "$key" ]] ; then
  echo "usage: $0 database key [value]" >&2
  exit 1
else
  value="$*"
  if [[ "unset" = "$value" ]] || [[ "delete" = "$value" ]] ; then
    sed -i.tmp "s#^$key=.*\$##" $database_file
  else
    if [[ -z "$value" ]] ; then # get
      awk -F= '/^'"$key"'=/{print $2}' $database_file
    else # set
      if [[ -z "$(awk -F= "/^'"$key"'=/{print $2}" $database_file)" ]] ; then # append
        echo "$key=$value" >> $database_file
      else # overwrite
        sed -i.tmp "s#^$key=.*\$#$key=$value#" $database_file
      fi
    fi
  fi
fi

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rvm-0.1.32 scripts/db
rvm-0.1.31 scripts/db
rvm-0.1.30 scripts/db
rvm-0.1.29 scripts/db