-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlessrm
executable file
·44 lines (39 loc) · 1017 Bytes
/
lessrm
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
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
source "$(dirname "$0")/lib/common.sh"
function do_one() {
FILE_NAME="$1"
if [[ ! -e "$FILE_NAME" ]]; then
echo >&2 "no such file :$FILE_NAME"
return
fi
set -e
if [[ "$(file --mime-type "$FILE_NAME" | awk '{print $NF}')" == "image/"* ]]; then
if is_installed ~/.iterm2/imgcat ; then
~/.iterm2/imgcat "$FILE_NAME"
else
echo "$FILE is an image, but imgcat isn't available"
return
fi
else
vim -R "$FILE_NAME"
fi
while [[ true ]]; do
read -p "rm $FILE_NAME? " SHOULD_DELETE
if [[ "$SHOULD_DELETE" == 'yes' || "$SHOULD_DELETE" == 'y' ]]; then
rm "$FILE_NAME"
return
elif [[ "$SHOULD_DELETE" == 'no' || "$SHOULD_DELETE" == 'n' ]]; then
return
else
echo 'Please enter "yes" or "no".'
fi
done
}
if [[ -z "$1" ]]; then
echo 1>&2 "Usage $(basename "$0") <file>"
echo 1>&2 "Opens the given file with less, and then prompts you if you want to delete it."
exit 1
fi
for f in "$@"; do
do_one "$f"
done