.bashrc
changeset 937 a2beae97e3d8
parent 922 e2c60fd8f61b
child 945 d9232a82c55a
--- a/.bashrc	Mon Jan 13 14:00:42 2020 +0200
+++ b/.bashrc	Sat Jan 18 00:19:38 2020 +0200
@@ -251,15 +251,31 @@
   ag --nofilename --count -- "$1" | awk '{c += $1} END {print c}'
 }
 
-# "YYYY-MM-DD hh:mm:ss" or "hh:mm" for current day and random sec.
 mygit-date() {
-  if [[ "02:23" =~ ^[0-9]{2}:[0-9]{2}$ ]]; then
-      local sec=$(($RANDOM % 60))
-      if [[ ${#sec} = 1 ]]; then
-          sec=0$sec
-      fi
+  if [[ -n "$2" ]]; then
+    echo Provide only one arg.
+    return 1;
+  fi
+  local sec=$(($RANDOM % 60))
+  if [[ ${#sec} = 1 ]]; then
+      sec=0$sec
+  fi
+  if [[ "$1" =~ ^[0-9]{2}:[0-9]{2}$ ]]; then
       local yyyymmdd=`date +%F`
       set "$yyyymmdd $1:$sec"
+  elif [[ "$1" =~ ^[0-9]{2}' '[0-9]{2}:[0-9]{2}$ ]]; then
+      local yyyymm=`date +%Y-%m`
+      set "$yyyymm-$1:$sec"
+  elif [[ "$1" =~ ^[0-9]{2}-[0-9]{2}' '[0-9]{2}:[0-9]{2}$ ]]; then
+      local yyyy=`date +%Y`
+      set "$yyyy-$1:$sec"
+  elif [[ "$1" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}' '[0-9]{2}:[0-9]{2}$ ]]; then
+      set "$1:$sec"
+  elif [[ "$1" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}' '[0-9]{2}:[0-9]{2}:[0-9]{2}$ ]]; then
+      :
+  else
+    echo 'Unsupported format, try hh:mm, "dd hh:mm", "MM-dd hh:mm", "yyyy-MM-dd hh:mm", "yyyy-MM-dd hh:mm:ss"'
+    return 1;
   fi
   echo GIT_COMMITTER_DATE='"'"$1"'"' git commit --amend --no-edit --date '"'"$1"'"'
   GIT_COMMITTER_DATE="$1" git commit --amend --no-edit --date "$1"