Skip to content

Instantly share code, notes, and snippets.

@yzhong52
Last active February 20, 2018 19:26
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 yzhong52/a69a8ff1c4e69b96c9a4636fbb37ae2e to your computer and use it in GitHub Desktop.
Save yzhong52/a69a8ff1c4e69b96c9a4636fbb37ae2e to your computer and use it in GitHub Desktop.
alias_gen.py

alias generation

Genereate alias for each of the git folder in ~/Documents.

  1. Run the script python3 alia_gen.py
  2. Add the following to .bash_profile
# Added by Yuchen: using alias!
if [ -f ~/.alias_gen ]; then 
    . ~/.alias_gen;
fi
import os, sys
import git
from pathlib import Path
alias_gen_file = Path.home().joinpath(".alias_gen") # ~/.alias_gen
sys.stdout=open(str(alias_gen_file), "w+")
print("#")
print("# Generated by alia-gen.py")
print("#")
for root, folders, files in os.walk("/Users/yuchen/Documents/"):
for folder in sorted(folders):
try:
_ = git.Repo(folder).git_dir # May throw
alias = ''.join(folder.split()).lower()
absolute_path=os.path.abspath(os.path.join(root, folder))
print('alias ' + alias + '="cd ' + absolute_path + '"')
except git.exc.InvalidGitRepositoryError:
print("# Skiping directory " + folder + "because it is not a git repo")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment