Skip to content

Commit 7dd9c56

Browse files
committed
Only add source lines to shell rc file if not already there
1 parent 504743a commit 7dd9c56

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

install.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22
_src_dir="${PWD}/src/venv-cli"
33
_install_dir="/usr/local/share/venv"
4+
_source_comment="# Source function script for 'venv' command"
45

56
set -e
67

@@ -18,9 +19,13 @@ install_common() {
1819
sudo cp "${completion_file}" "${completion_target}"
1920
fi
2021

21-
# Append line to the shell config file to source the script
22-
echo -e "\n# Source function script for 'venv' command" >> "${rcfile}"
23-
echo ". ${_install_dir}/venv" >> "${rcfile}"
22+
# If line does not already exist in the rc file,
23+
# append line to the shell config file to source the venv-cli script
24+
if ! command grep -q "${_source_comment}" "${rcfile}"; then
25+
echo "${_source_comment}" >> "${rcfile}"
26+
echo "source ${_install_dir}/venv" >> "${rcfile}"
27+
fi
28+
2429
{ set +x; } 2>/dev/null
2530
}
2631

@@ -40,8 +45,10 @@ install_zsh() {
4045
echo "Command completions currently not supported for zsh"
4146

4247
install_common "${rcfile}"
43-
echo "fpath+=( ${_install_dir} )" >> "${rcfile}"
44-
echo "autoload -Uz venv" >> "${rcfile}"
48+
if ! command grep -q "${_source_comment}" "${rcfile}"; then
49+
echo "fpath+=( ${_install_dir} )" >> "${rcfile}"
50+
echo "autoload -Uz venv" >> "${rcfile}"
51+
fi
4552
}
4653

4754
main() {

0 commit comments

Comments
 (0)