dotfiles/system/.lyrical-git_mask

50 lines
1.9 KiB
Bash

#!/bin/bash
declare -A user1=([name]='Alexander Hosking' [email]='alexander@ahosking.com')
declare -A user2=([name]='Kim Martin' [email]='kim@lyricalsecurity.com')
declare -A user3=([name]='Dillon Zhang' [email]='Dillon@lyricalsecurity.com')
declare -A user4=([name]='Pam Moire' [email]='pam@lyricalsecurity.com')
declare -A user5=([name]='Mitch Warren' [email]='mitch@lyricalsecurity.com')
declare -A user6=([name]='James Webster' [email]='james@lyricalsecurity.com')
declare -A user7=([name]='Caroline Marcoux' [email]='caroline@lyricalsecurity.com')
declare -A user8=([name]='Renato Streefkerk' [email]='renato@lyricalsecurity.com')
users=(user1 user2 user3 user4 user5 user6 user7 user8)
#echo $RANDO ## DEBUG
##Print the bits from the array index of random number
function git_mask() {
if [ -z "$1" ]
then
RANDO=$(( ( RANDOM % ${#users[@]} ) )) ## Generate a random index from the users array
for arr_name in "${users[$RANDO]}"; do
declare -n arr_ref="$arr_name"
printf "git config user.name \"%s\"\n" "${arr_ref[name]}"
printf "git config user.email \"%s\"\n" "${arr_ref[email]}"
set_username="git config user.name \"${arr_ref[name]}\" --replace-all"
eval $set_username
set_email="git config user.email \"${arr_ref[email]}\" --replace-all"
eval $set_email
done
else
if [[ ! $1 =~ [0-9] ]] || ([[ $1 -gt ${#users[@]} ]] || [[ $1 -le 0 ]]); then
printf "Please enter a valid number from 1 to %s\n" "${#users[@]}"
else
user_id="$(($1 - 1))"
for arr_name in "${users[$user_id]}"; do
declare -n arr_ref="$arr_name"
printf "Your git profile is now: \"%s\"\n" "${arr_ref[name]}"
set_username="git config user.name \"${arr_ref[name]}\" --replace-all"
eval $set_username
set_email="git config user.email \"${arr_ref[email]}\" --replace-all"
eval $set_email
done
fi
fi
}