Skip to content

Conversation

@jhauga
Copy link

@jhauga jhauga commented Dec 1, 2025

Add --save option set for reusable curl configurations

This PR adds a new feature set to save and reuse curl option combinations,
making it easier to work with frequently used curl configurations. Users can
save complex option sets with memorable names instead of remembering
lengthy command-line arguments. The feature also supports parameter
expansion, allowing saved configurations to accept dynamic values like
URLs and filenames at runtime.

New Options

  • --save-call=NAME:OPTIONS - Save curl options to ~/.wcurlrc with a
    memorable name
  • -r, --run-save=NAME - Run a saved curl configuration
  • --list-save - List all saved configurations
  • --rm-save=NAME - Remove a saved configuration

Key Features

Parameter Expansion:

# Save with placeholders (!1, !2, !3)
wcurl --save-call=getFile:'-o !1 !2'

# Simple run with parameters
# Essentially expands to:
# curl -o output.txt example.com/file.txt
wcurl --run-save=getFile -o output.txt example.com/file.txt

# Save with placeholders (!1, !2, !3, !4)
wcurl --save-call=dumpVerb:'-I !1 -o !2 --next -v !3 -o !4'

# Essentially expands to:
# curl -I example.com -o dump.txt --next -v example.com/file.txt -o file.txt
wcurl -r=dumpVerb example.com dump.txt example.com/file.txt file.txt

# With --dry-run
# Expansion parameters will not work with --dry-run
wcurl --dry-run -r=dumpVerb example.com dump.txt example.com/file.txt file.txt # Outputs
# curl -I 'example.com' -o 'dump.txt' --next -v 'example.com/file.txt' -o 'file.txt'

Basic Usage:

# Save frequently used options
wcurl --save-call=quiet:"--silent --show-error"

# Reuse saved options
wcurl --run-save=quiet example.com/file.txt

# Save for getting status code
wcurl --save-call=code:" -LI -s -w %{http_code}\n -o /dev/null"

# Returns the status code for each URL on new line.
wcurl -r=code example.com imdb.com google.com curl.se # etc...
# 200
# 200
# 200
# 403

List Saved Configurations:

wcurl --list-save #outputs
# Saved calls in /home/user/.wcurlrc:
#
#  verbose:
#    --progress-bar -L -I -v
#
#  progress:
#    --progress-bar -L -v
#
#  getFile:
#    -o !1 !2
#
#  dumpVerb:
#    -I !1 -o !2 --next -v !3 -o !4
#
#  code:
#     -LI -s -w %{http_code}\\n -o /dev/null
#
#  torture:
#    -I -L !1 -o !2 --next -I !3 -o !4 --next -I !5 -o !6 --next -I !7 -o !8 --next -I !9 -o !10 --next -I !11 -o !12 --next -I !13 -o !14 --next -v !15

Remove Saved Configuration

wcurl --rm-save=verbose # outputs
# Removed saved call: verbose

Security

  • File permissions set to 600 (owner read/write only)
  • Input validation: names restricted to alphanumeric, dash, underscore
  • Secure temp file handling with mktemp
  • Proper shell escaping to prevent command injection
  • Grep pattern escaping to prevent regex injection

Testing

  • 14 new test cases covering all functionality.
  • Tests for basic save/load, parameter expansion, error handling, and security.
  • All existing tests continue to pass.
  • Parameter expansion can take over a dozen parameters. Locally tested using:
# Save a call with 15 parameter expansion markers.
wcurl --save-call=torture:'-I -L !1 -o !2 --next -I !3 -o !4 --next -I !5 -o !6 --next -I !7 -o !8 --next -I !9 -o !10 --next -I !11 -o !12 --next -I !13 -o !14 --next -v !15'

# Test with to verify parameter expansion
wcurl --run-save=torture example.com out1.txt example.com out2.txt example.com out3.txt example.com out4.txt example.com out5.txt example.com out6.txt example.com out7.txt example.com

# With --dry-run
# Using --dry-run with many parameters
wcurl --dry-run --run-save=torture example.com out1.txt example.com out2.txt example.com out3.txt example.com out4.txt example.com out5.txt example.com out6.txt example.com out7.txt example.com # outputs
# curl -I -L 'example.com' -o 'out1.txt' --next -I 'example.com' -o 'out2.txt' --next -I 'example.com' -o 'out3.txt' --next -I 'example.com' -o 'out4.txt' --next -I 'example.com' -o 'out5.txt' --next -I 'example.com' -o 'out6.txt' --next -I 'example.com' -o 'out7.txt' --next -v 'example.com'

Documentation

  • Updated wcurl, wcurl.md, and wcurl.1 with complete option descriptions.
  • Examples for both basic usage and parameter expansion.
  • Security considerations documented.

This feature allows for complex option combinations to be reused, and addresses
the need for users who frequently use the same curl option combinations,
reducing command-line typing and potential errors while maintaining wcurl's
simplicity.

@samueloph
Copy link
Collaborator

Thank you for the PR.

I don't think we should add config handling to wcurl as a shell script due to its complexity, this should be reserved for a compiled version of wcurl (iff we decide the we should have this feature).

Today you can already make use of curl's config files by using the option --curl-options="--config $CONFIGFILE", this will work because wcurl calls curl. You don't even need to explicitly provide a config file if you save it in one of the places where curl looks for them by default, as described in https://everything.curl.dev/cmdline/configfile.html#default-config-file.

Does this cover your use case?

https://everything.curl.dev/cmdline/configfile.html

@jhauga
Copy link
Author

jhauga commented Dec 1, 2025

Does this cover your use case?

Yes. Thank you!

@jhauga jhauga closed this Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants