import os,sys
from itertools import count
try:
	os.chdir("chapters")
except OSError: pass

chapter = int(sys.argv[1])

def chapterName(which):
	return "Chapter{}.md".format(which)

for num in count(chapter):
	if not os.path.exists(chapterName(num)): break

for which in range(num,chapter,-1):
	dest = chapterName(which)
	src = chapterName(which-1)
	print(src,'->',dest)
	#os.rename(src,dest)
	os.system("git mv "+src+" "+dest)

os.system("em "+chapterName(chapter))
