Skip to content

Commit

Permalink
chore: Refactor file copying logic in aiddc scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsoyes committed Jul 3, 2024
1 parent 01c32f7 commit 2d4d19d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ if [ ! -d "${PATH_DESTINATION}" ]; then
fi

# For each file in source, copy it in the destination, but if exists, rename it with a .bak extension and current date
for file in $(ls "${PATH_SOURCE}"); do
for file in "${PATH_SOURCE}"/*; do
filename=$(basename $file)
if [ -f "${PATH_DESTINATION}/$filename" ]; then
mv "${PATH_DESTINATION}/$filename" "${PATH_DESTINATION}/$filename.bak.$(date +%Y%m%d)"
Expand Down
5 changes: 2 additions & 3 deletions resources/guide/coding-with-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ declare -a filesToIndex
# Returns:
# None
#
function reset() {
unset filesToIndex
declare -a filesToIndex
function reset() {
filesToIndex=()
}

#
Expand Down
11 changes: 6 additions & 5 deletions scripts/aiddc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ A list of aliases and pre-written scripts to help you inject AI into your dev wo

## Installation

```bash
curl -sSf https://raw.githubusercontent.com/alexsoyes/ai-driven-dev-community/main/scripts/aiddc/install.sh | bash
```shell
#!/bin/sh
curl -sSf "https://raw.githubusercontent.com/alexsoyes/ai-driven-dev-community/main/scripts/aiddc/install.sh" | bash
```

## Configuration
Expand All @@ -26,7 +27,7 @@ Provide an OpenAI API key in the `.env` file.
OPENAI_API_KEY=sk-<your-api-key>
```

Or direcly in your `.bashrc` file.
Or directly in your `.bashrc` file.

```bash
export OPENAI_API_KEY=sk-<your-api-key>
Expand All @@ -38,7 +39,7 @@ Use `aiddc-<command>` to run our scripts.

### Available Commands

There is two types of commands to help you.
There are two types of commands to help you.

- *Operation*: The ones which call the AI to help you with your code (e.g. `aiddc-commit-msg` - ask AI to generate a beautiful commit message for you).
- *Asking AI*: The ones which are doing easier operations (e.g. `aiddc-changes` - copy `git diff` in your clipboard).
Expand All @@ -49,7 +50,7 @@ There is two types of commands to help you.

- `aiddc-changes` - Copy the `git diff` output to your clipboard.
- `aiddc-changes-from-main` - Copy the `git diff main` output to your clipboard.
- `aidd-commit-last` - Copy last 10 commit messages to your clipboard.
- `aidd-commit-last` - Copy the last 10 commit messages to your clipboard.

#### Asking AI

Expand Down
10 changes: 5 additions & 5 deletions scripts/aiddc/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ const askAi = async (prompt) => {
console.warn(prompt);
console.log(`--------------------`);

try {
clipboardy.writeSync(prompt);
} catch (error) {
console.error('Failed to copy prompt to clipboard:', error);
}
try {
clipboardy.writeSync(prompt);
} catch (error) {
console.error('Failed to copy prompt to clipboard:', error);
}

console.info(`📋 Prompt copied to clipboard.\n`);

Expand Down
14 changes: 5 additions & 9 deletions scripts/aiddc/scripts/_.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,11 @@ error() {
# Arguments:
# $1 - The debug message to print.
#
if [[ "${DEBUG}" == "true" ]]; then
debug() {
debug() {
if [ "${DEBUG}" = "true" ]; then
echo "---> DEBUG: $1"
}
else
debug() {
: # No-op when debug is not enabled
}
fi
fi
}


#
Expand All @@ -74,7 +70,7 @@ BASE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
ENV_PATH="$BASE_DIR/../.env"

if [ -f "$ENV_PATH" ]; then
source "$ENV_PATH"
. "$ENV_PATH"
debug ".env file loaded"
else
error "No .env file found in dir $BASE_DIR"
Expand Down
3 changes: 1 addition & 2 deletions scripts/generated/code-with-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ declare -a filesToIndex
# Returns:
# None
#
function reset() {
function reset() {
filesToIndex=()
declare -a filesToIndex
}

#
Expand Down
2 changes: 1 addition & 1 deletion scripts/generated/snippets-install-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if [ ! -d "${PATH_DESTINATION}" ]; then
fi

# For each file in source, copy it in the destination, but if exists, rename it with a .bak extension and current date
for file in $(ls "${PATH_SOURCE}"); do
for file in "${PATH_SOURCE}"/*; do
filename=$(basename $file)
if [ -f "${PATH_DESTINATION}/$filename" ]; then
mv "${PATH_DESTINATION}/$filename" "${PATH_DESTINATION}/$filename.bak.$(date +%Y%m%d)"
Expand Down

0 comments on commit 2d4d19d

Please sign in to comment.