Skip to content

Instantly share code, notes, and snippets.

@zudsniper
Last active August 2, 2023 02:52
Show Gist options
  • Save zudsniper/1548776501b4a598eac24b63c849f241 to your computer and use it in GitHub Desktop.
Save zudsniper/1548776501b4a598eac24b63c849f241 to your computer and use it in GitHub Desktop.
πŸ–¨ [GPT-4] Prompt to qualify a bash script generation so as to fit my specifications. (07/15/2023)

UPDATE regarding this README file

2023-08-01

THIS FILE IS NOT BE GUARANTEED, OR EVEN ASSUMED, TO BE UP TO DATE.

Check the file (right below this if you're viewing the gist on github) called bash_zreqs.prompt for the prompt.


the_answers


CHANGELOG

well sort of

  • 2023-08-01 updating this file, as well as updating the prompt itself. Could still use optimization for length.
  • 2023-07-15 Date of last edit prior to addition of this section
1. Checks for and installs, if necessary, an ANSI color schema from ~/.ansi_colors.sh or https://raw.githubusercontent.com/zudsniper/bashbits/master/.ansi_colors.sh.
2. Uses ANSI escape codes to style console output, ensuring readability of color contrasts.
a. Determine operating system of execution. Set the SYS_PKG_MGR variable to the appropriate value. For Debian/Ubuntu, this would be `apt` or `apt-get`, for macOS this would be `brew`, and if Windows is the executing OS just output `πŸ’€ How did you get here?` and quit.
b. An OS is allowed to have multiple package managers: with the only one you need to support being `snap` as a fallback for `apt-get` / `apt`: meaning if a package isn't available on aptitude, you should then (first install `snap` via `sudo apt-get install snap -y`) see if you can `sudo snap install <pkg_name>`
3. Implements a log function defined as follows:
log() calls should follow this example: `log info "my name is jeff"`
create a global (outside of this function) variable called LOG_LEVEL.
with these log levels, which have a name as well as a numerical value associated with them as follows: verbose(5), debug(4), info(3), warn(2), error(1), fatal(0). The order defines the priority, with fatal being the most extreme. this should be set by default to 'info'.
Using these names & numbers, the log function should use the LOG_LEVEL variable, which (as described later) should be configurable via the --log_level|-l <level> CLI flag, to determine what level of logs are actually printed to the user. All log levels below the selected log level, as well as of course that level itself, shall be printed. For instance, by default with the value of LOG_LEVEL being 'info' and associated number for 'info' being 3, all messages, EXCEPT OF LEVEL verbose(5>3) or debug(4>3), shall be printed for the user.
For all log levels, use the following format for prints: '[{LEVEL_COLOR}{LEVEL_NAME}${A_RESET}] {LEVEL_TEXT_COLOR}{log_message}' Not all log levels will have a text color, and if this is the case, simply use ${A_RESET}. Otherwise, text colors for each log level should be used to color the printed text, and log color should simply define the color of the description text message. Use bold red for fatal color, text color simply red. info color is green, text color none. warn color is yellow (with a black bg, "${A_BG_BLACK}${A_YELLOW}"), text color is simply bold ("${A_BOLD}"), debug's color is purple, with a text color of grey italic. verbose should have the color "${A_INVERSE}", and a text color of "${A_RESET}".
4. Includes these CLI flags:
- --help|-h: Show usage message with color.
- --version|-V: Display VERSION variable, if undefined, print "None".
- --verbose|-v: Set logging to verbose, excluding "silly" level.
- --log_level|-l [level]: Set log level, accepts values or integers (7=silly, 0=critical).
- --debug|-d: convenience flag, sets log_level to debug.
5. Use these log levels in place of normal echo commands throughout the script.
6. If any external packages / CLI tools are used such as jq, curl, wget, perl, etc. please first check if they are installed, then attempt to install the missing dependencies, and finally error out with a detailed description of the problem if unable to auto-install.
7. Prints my tag ( echo -ne "\n\n by ${A_GREEN}@zudsniper${A_RESET}" ) GitHub handle in color. (also add add a printed message in grey which says "replace @zudsniper with your author tag." )
[
{
"cmd": "Bash Script Requirements",
"act": "Implement the requirements for the bash script as detailed in the prompt",
"prompt": "1. Checks for and installs, if necessary, an ANSI color schema from ~/.ansi_colors.sh or https://raw.githubusercontent.com/zudsniper/bashbits/master/.ansi_colors.sh.\n2. Uses ANSI escape codes to style console output, ensuring readability of color contrasts.\n a. Determine operating system of execution. Set the SYS_PKG_MGR variable to the appropriate value. For Debian/Ubuntu, this would be `apt` or `apt-get`, for macOS this would be `brew`, and if Windows is the executing OS just output `πŸ’€ How did you get here?` and quit. \n b. An OS is allowed to have multiple package managers: with the only one you need to support being `snap` as a fallback for `apt-get` / `apt`: meaning if a package isn't available on aptitude, you should then (first install `snap` via `sudo apt-get install snap -y`) see if you can `sudo snap install <pkg_name>` \n3. Implements a log function with the 7 log levels (silly, verbose, debug, http, info, warn, error, critical) to control output style and color.\n4. Includes CLI flags: \n - --help|-h: Show usage message with color.\n - --version|-V: Display VERSION variable, if undefined, print \"None\".\n - --verbose|-v: Set logging to verbose, excluding \"silly\" level.\n - --log_level|-l [level]: Set log level, accepts values or integers (7=silly, 0=critical).\n - --debug|-d: convenience flag, sets log_level to debug. \n5. Use these log levels in place of normal echo commands throughout the script. \n6. If any external packages / CLI tools are used such as jq, curl, wget, perl, etc. please first check if they are installed, then attempt to install the missing dependencies, and finally error out with a detailed description of the problem if unable to auto-install. \n7. Prints the author's tag ( by ${A_GREEN}@zudsniper${A_RESET}) GitHub handle in color."
}
]
[
{
"cmd": "Check and install ANSI color schema",
"act": "Install ANSI color schema from ~/.ansi_colors.sh or https://raw.githubusercontent.com/zudsniper/bashbits/master/.ansi_colors.sh if necessary",
"prompt": "Checks for and installs, if necessary, an ANSI color schema from ~/.ansi_colors.sh or https://raw.githubusercontent.com/zudsniper/bashbits/master/.ansi_colors.sh."
},
{
"cmd": "Use ANSI escape codes",
"act": "Style console output using ANSI escape codes, ensuring readability of color contrasts",
"prompt": "Uses ANSI escape codes to style console output, ensuring readability of color contrasts."
},
{
"cmd": "Determine operating system",
"act": "Set the SYS_PKG_MGR variable to the appropriate value based on the operating system",
"prompt": "Determine operating system of execution. Set the SYS_PKG_MGR variable to the appropriate value. For Debian/Ubuntu, this would be `apt` or `apt-get`, for macOS this would be `brew`, and if Windows is the executing OS just output `πŸ’€ How did you get here?` and quit."
},
{
"cmd": "Support multiple package managers",
"act": "Support `snap` as a fallback for `apt-get` / `apt`",
"prompt": "An OS is allowed to have multiple package managers: with the only one you need to support being `snap` as a fallback for `apt-get` / `apt`: meaning if a package isn't available on aptitude, you should then (first install `snap` via `sudo apt-get install snap -y`) see if you can `sudo snap install <pkg_name>`"
},
{
"cmd": "Implement log function",
"act": "Implement a log function with the 7 log levels (silly, verbose, debug, http, info, warn, error, critical) to control output style and color",
"prompt": "Implements a log function with the 7 log levels (silly, verbose, debug, http, info, warn, error, critical) to control output style and color."
},
{
"cmd": "Include CLI flags",
"act": "Include CLI flags such as --help|-h, --version|-V, --verbose|-v, --log_level|-l [level], --debug|-d",
"prompt": "Includes CLI flags: \n - --help|-h: Show usage message with color.\n - --version|-V: Display VERSION variable, if undefined, print \"None\".\n - --verbose|-v: Set logging to verbose, excluding \"silly\" level.\n - --log_level|-l [level]: Set log level, accepts values or integers (7=silly, 0=critical).\n - --debug|-d: convenience flag, sets log_level to debug."
},
{
"cmd": "Use log levels",
"act": "Use log levels in place of normal echo commands throughout the script",
"prompt": "Use these log levels in place of normal echo commands throughout the script."
},
{
"cmd": "Check and install external packages",
"act": "Check if external packages / CLI tools are installed, then attempt to install the missing dependencies, and finally error out with a detailed description of the problem if unable to auto-install",
"prompt": "If any external packages / CLI tools are used such as jq, curl, wget, perl, etc. please first check if they are installed, then attempt to install the missing dependencies, and finally error out with a detailed description of the problem if unable to auto-install."
},
{
"cmd": "Print author's tag",
"act": "Print the author's tag ( by ${A_GREEN}@zudsniper${A_RESET}) GitHub handle in color",
"prompt": "Prints the author's tag ( by ${A_GREEN}@zudsniper${A_RESET}) GitHub handle in color."
}
]

Bash Script Optimization

You:

Your purpose is to optimize prompts for input into ChatGPT3.5 or 4 so as to make them

  1. The most effective, while also
  2. Minimizing the number of tokens which the prompt uses

Here is a prompt to optimize:

Please write me a bash script that first uses my color text output schema by checking for its installation at ~/.ansi_colors.sh -- if it does not exist, it should be installed from https://raw.githubusercontent.com/zudsniper/bashbits/master/.ansi_colors.sh and then sourced. Use these ANSI escape code variables such as ${A_RED} and ${A_RESET} to style all output to console. Use appropriate coloring, as well as style (bold, italics) -- such as styling errors with red, or warnings with yellow or orange. Please also determine that the foreground and background colors chosen through ANSI variables will be readable (in terms of contrast against one another) before choosing, and if they are not, adjust them to be so. Along with colored output, implement a very simple log_level system with a log() function that determines print color and style and has the 7 standard logging levels which Winston.js and many other loggers use (silly, verbose, debug, http, info, warn, error, critical) and use this log() function at the appropriate level for what is being printed as you discern it, and entirely instead of printing directly to console output. Also include the following CLI flags: 
--help|-h : shows a detailed Usage message printed from a function (use colors)
--version|-V : shows the version of the application via a variable exported by the script called VERSION, or if no version is defined then simply outputs None. 
--verbose|-v : this enables the verbose log level in the logging system you will use throughout this implementation to verbose, so all but "silly" messages are shown. This should increase the amount of detail significantly. 
--log_level|-l [level] : define the log level of the script. Use the 7 valid values as defined earlier as valid input, or accept an integer, 7 being silly and 0 being critical. 

---
Finally, please add  a colored print of the author of this application & this prompt, myself, @zudsniper on github. 
Now, use these specifications when doing the following: 

ChatGPT:

Here's a more concise version of your prompt:

Create a bash script that:
1. Checks for and installs, if necessary, an ANSI color schema from ~/.ansi_colors.sh or https://raw.githubusercontent.com/zudsniper/bashbits/master/.ansi_colors.sh.
2. Uses ANSI escape codes to style console output, ensuring readability of color contrasts.
3. Implements a log function with 7 levels from Winston.js (silly, verbose, debug, http, info, warn, error, critical) to control output style and color.
4. Includes CLI flags: 
   - --help|-h: Show usage message with color.
   - --version|-V: Display VERSION variable, if undefined, print "None".
   - --verbose|-v: Set logging to verbose, excluding "silly" level.
   - --log_level|-l [level]: Set log level, accepts values or integers (7=silly, 0=critical).
5. Prints the author's (@zudsniper) GitHub handle in color.

Use these specifications in the following actions:

This version removes redundancy and specifies all requirements more succinctly. Although the context behind some specifications (like readability of color contrasts) is lost, the primary requirements are all still clear. The total token count is significantly reduced.

@zudsniper
Copy link
Author

added newer logger

@zudsniper
Copy link
Author

added newer logger

I kinda did?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment