forked from andresgongora/synth-shell-prompt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·134 lines (93 loc) · 4.51 KB
/
setup.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
## +-----------------------------------+-----------------------------------+
## | |
## | Copyright (c) 2019-2020, Andres Gongora <[email protected]>. |
## | |
## | This program is free software: you can redistribute it and/or modify |
## | it under the terms of the GNU General Public License as published by |
## | the Free Software Foundation, either version 3 of the License, or |
## | (at your option) any later version. |
## | |
## | This program is distributed in the hope that it will be useful, |
## | but WITHOUT ANY WARRANTY; without even the implied warranty of |
## | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
## | GNU General Public License for more details. |
## | |
## | You should have received a copy of the GNU General Public License |
## | along with this program. If not, see <http://www.gnu.org/licenses/>. |
## | |
## +-----------------------------------------------------------------------+
##
## QUICK INSTALLER
##
##==============================================================================
## INCLUDE DEPENDENCIES
##==============================================================================
[ "$(type -t include)" != 'function' ]&&{ include(){ { [ -z "$_IR" ]&&_IR="$PWD"&&cd $(dirname "${BASH_SOURCE[0]}")&&include "$1"&&cd "$_IR"&&unset _IR;}||{ local d=$PWD&&cd "$(dirname "$PWD/$1")"&&. "$(basename "$1")"&&cd "$d";}||{ echo "Include failed $PWD->$1"&&exit 1;};};}
include 'bash-tools/bash-tools/user_io.sh'
include 'bash-tools/bash-tools/hook_script.sh'
include 'bash-tools/bash-tools/assemble_script.sh'
##==============================================================================
## SELECT SETUP LOCATION (PROMPT USER IF NEED BE)
##==============================================================================
## SWITCH BETWEEN AUTOMATIC AND USER INSTALLATION
if [ "$#" -eq 0 ]; then
OUTPUT_SCRIPT="$HOME/.config/synth-shell/synth-shell-prompt.sh"
OUTPUT_CONFIG_DIR="$HOME/.config/synth-shell"
USER_CHOICE=""
elif [ "$#" -eq 2 ]; then
OUTPUT_SCRIPT="$1"
OUTPUT_CONFIG_DIR="$2"
USER_CHOICE="y"
else
printError "Wrong number of arguments passed to setup script"
exit 1
fi
## CREATE HOOK
printInfo "Installing script as $OUTPUT_SCRIPT"
if [ -z "$USER_CHOICE" ]; then
USER_CHOICE=$(promptUser "Add hook your .bashrc file or equivalent?\n\tRequired for autostart on new terminals" "[Y]/[n]?" "yYnN" "y")
fi
case "$USER_CHOICE" in
""|y|Y ) hookScript $OUTPUT_SCRIPT ;;
n|N ) ;;
*) printError "Invalid option"; exit 1
esac
##==============================================================================
## EMPLACE SCRIPT
##==============================================================================
## DEFINE LOCAL VARIABLES
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
INPUT_SCRIPT="$DIR/synth-shell-prompt/synth-shell-prompt.sh"
INPUT_CONFIG_DIR="$DIR/config"
## HEADER TO BE ADDED AT THE TOP OF THE ASSEMBLED SCRIPT
OUTPUT_SCRIPT_HEADER=$(printf '%s'\
"##\n"\
"##\n"\
"## =======================\n"\
"## WARNING!!\n"\
"## DO NOT EDIT THIS FILE!!\n"\
"## =======================\n"\
"##\n"\
"## This file was generated by an installation script.\n"\
"## It might be overwritten without warning at any time\n"\
"## and you will lose all your changes.\n"\
"##\n"\
"## Visit for instructions and more information:\n"\
"## https://github.com/andresgongora/synth-shell/\n"\
"##\n"\
"##\n\n\n")
##==============================================================================
## EMPLACE CONFIGURATION FILES
##==============================================================================
## SETUP SCRIPT
assembleScript "$INPUT_SCRIPT" "$OUTPUT_SCRIPT" "$OUTPUT_SCRIPT_HEADER"
## SETUP CONFIGURATION FILES
[ -d "$OUTPUT_CONFIG_DIR" ] || mkdir -p "$OUTPUT_CONFIG_DIR"
cp -r "$INPUT_CONFIG_DIR/." "$OUTPUT_CONFIG_DIR/"
## SETUP DEFAULT SYNTH-SHELL-PROMPT CONFIG FILE
CONFIG_FILE="$OUTPUT_CONFIG_DIR/synth-shell-prompt.config"
if [ -f "$CONFIG_FILE" ]; then
CONFIG_FILE="${CONFIG_FILE}.new"
fi
cp "$INPUT_CONFIG_DIR/synth-shell-prompt.config.default" "$CONFIG_FILE"