Skip to content

Instantly share code, notes, and snippets.

@yzhong52

yzhong52/Readme.md

Last active Feb 20, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.