Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Last active April 15, 2024 05:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inxilpro/88d8b192c4fbee8a1b54ee4196f3712c to your computer and use it in GitHub Desktop.
Save inxilpro/88d8b192c4fbee8a1b54ee4196f3712c to your computer and use it in GitHub Desktop.
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
}
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