Skip to content

Instantly share code, notes, and snippets.

@yatishbalaji
Last active January 14, 2021 12:29
Show Gist options
  • Select an option

  • Save yatishbalaji/f8454d9cef45e7fc7e7b2d2703ef764f to your computer and use it in GitHub Desktop.

Select an option

Save yatishbalaji/f8454d9cef45e7fc7e7b2d2703ef764f to your computer and use it in GitHub Desktop.
Create Alias to run any command on multiple directories. EG: Used for maintaining multiple git repositories by single command
export workspace=($HOME"/projects/project1" $HOME"/projects/project2");
export multiDirExec() {
for dir in ${workspace[@]}; do
echo 'Running >>>> '$dir ' >>>> ' $1 ;
(cd "$dir" && eval "$1");
done;
}
@yatishbalaji
Copy link
Author

yatishbalaji commented Jan 14, 2021

Use case

  • Execute command on all related at once
  • Keeping all Microservices repos in local with sync without going in each folder and run git pull
  • Raise PR for multiple projects at once
  • Sync all related projects at once like api/backend.
  • Running build script in multiple local repos at once
  • Run lint on all related projects

Usage

  • add above code in .zshrc or .bashrc
  • If you want to iterate though all folders in given dir use for dir in ~/projects/*;

Examples

  • Run multiDirExec "git remote update origin"
  • Run multiDirExec "git pull origin feat/gitlessons --rebase"
  • Run with alias (if your terminal supports it) multiDirExec "grupo"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment