this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #3 from jacek-marchwicki/improve-git-identity

Small improvements in identity file

authored by

Łukasz Jan Niemier and committed by
GitHub
f2f96aec a612d0e1

+51 -7
+51 -7
bin/git-identity
··· 2 2 3 3 set -eo pipefail 4 4 5 - USAGE=<<EOF 6 - [-d|--define] <identity> <name> <email> 5 + USAGE=$(cat <<EOF 6 + | [-d|--define] <identity> <name> <email> 7 7 | [-p|--print] <identity> 8 8 | [-r|--remove] <identity> 9 9 | [-l|--list] 10 10 | [-R|--list-raw] 11 + | [-h|--help] 11 12 | <identity> 12 - EOF 13 + 14 + Define identity globally: 15 + git -d private "My Name Suername" me@example.com 16 + git -d company "My Name Suername" me@your-company.com 17 + 18 + Use identity in your git repository: 19 + cd your_repository 20 + git identity private 21 + 22 + List current identity: 23 + cd your_repository 24 + git identity private 25 + 26 + Print current identity: 27 + cd your_repository 28 + git identity 29 + 30 + EOF) 31 + 32 + error () { 33 + local message="$1" 34 + (>&2 echo "$message") 35 + exit 1 36 + } 13 37 14 38 lookup () { 15 39 local identity="$1" 16 40 local key="$2" 17 41 18 - git config "identity.$identity.$key" 42 + git config "identity.$identity.$key" || error "Unknown identity: $identity" 19 43 } 20 44 21 45 format_identity () { ··· 71 95 print_current_identity () { 72 96 local identity 73 97 74 - identity="$(git config user.identity)" 75 - 76 - echo "Current identity: $(format_identity "$identity")" 98 + identity="$(git config user.identity || echo "")" 99 + if [ "$identity" ]; then 100 + echo "Current identity: $(format_identity "$identity")" 101 + else 102 + (>&2 echo "=================================================") 103 + (>&2 echo -e "\033[0;31mNO IDENTITY SET\033[0m") 104 + (>&2 echo "Your name: $(git config user.name)") 105 + (>&2 echo "Your email: $(git config user.email)") 106 + (>&2 echo "=================================================") 107 + (>&2 echo "How to use this tool") 108 + (>&2 echo "${USAGE}") 109 + (>&2 echo "=================================================") 110 + exit 1 111 + fi 77 112 } 78 113 79 114 define_identity () { ··· 98 133 99 134 IDENTITY="$1" 100 135 136 + usage () { 137 + echo "${USAGE}" 138 + } 139 + 101 140 check_arguments () { 102 141 if [ "$1" -lt "$2" ]; then 103 142 usage ··· 127 166 -p|--print) 128 167 shift 129 168 print_raw_identity "$1" 169 + ;; 170 + 171 + -h|--help) 172 + shift 173 + usage 130 174 ;; 131 175 132 176 *) use_identity "$IDENTITY" ;;