Skip to content

Instantly share code, notes, and snippets.

@joaorbrandao
Created February 12, 2025 10:21
Show Gist options
  • Save joaorbrandao/d59f0cdee61c64265acaaf3cb0f8a891 to your computer and use it in GitHub Desktop.
Save joaorbrandao/d59f0cdee61c64265acaaf3cb0f8a891 to your computer and use it in GitHub Desktop.
Mac alias creator
#!/bin/bash
# This file receives the path to the parent folder that contains children folder to create alias for.
# Example add aliases to the ZSH file:
# > sh alias_creator.sh ~/dev ~/.zshrc
PARENT_FOLDER=$1
TARGET_FILE_TO_APPEND=$2
# Get all children folders from the given parent
CHILDREN_FOLDERS=$(ls $PARENT_FOLDER)
# Enter an empty line before adding the aliases
echo "\n" >> $TARGET_FILE_TO_APPEND
# Add the aliases to all folders to the target file
for child_folder in $CHILDREN_FOLDERS; do
echo "alias $child_folder=\"cd $PARENT_FOLDER/$child_folder\"" >> $TARGET_FILE_TO_APPEND
done
# Enter an empty line after adding the aliases
echo "\n" >> $TARGET_FILE_TO_APPEND
# Refresh the aliases file to make them available
source $TARGET_FILE_TO_APPEND
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment