mirror of
https://codeberg.org/vlw/curl.git
synced 2026-04-13 10:49:39 +02:00
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 <victor@vlw.se> Co-committed-by: vlw <victor@vlw.se>
This commit is contained in:
parent
0ddb72a05f
commit
8c2caf78cb
4 changed files with 96 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,4 +1,7 @@
|
||||||
curl/*
|
curl/*
|
||||||
!curl/.gitkeep
|
!curl/.gitkeep
|
||||||
|
|
||||||
|
saved/*
|
||||||
|
!saved/.gitkeep
|
||||||
|
|
||||||
disable_peer_validation
|
disable_peer_validation
|
||||||
|
|
|
||||||
10
README.md
10
README.md
|
|
@ -76,3 +76,13 @@ Run the `curl.sh` file from your shell and pass it two parametes for URL and req
|
||||||
```sh
|
```sh
|
||||||
./curl.sh https://example.com GET
|
./curl.sh https://example.com GET
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# 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 <name>`|Save the current configuration where `<name>` is the name of this configuration
|
||||||
|
`./save.sh move <name>`|Move the current configuration where `<name>` is the name of this configuration. A new empty configuration will be created.
|
||||||
|
`./save.sh load <name>`|Load a saved configuration where `<name>` is the name of the target configuration. The current configuration will be saved as `._backup`.
|
||||||
|
`./save.sh list`|List all saved configurations
|
||||||
82
save.sh
Executable file
82
save.sh
Executable file
|
|
@ -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 <name>\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 <name>\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
|
||||||
0
saved/.gitkeep
Normal file
0
saved/.gitkeep
Normal file
Loading…
Add table
Reference in a new issue