Genereate alias for each of the git folder in ~/Documents.
- Run the script
python3 alia_gen.py - 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 |