Skip to content

Instantly share code, notes, and snippets.

@iolloyd
Last active September 7, 2016 15:23
Show Gist options
  • Save iolloyd/7ba974316ade37768ceebedf15eec72c to your computer and use it in GitHub Desktop.
Save iolloyd/7ba974316ade37768ceebedf15eec72c to your computer and use it in GitHub Desktop.
Bash / zsh key value map
#!/bin/sh
pre=$(basename $0)
# the -d flag makes a directory in place of a file
# the -t flag uses the pre variable as a template
dir=$(mktemp -dt ${pre})
getmap() {
# Make sure we have both a map name and key
[ "$#" != 2 ] && exit 1
cat "${dir}/$1/$2"
}
addmap() {
# Make sure we have a map name, a key and a value
[ "$#" != 3 ] && exit 1
[ -d "${dir}/$1" ] || mkdir "${dir}/$1"
echo $3 >"${dir}/$1/$2"
}
######
# Test
######
# addmap "testmap" "foo" "bar"
# addmap "testmap" "woo" "waah"
# echo $(getmap "testmap" "foo")
# echo $(getmap "testmap" "woo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment