GeezerVison is showing github.com — fix(install): check if the path export command already exists (#28) · toastdriven/opencode@ec928d8
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: install +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -107,7 +107,9 @@ add_to_path() { |
107 | 107 | local config_file=$1 |
108 | 108 | local command=$2 |
109 | 109 |
|
110 | | - if [[ -w $config_file ]]; then |
| 110 | + if grep -Fxq "$command" "$config_file"; then |
| 111 | + print_message info "Command already exists in $config_file, skipping write." |
| 112 | + elif [[ -w $config_file ]]; then |
111 | 113 | echo -e "\n# opencode" >> "$config_file" |
112 | 114 | echo "$command" >> "$config_file" |
113 | 115 | print_message info "Successfully added ${ORANGE}opencode ${GREEN}to \$PATH in $config_file" |
@@ -173,6 +175,7 @@ if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then |
173 | 175 | add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" |
174 | 176 | ;; |
175 | 177 | *) |
| 178 | + export PATH=$INSTALL_DIR:$PATH |
176 | 179 | print_message warning "Manually add the directory to $config_file (or similar):" |
177 | 180 | print_message info " export PATH=$INSTALL_DIR:\$PATH" |
178 | 181 | ;; |
|