-
Notifications
You must be signed in to change notification settings - Fork 0
/
doppelganger.sh
74 lines (66 loc) · 1.44 KB
/
doppelganger.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
63
64
65
66
67
68
69
70
71
72
73
74
dgf=$HOME/.doppelganger
if [ -z "${BASH_SOURCE[0]}" ]
then
dg_location="$( cd "$( dirname "$0" )" &> /dev/null && pwd )"
else
dg_location="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
fi
dgs() {
# Save current shell settings to doppelganger file
# Get current directory
echo "cd $(pwd)" > $dgf
# Get current shell local variables and functions
if [ ! -z "${ZSH_NAME}" ]
then
# Functions doesn't exist in bash, but set dumps the functions anyway
functions >> $dgf
if [ -s "$dg_location/set_ignores" ]
then
# We grep for "=" to exclude unset things that confuse zsh
set | grep -vf "$dg_location/set_ignores" | grep = >> $dgf
else
# We grep for "=" to exclude unset things that confuse zsh
set | grep = >> $dgf
fi
else
if [ -s "$dg_location/set_ignores" ]
then
set | grep -vf "$dg_location/set_ignores" >> $dgf
else
set >> $dgf
fi
fi
# Get exported env vars
if [ -s "$dg_location/export_ignores" ]
then
export -p | grep -vf "$dg_location/export_ignores" >> $dgf
else
export -p >> $dgf
fi
}
dgl() {
# Load doppelganger file
if [ -f "$dgf" ]
then
source $dgf
if [ -z "$dg_non_interractive" ]
then
reset # Weird characters sometimes get printed, reset solves it...
echo "doppelgänger engaged"
fi
else
echo "no doppelgänger available"
fi
}
dgc() {
# Clean doppelganger file
if [ -f "$dgf" ]
then
rm $dgf
fi
}
dgu() {
# Update doppelganger
cd $dg_location
git pull
}