Skip to content

Commit 2689246

Browse files
committed
Add smart functions detection during installation
If BASH installation is used, then 1. if `git-elegant` binary is available, it starts; otherwise, the configuration instructions are printed 2. if `git-elegant` BASH completion is not available, the configuration instructions are printed If Brew installation is used, then it installs the binary and completion files. As the `git-elegant` won't be available from Brew, the configuration instructions are printed.
1 parent 07bc585 commit 2689246

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

install.bash

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,30 @@ copy(){
2121
install -m 644 ${FROM}/version ${INTO}
2222
}
2323

24-
next-steps() {
24+
update-path() {
25+
local INSTALL_PATH=${1}
26+
cat <<TEXT
27+
You need to add Elegant Git to the PATH by adding to
28+
a "~/.bashrc" or "~/.bash_profile" file:
29+
30+
export PATH=${INSTALL_PATH}/bin:\$PATH
31+
32+
After, please configure the installation by running
33+
34+
git-elegant acquire-git
35+
36+
TEXT
37+
}
38+
39+
update-completion() {
2540
local INSTALL_PATH=${1}
2641
local COMPLETION_FILE="${INSTALL_PATH}/completions/git-elegant.bash"
27-
cat <<TEXT >&1
28-
Please add 3 highlighted lines to your "~/.bashrc" (or "~/.bash_profile"):
29-
--------------------------------------------------------------------------
30-
# elegant git: ${REPO_HOME}
31-
export PATH=${INSTALL_PATH}/bin:\$PATH
32-
[ -f ${COMPLETION_FILE} ] && . ${COMPLETION_FILE}
33-
--------------------------------------------------------------------------
34-
Then, please restart the terminal and enjoy the 'elegant git'!
42+
cat <<TEXT
43+
You need to add loading of BASH completion file to
44+
a "~/.bashrc" or "~/.bash_profile" file:
45+
46+
[ -f ${COMPLETION_FILE} ] && . ${COMPLETION_FILE}
47+
3548
TEXT
3649
}
3750

@@ -60,8 +73,14 @@ main() {
6073
copy "${path}" ${INSTALL_PATH}
6174
fi
6275
echo "Elegant Git is installed to '${INSTALL_PATH}/bin/git-elegant'."
63-
${INSTALL_PATH}/bin/git-elegant acquire-git
64-
command -v git-elegant 1>/dev/null 2>&1 || next-steps ${INSTALL_PATH}
76+
if command -v git-elegant 1>/dev/null 2>&1; then
77+
git-elegant acquire-git
78+
else
79+
update-path ${INSTALL_PATH}
80+
fi
81+
if ! complete -p git-elegant 1>/dev/null 2>&1; then
82+
update-completion ${INSTALL_PATH}
83+
fi
6584
}
6685

6786
main $@

0 commit comments

Comments
 (0)