Merge pull request #74 from axzn/powershell-support
Support Powershell as target shell
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,2 +1,3 @@ | |||||||
| *.pyc | *.pyc | ||||||
| gitfiti.sh | gitfiti.sh | ||||||
|  | gitfiti.ps1 | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ An example of gitfiti in the wild: | |||||||
|  |  | ||||||
| `gitfiti.py` is a tool I wrote to decorate your github account's commit history calendar by (blatantly) abusing git's ability to accept commits _in the past_. | `gitfiti.py` is a tool I wrote to decorate your github account's commit history calendar by (blatantly) abusing git's ability to accept commits _in the past_. | ||||||
|  |  | ||||||
| How?  `gitfiti.py` generates a bash script: `gitfiti.sh` that makes commits with the GIT_AUTHOR_DATE and GIT_COMMITTER_DATE environment variables set for each targeted pixel. | How?  `gitfiti.py` generates a script that makes commits with the GIT_AUTHOR_DATE and GIT_COMMITTER_DATE environment variables set for each targeted pixel. | ||||||
|  |  | ||||||
| Since this is likely to clobber repo's history, I highly recommend that you create a _new_ github repo when using gitfiti. Also, the generated bash script assumes you are using public-key authentication with git. | Since this is likely to clobber repo's history, I highly recommend that you create a _new_ github repo when using gitfiti. Also, the generated bash script assumes you are using public-key authentication with git. | ||||||
|  |  | ||||||
| @ -19,7 +19,7 @@ Included "art" from left to right: kitty, oneup, oneup2, hackerschool, octocat, | |||||||
| ### Usage: | ### Usage: | ||||||
| 1. Create a new github repo to store your handiwork. | 1. Create a new github repo to store your handiwork. | ||||||
| 2. Run `gitfiti.py` and follow the prompts for username, art selection, offset, and repo name. | 2. Run `gitfiti.py` and follow the prompts for username, art selection, offset, and repo name. | ||||||
| 3. Run the generated `gitfiti.sh` from your home directory (or any non-git tracked dir) and watch it go to work. | 3. Run the generated `gitfiti.sh` or `gitfiti.ps1` from your home directory (or any non-git tracked dir) and watch it go to work. | ||||||
| 4. Wait... Seriously, you'll probably need to wait a day or two for the gitfiti to show in your commit graph. | 4. Wait... Seriously, you'll probably need to wait a day or two for the gitfiti to show in your commit graph. | ||||||
|  |  | ||||||
| ### User Templates | ### User Templates | ||||||
|  | |||||||
							
								
								
									
										51
									
								
								gitfiti.py
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								gitfiti.py
									
									
									
									
									
								
							| @ -197,6 +197,10 @@ IMAGES = { | |||||||
|   'gliders': GLIDERS, |   'gliders': GLIDERS, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | SHELLS = { | ||||||
|  |   'bash': 'sh', | ||||||
|  |   'powershell': 'ps1', | ||||||
|  | } | ||||||
|  |  | ||||||
| def load_images(img_names): | def load_images(img_names): | ||||||
|     """loads user images from given file(s)""" |     """loads user images from given file(s)""" | ||||||
| @ -303,16 +307,24 @@ def generate_values_in_date_order(image, multiplier=1): | |||||||
|             yield image[h][w] * multiplier |             yield image[h][w] * multiplier | ||||||
|  |  | ||||||
|  |  | ||||||
| def commit(commitdate): | def commit(commitdate, shell): | ||||||
|     template = ( |     template_bash = ( | ||||||
|         '''GIT_AUTHOR_DATE={0} GIT_COMMITTER_DATE={1} ''' |         '''GIT_AUTHOR_DATE={0} GIT_COMMITTER_DATE={1} ''' | ||||||
|         '''git commit --allow-empty -m "gitfiti" > /dev/null\n''' |         '''git commit --allow-empty -m "gitfiti" > /dev/null\n''' | ||||||
|     ) |     ) | ||||||
|  |      | ||||||
|  |     template_powershell = ( | ||||||
|  |         '''$Env:GIT_AUTHOR_DATE="{0}"\n$Env:GIT_COMMITTER_DATE="{1}"\n''' | ||||||
|  |         '''git commit --allow-empty -m "gitfiti" | Out-Null\n''' | ||||||
|  |     ) | ||||||
|  |  | ||||||
|  |     template = template_bash if shell == 'bash' else template_powershell | ||||||
|  |  | ||||||
|     return template.format(commitdate.isoformat(), commitdate.isoformat()) |     return template.format(commitdate.isoformat(), commitdate.isoformat()) | ||||||
|  |  | ||||||
|  |  | ||||||
| def fake_it(image, start_date, username, repo, git_url, offset=0, multiplier=1): | def fake_it(image, start_date, username, repo, git_url, shell, offset=0, multiplier=1): | ||||||
|     template = ( |     template_bash = ( | ||||||
|         '#!/usr/bin/env bash\n' |         '#!/usr/bin/env bash\n' | ||||||
|         'REPO={0}\n' |         'REPO={0}\n' | ||||||
|         'git init $REPO\n' |         'git init $REPO\n' | ||||||
| @ -327,11 +339,28 @@ def fake_it(image, start_date, username, repo, git_url, offset=0, multiplier=1): | |||||||
|         'git push -u origin master\n' |         'git push -u origin master\n' | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |     template_powershell = ( | ||||||
|  |         'cd $PSScriptRoot\n' | ||||||
|  |         '$REPO="{0}"\n' | ||||||
|  |         'git init $REPO\n' | ||||||
|  |         'cd $REPO\n' | ||||||
|  |         'New-Item README.md -ItemType file | Out-Null\n' | ||||||
|  |         'git add README.md\n' | ||||||
|  |         'New-Item gitfiti -ItemType file | Out-Null\n' | ||||||
|  |         'git add gitfiti\n' | ||||||
|  |         '{1}\n' | ||||||
|  |         'git remote add origin {2}:{3}/$REPO.git\n' | ||||||
|  |         'git pull origin master\n' | ||||||
|  |         'git push -u origin master\n' | ||||||
|  |     ) | ||||||
|  |  | ||||||
|  |     template = template_bash if shell == 'bash' else template_powershell | ||||||
|  |  | ||||||
|     strings = [] |     strings = [] | ||||||
|     for value, date in zip(generate_values_in_date_order(image, multiplier), |     for value, date in zip(generate_values_in_date_order(image, multiplier), | ||||||
|             generate_next_dates(start_date, offset)): |             generate_next_dates(start_date, offset)): | ||||||
|         for _ in range(value): |         for _ in range(value): | ||||||
|             strings.append(commit(date)) |             strings.append(commit(date, shell)) | ||||||
|  |  | ||||||
|     return template.format(repo, ''.join(strings), git_url, username) |     return template.format(repo, ''.join(strings), git_url, username) | ||||||
|  |  | ||||||
| @ -413,12 +442,18 @@ def main(): | |||||||
|         git_url = 'git@github.com' |         git_url = 'git@github.com' | ||||||
|     else: |     else: | ||||||
|         git_url = request_user_input('Enter Git URL like git@site.github.com: ') |         git_url = request_user_input('Enter Git URL like git@site.github.com: ') | ||||||
|  |          | ||||||
|  |     shell = '' | ||||||
|  |     while shell not in SHELLS.keys():  | ||||||
|  |         shell = request_user_input( | ||||||
|  |             'Enter the target shell ({}): '.format(' or '.join(SHELLS.keys()))) | ||||||
|  |  | ||||||
|     output = fake_it(image, start_date, username, repo, git_url, offset, |     output = fake_it(image, start_date, username, repo, git_url, shell, offset, | ||||||
|                      fake_it_multiplier) |                      fake_it_multiplier) | ||||||
|  |  | ||||||
|     save(output, 'gitfiti.sh') |     output_filename = 'gitfiti.{}'.format(SHELLS[shell]) | ||||||
|     print('gitfiti.sh saved.') |     save(output, output_filename) | ||||||
|  |     print('{} saved.'.format(output_filename)) | ||||||
|     print('Create a new(!) repo named {0} at {1} and run the script'.format(repo, git_base)) |     print('Create a new(!) repo named {0} at {1} and run the script'.format(repo, git_base)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user