Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
keeporsweep.net/keeporsweep.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
32 lines (28 sloc)
1.42 KB
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
#!/bin/bash | |
# π»πποΈ Keep or Sweep | |
# Show a random file so you can clean your stuff | |
# Simply make executable and click (or run as bash keeporsweep.sh) | |
# http://keeporsweep.net | |
# Use the current folder for now, with optional argument for subfolder | |
FOLDER=$(pwd)/$1 | |
# Get a random file, ignoring hidden files | |
# https://askubuntu.com/questions/266179/how-to-exclude-ignore-hidden-files-and-directories-in-a-wildcard-embedded-find/749708#749708 | |
# "tr -d '\0'" gets rid of "command substitution: ignored null byte in input" | |
# https://stackoverflow.com/questions/46163678/get-rid-of-warning-command-substitution-ignored-null-byte-in-input/46163991#46163991 | |
RANDOMFILE=$(find "$FOLDER" -not -path '*/\.*' -type f -print0 | shuf -zn1 | tr -d '\0') | |
# Open file with relevant app, also checking for operating system | |
# https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux/17072017#17072017 | |
if [ "$(uname)" == "Darwin" ]; then | |
open "$RANDOMFILE" # macOS | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
xdg-open "$RANDOMFILE" # Linux | |
fi | |
# Ask for Keep or Sweep | |
# https://stackoverflow.com/questions/226703/how-do-i-prompt-for-yes-no-cancel-input-in-a-linux-shell-script/27875395#27875395 | |
echo "Keep or Sweep $RANDOMFILE?" | |
select ks in "Keep" "Sweep"; do | |
case $ks in | |
Keep ) echo "β KEPT $RANDOMFILE"; break;; | |
Sweep ) rm "$RANDOMFILE"; echo "β SWEPT $RANDOMFILE!"; exit;; | |
esac | |
done |