-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenv
More file actions
executable file
·46 lines (39 loc) · 784 Bytes
/
benv
File metadata and controls
executable file
·46 lines (39 loc) · 784 Bytes
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
#!/bin/bash
command=$1
key=$2
value=$3
bash_file="$HOME/.bashrc"
function get(){
printenv $key
}
function search(){
query=$key
printenv | grep $query
}
function set(){
export $key=$value
update $key
echo "Run the following line"
echo "---------------------------------------"
echo "> source $bash_file"
echo "---------------------------------------"
echo "To update the changes made."
}
function del(){
old=$(cat $bash_file | grep "export $key")
$(sed -i .benv.backup "/$old/d" $bash_file)
}
function update(){
variable=$1
old=$(cat $bash_file | grep "export $variable")
new="export $variable="$(printenv $variable)
if [ "$old" ]; then
$(sed -i .benv.backup "s/$old/$new/g" $bash_file)
else
echo $new >> $bash_file
fi
}
function main(){
$command
}
main