Created
May 2, 2019 13:18
-
-
Save cameron/7ca2537822d7674132846243555ef9a0 to your computer and use it in GitHub Desktop.
If git stash worked anywhere, but only on one file per directory...
This file contains 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/env zsh | |
# aspires to be git stash, everywhere (temporarily hide and unhide files/dirs) | |
# achieves less: hides a single file or directory by prefixing it with ".stashed-" | |
# (i.e., will not stash multiple files in the same dir at once) | |
if [[ -z "$1" ]]; then | |
echo "Need either a path or 'pop' as an argument" | |
exit 1 | |
fi | |
stashed=$(ls -a | grep "\.stashed-") | |
if [[ "$1" == "pop" ]]; then | |
# nb this means you can't stash files named 'pop' | |
if [[ -z "$stashed" ]]; then | |
echo "stash: nothing to pop"; | |
exit 1 | |
fi | |
mv $stashed $(echo $stashed | sed 's/.stashed-//') | |
exit | |
fi | |
if [[ ! -z "$stashed" ]]; then | |
echo "Cannot stash another file" | |
exit 1 | |
fi | |
mv "$1" "./.stashed-$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment