Skip to content

Instantly share code, notes, and snippets.

@taveras
Last active November 3, 2016 23:05
Show Gist options
  • Save taveras/162860deae8f62a6d774292abe6442f4 to your computer and use it in GitHub Desktop.
Save taveras/162860deae8f62a6d774292abe6442f4 to your computer and use it in GitHub Desktop.
Convert Apache redirect map to NGINX format
#!/bin/bash
# copy file 1 to file 2, and overwrite file 2 if necessary
yes | cp $1 $2
# %g/^#/normal dd # Deletes all comments
# %normal Elcw # Collapses whitespace between segments
# %normal A; # Adds semicolon to the end of each line
# %g/\S\/\;/normal f;hx # Removes trailling slash for second segment
# %g/\/ /normal Ex # Removes trailing slash for first segment
# %normal Vgu # Lower cases all characters
# %sort u # Sort all redirects, remove duplicates
# wq # Save file and quit
# open vim and run the above ex commands
vim -T dumb --noplugin $2 -c "%g/^#/normal dd" \
-c "%normal Elcw " \
-c "%normal A;" \
-c "%g/\S\/\;/normal f;hx" \
-c "%g/\/ /normal Ex" \
-c "%normal Vgu" \
-c "%sort u" \
-c "wq"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment