Something that we could think about is directly to provide a command to pg_rewind via command line.
In my patch I added this option too. One can pass restore_command via -R option, e.g.:
pg_rewind -P --target-pgdata=/path/to/master/pg_data --source-pgdata=/path/to/standby/pg_data -R 'cp /path/to/wals_archive/%f %p'
Another possibility would be to have a separate tool which scans a data folder and fetches by itself a range of WAL segments wanted.
Currently in the patch, with dry-run option (-n) pg_rewind only fetches missing WALs to be able to build file map, while doesn't touch any data files. So I guess it behaves exactly as you described and we do not need a separate tool.
-- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company