-
Notifications
You must be signed in to change notification settings - Fork 9
/
keeporsweep.sh
executable file
Β·32 lines (28 loc) Β· 1.42 KB
/
keeporsweep.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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