-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-alias
executable file
·52 lines (42 loc) · 1.44 KB
/
git-alias
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
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Copyright (c) 2019 Benjamin Holt -- MIT License
if [ "$1" == "-h" -o "$1" == "--help" ]; then
cat <<USAGE
usage: git alias Prints existing git aliases
git alias A 'C' Set alias A to command C
git alias --unset A Unset alias A
git alias -s|--script Prints git aliases as a script for reproducing
them in a new environment
git alias -h|--help Print this message and exit
Note: this always sets and unsets aliases in the global scope
USAGE
exit 0
fi
# Bold=`tput bold`
# Off=`tput sgr0`
if [ "$1" == "-s" -o "$1" == "--script" ]; then
# Print as a script
echo "#!/bin/sh"
git config --list | grep alias | sed -e $'s/\([^=]*\)=\(.*\)/git config --global \\1 \'\\2\'/'
exit 0
fi
if [ "$1" == "-u" -o "$1" == "--unset" ]; then
if [ $# != 2 ]; then
echo "error: missing alias to unset; run 'git alias -h' for help"
exit 1
fi
# Set an alias
git config --list | grep "alias.$2=" | sed -e $'s/alias\.\([^=]*\)=\(.*\)/Unsetting \\1 = \'\\2\'/' # -e "s/\(.*\)/$Bold\\1$Off/"
git config --global --unset "alias.$2"
exit 0
fi
if [ $# == 2 ]; then
# Set an alias
# echo "${Bold}Setting $1 = '$2'${Off}"
echo "Setting $1 = '$2'"
git config --global "alias.$1" "$2"
exit 0
fi
# Else, print in a nice format
git config --list | grep alias | sed -e $'s/alias\.\([^=]*\)=\(.*\)/\\1 = \'\\2\'/' | sort
###