Last active
April 15, 2024 05:15
-
-
Save inxilpro/88d8b192c4fbee8a1b54ee4196f3712c 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
nah() { | |
# Configuration | |
local cutoff_in_seconds=86400 # 1 day | |
# Stash our current changes, including untracked files | |
git stash save -u "<<nah - $(date +%s)>>" | |
# Get a list of all stashes that match our message format | |
IFS=$'\n' existing_stashes=($(git stash list | grep "<<nah - [0-9]*>>")) | |
# Iterate over stashes and drop stashes older than our cutoff | |
local current_time=$(date +%s) | |
for stash in "${existing_stashes[@]}"; do | |
local stash_name=$(echo $stash | cut -d ":" -f1) | |
local stash_time=$(echo $stash | grep -o "<<nah - [0-9]*>>" | grep -o "[0-9]*") | |
if [[ $stash_time =~ ^[0-9]+$ ]] && ((current_time - stash_time > cutoff_in_seconds)) ; then | |
git stash drop $stash_name | |
fi | |
done | |
} |
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
yah() { | |
# Get a list of all 'nah' stashes | |
IFS=$'\n' existing_stashes=($(git stash list | grep "<<nah - [0-9]*>>")) | |
if [ ${#existing_stashes[@]} -gt 0 ]; then | |
local most_recent_stash=$(echo ${existing_stashes[0]} | cut -d ":" -f1) | |
git stash apply $most_recent_stash | |
else | |
echo "No nah stashes found" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment