-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.addvar~evo
executable file
·57 lines (44 loc) · 1.79 KB
/
.addvar~evo
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
#!/bin/zsh
QTS="\""
KEEP=false
startsWithDash "${1}" && [[ ${1//-/} = 's' ]] && QTS="'" && shift
startsWithDash "${1}" && [[ ${1//-/} = 'a' ]] && QTS="" && shift
startsWithDash "${1}" && [[ ${1//-/} = 'k' ]] && KEEP=true && shift
#[[ ${SHLVL} -gt 1 ]] && [[ -r ~/bin/.functions ]] && source ~/bin/.functions
SCRIPTNAME="$(basename $0)"
CURR_SHELL_VARS="${SHELL_VARS}"
startsWithDash ${1} && ([[ ${1/-/} = 't' ]] || [[ ${1/-/} = '-target' ]]) && [[ -w "${2}" ]] && CURR_SHELL_VARS="${2}" && source ${CURR_SHELL_VARS} && shift 2
# add alias like
# alias addvar='source addvar'
#[[ ${SHLVL} -eq 1 ]] && [[ -z $(alias ${SCRIPTNAME}) ]] && addalias ${SCRIPTNAME} "source ${SCRIPTNAME}" && update-aliases
alias-exists -a ${SCRIPTNAME}
_addvar() {
SZ_EXPORT='export '
if [ $# -eq 0 ] # || [ $# -lt 2 ]
then
echo "$# is $((2-$#)) too few"
echo "Usage: ${SCRIPTNAME} name [value]"
echo "addalias ${SCRIPTNAME} 'source ${SCRIPTNAME}'"
return 1
else
PNAME="${1//-/_}"
PNAME=$(uppercase ${PNAME})
PVALUE="${2:-$(pbpaste)}"
[[ $# -eq 1 ]] && startsWith $PVALUE '"' && endsWith $PVALUE '"' && PVALUE=${PVALUE[2,-2]}
! string_contains $PVALUE "(" && ! startsWith $PVALUE '"' && ! endsWith $PVALUE '"' && PVALUE=${PVALUE// /\\ }
fi
LASTCHAR=${PNAME[$#PNAME]}
[[ "$LASTCHAR" = "+" ]] && SZ_EXPORT=''
if ${KEEP}
then
echo "${SZ_EXPORT}${PNAME}=${QTS}${PVALUE}${QTS}" >> $CURR_SHELL_VARS
else
echo "${SZ_EXPORT}${PNAME}=${QTS}${PVALUE//\\/}${QTS}" >> $CURR_SHELL_VARS
fi
ARR_SHA512=($(sha512sum "${CURR_SHELL_VARS}"))
PATH2SHA512="${TMPDIR}/$(filename ${CURR_SHELL_VARS//\./})"
echo ${ARR_SHA512[1]} > ${PATH2SHA512}
# source $CURR_SHELL_VARS
}
_addvar ${@}
# source $CURR_SHELL_VARS