From 82f4938be02fd6105ffbee78442b2dfb13d28c7f Mon Sep 17 00:00:00 2001 From: vlw Date: Sun, 29 Mar 2026 13:47:09 +0200 Subject: [PATCH] feat: add script to save and load configs (#5) In this PR we add the ability to save, move, and load configurations with a new `save.sh` script. Reviewed-on: https://codeberg.org/vlw/curl/pulls/5 Co-authored-by: vlw Co-committed-by: vlw --- .gitignore | 3 ++ README.md | 12 +++++++- save.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ saved/.gitkeep | 0 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100755 save.sh create mode 100644 saved/.gitkeep diff --git a/.gitignore b/.gitignore index 37211d2..a77b4a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ curl/* !curl/.gitkeep +saved/* +!saved/.gitkeep + disable_peer_validation diff --git a/README.md b/README.md index e057767..3f95e88 100644 --- a/README.md +++ b/README.md @@ -75,4 +75,14 @@ Run the `curl.sh` file from your shell and pass it two parametes for URL and req ```sh ./curl.sh https://example.com GET -``` \ No newline at end of file +``` + +# Save and load configurations +The `save.sh` script allows you to save and load configurations so you can easily switch between them. + +Command|Description +--|-- +`./save.sh save `|Save the current configuration where `` is the name of this configuration +`./save.sh move `|Move the current configuration where `` is the name of this configuration. A new empty configuration will be created. +`./save.sh load `|Load a saved configuration where `` is the name of the target configuration. The current configuration will be saved as `._backup`. +`./save.sh list`|List all saved configurations \ No newline at end of file diff --git a/save.sh b/save.sh new file mode 100755 index 0000000..f019107 --- /dev/null +++ b/save.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +SAVE_DIR="saved" + +main () { + case "$1" in + # Save current config to a named directory + "save") + if [ "$#" -ne 2 ]; then + echo -e "\e[0;91mExpected: ./save.sh save \e[0m" + return 1 + fi + + local dir="$SAVE_DIR/$2" + + mkdir $dir 2>/dev/null + + shopt -s nullglob + + for file in "curl/req_"*; do + cp -- "$file" $dir + done + + shopt -u nullglob + echo "Saved current configuration to: $2" + ;; + + # Move current config to a named directory + "move") + if [ "$#" -ne 2 ]; then + echo -e "\e[0;91mExpected: ./save.sh move \e[0m" + return 1 + fi + + # Save config to destination + ./save.sh save $2 + + shopt -s nullglob + + for file in "curl/req_"*; do + rm -- "$file" + done + + shopt -u nullglob + + # Create new empty config + ./init.sh + ;; + + # Load saved config by name from directory + "load") + local dir="$SAVE_DIR/$2" + + if [ ! -d $dir ]; then + echo -e "\e[0;91mNo save with name '$2' found\e[0m" + exit 1 + fi + + # Move existing config to backup directory + ./save.sh move ._backup + + shopt -s nullglob + + for file in "$dir/req_"*; do + cp -- "$file" curl/ + done + + shopt -u nullglob + echo "Loaded configuration: $2" + ;; + + "list") + ls -l $SAVE_DIR + ;; + + *) + echo -e "\e[0;91mExpected: ./save.sh (save|move|load|list)\e[0m" + ;; + esac +} + +main $1 $2 diff --git a/saved/.gitkeep b/saved/.gitkeep new file mode 100644 index 0000000..e69de29