mirror of
https://github.com/The-Repo-Club/DotFiles.git
synced 2024-12-01 03:38:28 -05:00
64 lines
1.5 KiB
Plaintext
64 lines
1.5 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
|
||
|
#------------------------------------------------------------------------------
|
||
|
# Path - /usr/bin/genbatchnumber
|
||
|
# GitHub - https://github.com/The-Repo-Club/
|
||
|
# Author - The-Repo-Club [wayne6324@gmail.com]
|
||
|
# Start On - Sun 31 Oct 00:28:58 BST 2021
|
||
|
# Modified On - Sun 31 Oct 00:28:58 BST 2021
|
||
|
#------------------------------------------------------------------------------
|
||
|
|
||
|
date_flag=
|
||
|
|
||
|
genbatchnumber() {
|
||
|
configFolder=$HOME/.cache/genbatchnumber
|
||
|
configFile=$configFolder/date.ini
|
||
|
[ -d $configFolder ] || mkdir $configFolder
|
||
|
[[ -f $configFile ]] && . $configFile
|
||
|
|
||
|
if [ -z "$Batch" ]; then
|
||
|
num=1
|
||
|
else
|
||
|
if [ "$date" -eq "$Date" ]; then
|
||
|
num=`expr $Batch + 1`
|
||
|
else
|
||
|
num=1
|
||
|
fi
|
||
|
fi
|
||
|
batch="HM$date-$num"
|
||
|
|
||
|
if [ -z "$Date" ] || [ -z "$Batch" ]; then
|
||
|
printf "%s \n" "$batch"
|
||
|
echo -e "Date=${date}\nBatch=${num}" > $configFile
|
||
|
else
|
||
|
if [ "$date" -eq "$Date" ]; then
|
||
|
printf "%s \n" "$batch"
|
||
|
echo -e "Date=${date}\nBatch=${num}" > $configFile
|
||
|
else
|
||
|
printf "%s \n" "$batch"
|
||
|
echo -e "Date=${date}\nBatch=${num}" > $configFile
|
||
|
fi
|
||
|
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
while true; do
|
||
|
case $1 in
|
||
|
-d|--date)
|
||
|
date_flag=1
|
||
|
shift
|
||
|
;;
|
||
|
*)
|
||
|
break
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
if [[ "$date_flag" ]]; then
|
||
|
date=$(date -d $@ +%j%y)
|
||
|
genbatchnumber "$date"
|
||
|
else
|
||
|
date=$(date -d $(date +%Y-%m-%d) +%j%y)
|
||
|
genbatchnumber "$date"
|
||
|
fi
|