-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_aliases.sh
executable file
·42 lines (37 loc) · 1.14 KB
/
setup_aliases.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# This script sets up git aliases
# Usage: ./setup_aliases.sh [alias1 alias2 ...]
# If no aliases are provided, all aliases are set up
# Check the operating system
OS=$(uname)
# Install yq if not already installed
if ! command -v yq &> /dev/null
then
echo "yq could not be found, installing..."
if [ "$OS" == "Darwin" ]; then # Mac OS
brew install yq
elif [[ "$OS" == "MINGW64_NT"* ]]; then # Windows with MINGW64_NT prefix
winget install --id MikeFarah.yq
else
echo "Unsupported operating system. Please install yq manually."
exit 1
fi
fi
# Reminder to restart terminal
echo "Please restart your terminal to apply changes."
# Read aliases from YAML files and set them
if [ "$#" -eq 0 ]; then
for file in aliases/*.yml
do
alias=$(yq e '.alias' "$file")
command=$(yq e '.command' "$file")
git config --global alias.$alias "$command"
done
else
for alias_file in "$@"
do
alias=$(yq e '.alias' "aliases/${alias_file}.yml")
command=$(yq e '.command' "aliases/${alias_file}.yml")
git config --global alias.$alias "$command"
done
fi