-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_assigncmd
More file actions
executable file
·74 lines (64 loc) · 1.67 KB
/
bash_assigncmd
File metadata and controls
executable file
·74 lines (64 loc) · 1.67 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
if [ -e ~/.bash_assigned_vars ]
then
source ~/.bash_assigned_vars
fi
assign()
{
VarName=$1
Path=$2
if [ "$VarName" == "" ]
then
# list all assign's
echo "Assigned var's:"
if [ -e ~/.bash_assigned_vars ]
then
sed "s/^export set \"\(.*\)\"=\(.*$\)/ \1=\2/" <~/.bash_assigned_vars
fi
# Reload all assigned vars
source ~/.bash_assigned_vars
return
fi
if [ "$VarName" == "--help" ]
then
echo "Usage:"
echo "assign [OPTIONS] var [path]"
echo ""
echo "Options:"
echo " -d -- Delete assignment"
return
fi
# Convert this into a delete command
if [ "$Path" == "" ]
then
Path=$VarName
VarName="-d"
fi
if [ "$VarName" == "-d" ]
then
if [ "$Path" == "" ]
then
echo "Missing arg"
return
fi
# Remove this assign from the permanent list
if [ -e ~/.bash_assigned_vars ]
then
sed "/^export set \"$Path\"/d" <~/.bash_assigned_vars >~/.bash_assigned_vars_tmp
mv ~/.bash_assigned_vars_tmp ~/.bash_assigned_vars
fi
unset "$Path"
return
fi
# Take this path and make it an abs path
UsePath=$(readlink -f "$Path")
# Remove the old one (if any)
if [ -e ~/.bash_assigned_vars ]
then
sed "/^export set \"$VarName\"/d" <~/.bash_assigned_vars >~/.bash_assigned_vars_tmp
mv ~/.bash_assigned_vars_tmp ~/.bash_assigned_vars
fi
# Add the new one
echo >>~/.bash_assigned_vars "export set \"$VarName\"=$UsePath"
export set "$VarName"=$UsePath
}