Skip to content

Instantly share code, notes, and snippets.

@markgreene74
Created June 24, 2023 12:27
Show Gist options
  • Select an option

  • Save markgreene74/024308c8429595348be8576a79b81a15 to your computer and use it in GitHub Desktop.

Select an option

Save markgreene74/024308c8429595348be8576a79b81a15 to your computer and use it in GitHub Desktop.
Find the file modified after the last rebase

My solutions to rustlings are kept in a branch in my fork of the repo (markgreene74/rustlings:solutions), and also in a separate repo rustlings_solutions. After a rebase of the branch to main some solutions need to be modified and the changes pushed.

This simple bash script can be used to find the file modified so that thay can also be updated in rustlings_solutions.

cd github

for src_file in $(find rustlings/exercises -type f -name "*.rs"); do \
  dst_file=$(echo ${src_file} | sed 's/rustlings/rustlings_solutions/')
  echo "Comparing ${src_file} and ${dst_file}";
  diff ${src_file} ${dst_file} > /dev/null && echo "(OK) files are identical" || echo "${dst_file} differs" ;
  echo; echo;
done

Or just replace the files that do differ.

for src_file in $(find rustlings/exercises -type f -name "*.rs"); do \
  dst_file=$(echo ${src_file} | sed 's/rustlings/rustlings_solutions/')
  diff ${src_file} ${dst_file} > /dev/null && echo OK || cp ${src_file} ${dst_file};
  echo;
done

Originally started to build on just find and xargs, but couldn't make it work.

find rustlings/exercises -type f -name "*.rs" -print0 | xargs -0I{} sh -c "echo {} && echo {} | sed 's/rustlings/rustlings_solutions/'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment