Skip to content

Instantly share code, notes, and snippets.

@staeff
Last active August 29, 2015 14:14
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 staeff/41cade2144efefd1f5cf to your computer and use it in GitHub Desktop.
Save staeff/41cade2144efefd1f5cf to your computer and use it in GitHub Desktop.
Learn alias commands with a little quiz

Learn aliases with this little quiz app

This little word quiz lets you learn alias commands for your shell. Right now it only contains the alias defined by the "git" - plugin of oh-my-zsh.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
"""
Learn aliases
Parse a config file and extract the alias definitions into a dictionary.
Play a quiz with this data.
"""
MY_FILE = "zshgit.txt"
def generate_dictionary(raw_file, delimiter="="):
"""Parses alias definition in a config file into
a dictionary
"""
with open(raw_file, 'r') as f:
data = f.readlines()
dictionary = {}
for i in data:
k, v = i.split(delimiter,1)
dictionary[k]=v.strip("\n'")
return dictionary
def quiz(dictionary):
""" """
#welcome message
print("Learn Keyboard Shortcuts")
print("========================")
#the quiz will end when this variable becomes 'False'
playing = True
#While the game is running
while playing == True:
#set the score to 0
score = 0
#gets the number of questions the player wants to answer
num = int(input("\nHow many questions would you like: "))
#loop the correct number of times
for i in range(num):
#the question is one of the dictionary keys, picked at random
answer = (random.choice( list(dictionary.keys())))
#the answer is the string mapped to the question key
question = dictionary[answer]
#print the question, along with the question number
print("\n{0}").format(question)
#get the user's answer attempt
guess = raw_input("alias: ")
#if their guess is the same as the answer
if guess.lower() == answer.lower():
#add 1 to the score and print a message
print("Correct!")
score += 1
else:
print(("Nope! Correct answer: {0}").format(answer))
#after the quiz, print their final score
print("\nYour final score was " + str(score))
#store the user's input...
again = raw_input("Enter any key to play again, or 'q' to quit.")
#... and quit if they types 'q'
if again.lower() == 'q':
playing = False
def main():
data = generate_dictionary(MY_FILE, "=")
quiz(data)
if __name__ == "__main__":
main()
g='git'
gst='git status'
gd='git diff'
gdc='git diff --cached'
gl='git pull'
gup='git pull --rebase'
gp='git push'
gd='git diff'
gdt='git difftool'
gc='git commit -v'
gc!='git commit -v --amend'
gca='git commit -v -a'
gca!='git commit -v -a --amend'
gcmsg='git commit -m'
gco='git checkout'
gcm='git checkout master'
gr='git remote'
grv='git remote -v'
grmv='git remote rename'
grrm='git remote remove'
grset='git remote set-url'
grup='git remote update'
grbi='git rebase -i'
grbc='git rebase --continue'
grba='git rebase --abort'
gb='git branch'
gba='git branch -a'
gbr='git branch --remote'
gcount='git shortlog -sn'
gcl='git config --list'
gcp='git cherry-pick'
glg='git log --stat --max-count=10'
glgg='git log --graph --max-count=10'
glgga='git log --graph --decorate --all'
glo='git log --oneline --decorate --color'
glog='git log --oneline --decorate --color --graph'
gss='git status -s'
ga='git add'
gap='git add --patch'
gm='git merge'
grh='git reset HEAD'
grhh='git reset HEAD --hard'
gclean='git reset --hard && git clean -dfx'
gwc='git whatchanged -p --abbrev-commit --pretty=medium'
gcs='git commit -S'
gsps='git show --pretty=short --show-signature'
gts='git tag -s'
gvt='git verify-tag'
gpoat='git push origin --all && git push origin --tags'
gmt='git mergetool --no-prompt'
gg='git gui citool'
gga='git gui citool --amend'
gk='gitk --all --branches'
gsts='git stash show --text'
gsta='git stash'
gstp='git stash pop'
gstd='git stash drop'
grt='cd $(git rev-parse --show-toplevel || echo ".")'
gsr='git svn rebase'
gsd='git svn dcommit'
ggpull='git pull origin $(current_branch)'
ggpur='git pull --rebase origin $(current_branch)'
ggpush='git push origin $(current_branch)'
ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
glp="_git_log_prettily"
gwip='git add -A; git ls-files --deleted -z | xargs -r0 git rm; git commit -m "--wip--"'
gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
gignore='git update-index --assume-unchanged'
gunignore='git update-index --no-assume-unchanged'
gignored='git ls-files -v | grep "^[[:lower:]]"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment