Created
March 1, 2024 16:08
-
-
Save icholy/afaf59a68848aca1bb08f6c46d45bbb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
# Set timeout to prevent the script from hanging | |
set timeout -1 | |
# Get the search pattern as a command line argument | |
if {[llength $argv] != 0} { | |
set pattern [lindex $argv 0] | |
} else { | |
puts "Error: search pattern not provided" | |
exit 1 | |
} | |
# Open the interaction with git add -p | |
spawn git add -p | |
# This is the main loop that handles the user interaction | |
expect { | |
# This expect block is for the hunk that contains the provided pattern | |
"*$pattern*Stage this hunk*" { | |
send "y\r" | |
exp_continue | |
} | |
# This expect block is for continuing to the next hunk | |
"*Stage this hunk*" { | |
send "n\r" | |
exp_continue | |
} | |
eof | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment