-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigbash.sh
More file actions
executable file
·66 lines (55 loc) · 2.02 KB
/
configbash.sh
File metadata and controls
executable file
·66 lines (55 loc) · 2.02 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
#!/bin/bash
TARGETFILE=$HOME/.bashrc
# create file if not exist
[ ! -f $TARGETFILE ] && touch $TARGETFILE || echo "$TARGETFILE Found"
# read data from the file
while read -r configline ; do
#trim line
line="${configline##*( )}"
line="${configline%%*( )}"
# skip empty lines
[ -z "$configline" ] && continue
# skip comments
[[ ${configline:0:1} == "#" ]] && continue
# now we search the config file
if grep -q "$configline" $TARGETFILE ; then
echo "Settings [$configline] already exist. Skip."
else
# we need to check if the settings already have different value
if [[ $configline == "export *" ]]; then
# this is variable string in the config, pars the variable
VAR=${confitline#export} # remove word export
VAR=${VAR%%=*} # remove everything after
if [ -z "${!VAR}" ]; then
#VAR is unset, add to the file
echo $configline >> $TARGETFILE
else
echo "$VAR is set to '${!VAR}', would you like to add '$configline' (n to skip)?";
read yn
if [ $yn == "n" ]; then
continue
else
echo $configline >> $TARGETFILEi
fi
fi
else # this is setting, not a variable
echo $configline >> $TARGETFILE
fi
fi
done<bash.config
echo "Would you like to add DISPLAY=localhost:0.0 (n to skip)?";
read yn
[ "$yn" != "n" ] && cat bashdisplay.config >> $TARGETFILE
echo "Download bash_git to enable __git_ps1 (n to skip)?";
read yn
[ "$yn" != "n" ] && curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
echo "Would you like to add custom bash promt (n to skip)?";
read yn
[ "$yn" != "n" ] && cat bashpromt.config >> $TARGETFILE
# add variables from bashrc
source ~/.bashrc
# execute bashrc
# exec bash
# or source bash?
# or reset ?
# reset # no. source