Skip to content

Commit

Permalink
support powershell as target shell
Browse files Browse the repository at this point in the history
  • Loading branch information
axzn committed Jun 18, 2020
1 parent d9af21c commit 91686c4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
*.pyc
gitfiti.sh
gitfiti.ps1
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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_.

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.

Expand All @@ -19,7 +19,7 @@ Included "art" from left to right: kitty, oneup, oneup2, hackerschool, octocat,
### Usage:
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.
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.

### User Templates
Expand Down
51 changes: 43 additions & 8 deletions gitfiti.py
Expand Up @@ -197,6 +197,10 @@ def is_empty_line(line):
'gliders': GLIDERS,
}

SHELLS = {
'bash': 'sh',
'powershell': 'ps1',
}

def load_images(img_names):
"""loads user images from given file(s)"""
Expand Down Expand Up @@ -303,16 +307,24 @@ def generate_values_in_date_order(image, multiplier=1):
yield image[h][w] * multiplier


def commit(commitdate):
template = (
def commit(commitdate, shell):
template_bash = (
'''GIT_AUTHOR_DATE={0} GIT_COMMITTER_DATE={1} '''
'''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())


def fake_it(image, start_date, username, repo, git_url, offset=0, multiplier=1):
template = (
def fake_it(image, start_date, username, repo, git_url, shell, offset=0, multiplier=1):
template_bash = (
'#!/usr/bin/env bash\n'
'REPO={0}\n'
'git init $REPO\n'
Expand All @@ -327,11 +339,28 @@ def fake_it(image, start_date, username, repo, git_url, offset=0, multiplier=1):
'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 = []
for value, date in zip(generate_values_in_date_order(image, multiplier),
generate_next_dates(start_date, offset)):
for _ in range(value):
strings.append(commit(date))
strings.append(commit(date, shell))

return template.format(repo, ''.join(strings), git_url, username)

Expand Down Expand Up @@ -413,12 +442,18 @@ def main():
git_url = 'git@github.com'
else:
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)

save(output, 'gitfiti.sh')
print('gitfiti.sh saved.')
output_filename = 'gitfiti.{}'.format(SHELLS[shell])
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))


Expand Down

0 comments on commit 91686c4

Please sign in to comment.