Hello I need the help of the community to get the ChatGPT-3.5 to be able to continue the output of a shell script… The AI is unable to continue pass a certain limit as the script is 1,272 tokens… I was under the impression that calculating twice the amount of tokens such that it stays bellow 4000 would have been enough… apparently it is not…
Full Shell Script
#!/usr/bin/env bash
Replace these variables with the appropriate values for your installation
PORTABLE_VSCODE_DIR=“${HOME}/main-vscode”
DOWNLOAD_URL=“https://code.visualstudio.com/sha/download?build=stable\&os=linux-x64”
mkdir -p “$PORTABLE_VSCODE_DIR”
cd “$PORTABLE_VSCODE_DIR” || exit 10
If the -y flag is provided, automatically close any running instances of VS Code
if [[ $1 == “-y” ]]; then
echo “Closing any running instances of VS Code…”
pkill -f “Visual Studio Code” -15
sleep 1
else
# Ask for confirmation before proceeding
pwd
while true; do
read -rp “Are you sure you want to update VS Code? [Y/n] " yn
case $yn in
[OoYy]* | “”) # Acceptable affirmative answers in English or French
echo “Closing any running instances of VS Code…”
for i in {5…1}; do
echo -n " $i”
sleep 1
done
echo “”
pkill -f “Visual Studio Code” -15
sleep 1
;;
break
;;
[Nn]*) # Any answer starting with N or n is not acceptable
exit 0 ;;
*) # Any other answer will prompt for a re-ask
echo “Please answer Y or n.” ;;
esac
done
fi
Commit changes to git repository
if [[ -d .git ]]; then
git add .
git commit -am “Will Update VS Code on $(date +‘%Y-%m-%d %H:%M:%S’)”
fi
Create backup folder and move contents
backup_folder=(find "{PORTABLE_VSCODE_DIR}" -maxdepth 1 -type d -name “backup-*” 2>/dev/null | sort -r | head -n 1)
if [[ -z $backup_folder ]]; then
backup_folder="HOME/main-vscode/backup-001~"
else
last_num=(echo "backup_folder" | sed -n 's/.*backup-\(.*\)~\/.*/\1/p')
new_num=(printf ‘%03d’ $((10#last_num + 1)))
backup_folder={backup_folder/~/$new_num}
fi
echo “Creating backup directory: $backup_folder”
mkdir -p “backup_folder"
cp -r "{PORTABLE_VSCODE_DIR}”/!(.git) “$backup_folder”
Move back necessary files from backup folder
cp -r “$backup_folder/data” “$PORTABLE_VSCODE_DIR”
cp “$backup_folder/code-outlined-logo.svg” “$PORTABLE_VSCODE_DIR”
cp “$backup_folder”/.directory “$PORTABLE_VSCODE_DIR”
Remove content inside main folder’s user-data folder except for User folder
rm -rf “${PORTABLE_VSCODE_DIR}”/data/user-data/!(User)
download the latest version of VSCode
echo “Downloading latest version of VS Code…”
latest_url=$(curl -s “$DOWNLOAD_URL” | grep -Eo ‘https://.*.tar.gz’)
wget “latest_url" -P "{PORTABLE_VSCODE_DIR}”
extract the downloaded file
echo “Extracting VS Code files to temporary directory…”
tar -xzvf “{PORTABLE_VSCODE_DIR}/"*.tar.gz -C "{PORTABLE_VSCODE_DIR}/”
move all the content from the extracted folder to the parent folder
echo “Moving files to portable installation directory…”
mv “{PORTABLE_VSCODE_DIR}/VSCode-linux-x64/"* "{PORTABLE_VSCODE_DIR}/”
remove the extracted folder
echo “Cleaning up temporary files…”
rmdir “${PORTABLE_VSCODE_DIR}/VSCode-linux-x64”
rm -f code-stable-x64-*.tar.gz
if [[ -d .git ]]; then
git add .
git commit -am “Did Update VS Code to $(basename “$latest_url”)”
fi
echo “Update complete.”
― 1,272 Tokens
The AI stop short and do not understand when I ask to continue:
In this section, the script creates a backup directory and moves the contents of the main VS Code directory into it. Then, it moves back some necessary files from the backup directory to the main directory. Finally, it removes all the contents inside the user-data folder of the main directory, except for the User folder.
This is a good approach for ensuring that important files are not lost during the update process, and for keeping the user’s settings intact. The script is also using the
-r
flag withcp
to recursively copy directories and subdirectories, which is a best practice when working with files and folders.One suggestion for improvement would be to add some error handling for the
cp
command. For example, if the backup directory exists but there are no files in the main VS Code directory to copy, thecp
command will fail and the script will terminate. You could add a check for this scenario and display a warning message to the user.
If I ask to continue (I have tried many different manners) it generate the full script from the beginning:
I hope someone will have the experience of generating long script with ChatGPT-3.5 and will be willing to teach me and the community about the tips and tricks on how to prompt the AI for long scripts …