Skip to content

Instantly share code, notes, and snippets.

@diegogangl
Created March 25, 2017 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegogangl/aa785c67720860864534fae72936392d to your computer and use it in GitHub Desktop.
Save diegogangl/aa785c67720860864534fae72936392d to your computer and use it in GitHub Desktop.
Remove dates from jekyll post files using git mv
#!/bin/python
"""
Remove dates from jekyll post files
This is a small script made to remove dates from jekyll files using
the 'git mv' command.
It expects files to be in the format YYYY-MM-DD-NAME.EXT.
You can pass a different function to change() to remove or add
something different from filenames.
Simply point it to a folder containing the markdown files and it
will run git mv on all of them for you. Don't forget to commit afterwards!
Usage:
./rename_git.py path/to/files
"""
import os
import argparse
import subprocess
def get_command(src, dst): return 'git mv {0} {1}'.format(src, dst)
def remove_date(name, path): return path + name[11::]
def change(filename, path, change_fn):
new_name = change_fn(filename, path)
subprocess.run(get_command(path + filename, new_name), shell = True)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Change filenames')
parser.add_argument('path')
args = parser.parse_args()
filenames = next(os.walk(args.path))[2]
[change(name, args.path, remove_date) for name in filenames]
print('Filenames in {0} have been changed'.format(args.path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment