@@ -70,6 +70,43 @@ if [ ! -d "$TEMPLATE_DIR/hooks" ]; then
7070 exit 1
7171fi
7272
73+ # Function to sync global gitleaks config from repository
74+ function sync_global_config {
75+ # Determine the script directory (where .gitleaks.toml should be)
76+ local script_dir=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
77+ local source_config=" $script_dir /.gitleaks.toml"
78+
79+ # Determine the target config directory (handle sudo case)
80+ local config_dir=" $HOME /.config/gitleaks"
81+ if [ -n " $SUDO_USER " ]; then
82+ config_dir=$( eval echo ~ $SUDO_USER ) /.config/gitleaks
83+ fi
84+ local target_config=" $config_dir /gitleaks.toml"
85+
86+ # Check if source config exists
87+ if [ ! -f " $source_config " ]; then
88+ echo -e " ${WARNING} ⚠${NORMAL} Warning: Source config not found: $source_config "
89+ echo -e " ${HIGHLIGHT} →${NORMAL} Skipping config sync"
90+ return 1
91+ fi
92+
93+ # Create config directory if it doesn't exist
94+ mkdir -p " $config_dir " 2> /dev/null || {
95+ echo -e " ${ERROR} ✗${NORMAL} Failed to create config directory: $config_dir "
96+ return 1
97+ }
98+
99+ # Copy the config file
100+ if cp " $source_config " " $target_config " 2> /dev/null; then
101+ echo -e " ${SUCCESS} ✓${NORMAL} Synced global config: $target_config "
102+ return 0
103+ else
104+ echo -e " ${ERROR} ✗${NORMAL} Failed to sync config to: $target_config "
105+ return 1
106+ fi
107+ }
108+
109+
73110# Function to check if gitleaks is already in a file
74111function has_gitleaks {
75112 local file=" $1 "
@@ -473,6 +510,11 @@ if [ "$EUID" -eq 0 ]; then
473510 echo " "
474511fi
475512
513+ # Sync global gitleaks config from repository
514+ echo -e " ${HIGHLIGHT} Syncing global gitleaks configuration...${NORMAL} "
515+ sync_global_config
516+ echo " "
517+
476518if [ " $# " -eq 0 ]; then
477519 # No arguments provided - use smart defaults
478520 echo -e " ${HIGHLIGHT} No directory specified - using smart detection${NORMAL} \n"
0 commit comments