-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstore.sh
62 lines (62 loc) · 1.33 KB
/
store.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
## store
## version 0.1.0 - add list command
#################################################
shopt -s expand_aliases
alias init-store='
{
test ! -f ~/$( basename ${0} .sh )-store && {
touch ${_}
} || {
source ${_}
cecho green "loading store ..."
sleep 1
cecho green "done loading store"
}
}
{
declare -p store 2>/dev/null || {
cecho green "initializing store ..."
declare -A store
store initialize
cecho green "done initializing store"
}
}
'
alias init-store-silent='
{
init-store
} &>/dev/null
'
store-initialize() {
store["run"]=0
declare -p store &>/dev/null
}
store-persist() {
store[run]=$(( store[run] + 1 ))
declare -p store | tee "${store_file}" &>/dev/null
}
store-set() { { local key ; key="${1}" ; local value ; value="${@:2}" ; }
store[${key}]=${value}
}
store-get() { { local key ; key="${1}" ; }
echo "${store[${key}]}"
}
store-list() {
local key
# shellcheck disable=SC2154
for key in "${!store[@]}"
do
echo "${key}: ${store[${key}]}"
done
}
store() {
local store_file
store_file=~/$( basename ${0} .sh )-store
commands
}
##################################################
## generated by create-stub2.sh v0.1.2
## on Tue, 01 Oct 2019 15:13:44 +0900
## see <https://github.com/temptemp3/sh2>
##################################################