From 2d4d19d1514a667d66c0b9379fd165f539bdd5ae Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 3 Jul 2024 08:50:45 +0200 Subject: [PATCH] chore: Refactor file copying logic in aiddc scripts --- README.md | 2 +- resources/guide/coding-with-cli.md | 5 ++--- scripts/aiddc/README.md | 11 ++++++----- scripts/aiddc/main.js | 10 +++++----- scripts/aiddc/scripts/_.sh | 14 +++++--------- scripts/generated/code-with-cli.sh | 3 +-- scripts/generated/snippets-install-osx.sh | 2 +- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 798abb4..0bad1b0 100644 --- a/README.md +++ b/README.md @@ -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)" diff --git a/resources/guide/coding-with-cli.md b/resources/guide/coding-with-cli.md index fea833e..4e4d005 100644 --- a/resources/guide/coding-with-cli.md +++ b/resources/guide/coding-with-cli.md @@ -103,9 +103,8 @@ declare -a filesToIndex # Returns: # None # -function reset() { - unset filesToIndex - declare -a filesToIndex +function reset() { + filesToIndex=() } # diff --git a/scripts/aiddc/README.md b/scripts/aiddc/README.md index 5865bf1..b4ff009 100644 --- a/scripts/aiddc/README.md +++ b/scripts/aiddc/README.md @@ -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 @@ -26,7 +27,7 @@ Provide an OpenAI API key in the `.env` file. OPENAI_API_KEY=sk- ``` -Or direcly in your `.bashrc` file. +Or directly in your `.bashrc` file. ```bash export OPENAI_API_KEY=sk- @@ -38,7 +39,7 @@ Use `aiddc-` 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). @@ -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 diff --git a/scripts/aiddc/main.js b/scripts/aiddc/main.js index 8e89819..397d145 100644 --- a/scripts/aiddc/main.js +++ b/scripts/aiddc/main.js @@ -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`); diff --git a/scripts/aiddc/scripts/_.sh b/scripts/aiddc/scripts/_.sh index a44088e..01ce49e 100644 --- a/scripts/aiddc/scripts/_.sh +++ b/scripts/aiddc/scripts/_.sh @@ -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 +} # @@ -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" diff --git a/scripts/generated/code-with-cli.sh b/scripts/generated/code-with-cli.sh index 2dcb5cb..8224017 100644 --- a/scripts/generated/code-with-cli.sh +++ b/scripts/generated/code-with-cli.sh @@ -28,9 +28,8 @@ declare -a filesToIndex # Returns: # None # -function reset() { +function reset() { filesToIndex=() - declare -a filesToIndex } # diff --git a/scripts/generated/snippets-install-osx.sh b/scripts/generated/snippets-install-osx.sh index 9d12e7d..1599c08 100644 --- a/scripts/generated/snippets-install-osx.sh +++ b/scripts/generated/snippets-install-osx.sh @@ -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)"