Skip to content

martin-lechene/anti-friday-push

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anti push on Friday

To automatically replace the git push command with your custom script, you can use aliases or shell functions in your environment. Here's how to do it for Linux and Windows:


For Linux (Bash)

  1. Add an alias in your shell configuration file:

    • Open your shell configuration file (~/.bashrc, ~/.zshrc, or ~/.bash_profile depending on your shell).
    • Add the following function at the end of the file:
       git() {
          if [ "$1" = "push" ]; then
             DAY_OF_WEEK=$(date +%u)  # Get the day of the week (1 = Monday, 7 = Sunday)
             if [ "$DAY_OF_WEEK" -eq 5 ]; then  # Check if it's Friday (5)
                   read -p "Are you sure you want to push on a Friday? (y/n) " -n 1 -r
                   echo
                   if [[ ! $REPLY =~ ^[Yy]$ ]]; then
                      echo "Push cancelled."
                      return 1
                   fi
             fi
          fi
          command git "$@"  # Execute the original git command
       }
  2. Reload the shell configuration:

    • Execute the following command to apply the changes:
          source ~/.bashrc  # or ~/.zshrc depending on your shell
  3. Usage:

    • Now, when you type git push, the script will automatically check if it's Friday and ask for confirmation if necessary.

For Windows (PowerShell)

  1. Create a function in your PowerShell profile:

    • Open your PowerShell profile by running the following command:
       notepad $PROFILE
    • If the file doesn't exist, PowerShell will prompt you to create it. Accept the prompt.
  2. Add the following function:

    • Paste this code into the file:
       function git {
          if ($args[0] -eq "push") {
             $DayOfWeek = (Get-Date).DayOfWeek.value__  # Get the day of the week (1 = Monday, 7 = Sunday)
             if ($DayOfWeek -eq 5) {  # Check if it's Friday (5)
                   $confirmation = Read-Host "Are you sure you want to push on a Friday? (y/n)"
                   if ($confirmation -ne "y") {
                      Write-Host "Push cancelled."
                      return
                   }
             }
          }
          # Execute the original git command
          & (Get-Command git -CommandType Application) @args
       }
  3. Reload the PowerShell profile:

    • Execute the following command to apply the changes:
          . $PROFILE
  4. Usage:

    • Now, when you type git push in PowerShell, the script will automatically check if it's Friday and ask for confirmation if necessary.

For Windows (CMD)

If you're using the traditional command prompt (cmd.exe), you can create an alias using a trick with doskey.

  1. Create an alias:

    • Open cmd.exe and run the following command to create an alias:
          doskey git=git-wrapper.bat $*
  2. Create a git-wrapper.bat script:

    • Create a git-wrapper.bat file in an accessible directory (e.g., C:\Scripts) with the following content:
       @echo off
       setlocal
    
       if "%1"=="push" (
          for /f "tokens=2 delims==" %%I in ('"wmic path win32_localtime get dayofweek /value"') do set DAY_OF_WEEK=%%I
          if "%DAY_OF_WEEK%"=="5" (
             set /p CONFIRM=Are you sure you want to push on a Friday? (y/n)
             if /i not "%CONFIRM%"=="y" (
                   echo Push cancelled.
                   exit /b 1
             )
          )
       )
    
       :: Execute the original git command
       git %*
  3. Add the script directory to your PATH:

    • Add the directory containing git-wrapper.bat (e.g., C:\Scripts) to your PATH environment variable.
  4. Usage:

    • Now, when you type git push in cmd.exe, the script will automatically check if it's Friday and ask for confirmation if necessary.

Notes

  • Linux: The method with an alias in the shell configuration file is clean and portable.
  • Windows: PowerShell is recommended for better integration and flexibility.
  • These solutions seamlessly replace the git push command without requiring you to type a custom script.

Remember to test in a safe environment before using it in production!

About

System for anti-push for specified date : Friday.

Topics

Resources

License

Stars

Watchers

Forks

Languages