Redo org-clean script
This commit is contained in:
parent
22a60691d2
commit
325255dc80
|
@ -1,28 +1,36 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
## Location where org-mode stores attachments
|
# A cleanup script for attachments in my org-mode notes.
|
||||||
ORG_DIR="$HOME/Dropbox/org/"
|
|
||||||
DATA_DIR="$ORG_DIR/.attach";
|
|
||||||
|
|
||||||
echo "The following files appear orphaned:";
|
ORG_DIR="$HOME/Dropbox/org"
|
||||||
|
ATTACH_DIR=".attach"
|
||||||
|
IFS=$'\n'
|
||||||
|
|
||||||
files=$(find "$DATA_DIR" -type f|perl -ne 'print "$1\n" if /([^\/]*)\/[^\/]*$/'|uniq|while read id; do grep -qiR --include "*.org" "$id" "$ORG_DIR" || find "$DATA_DIR" -ipath "*$id*" -type f; done)
|
attachment_dirs() {
|
||||||
|
find "$ORG_DIR" -iname "$ATTACH_DIR" -type d
|
||||||
|
}
|
||||||
|
|
||||||
echo "$files"
|
attachments_in_dir() {
|
||||||
|
cd "$1/../"
|
||||||
|
find ".attach" -type f
|
||||||
|
}
|
||||||
|
|
||||||
if [ "" == "$files" ]; then
|
is_orphaned_file() {
|
||||||
echo "Nothing to do!"
|
cd "$ORG_DIR"
|
||||||
exit
|
ag -Q "$1" >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" == "-n" ]; then
|
||||||
|
DRY_RUN=1
|
||||||
|
echo "Running dry run!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Delete? y/[n]"
|
for folder in $(attachment_dirs); do
|
||||||
read delete
|
cd "$folder"
|
||||||
case $delete in
|
for file in $(attachments_in_dir "$folder"); do
|
||||||
y)
|
if ! is_orphaned_file "$file"; then
|
||||||
echo "$files" | while read fn; do rm "$fn"; done
|
[ -z "$DRY_RUN" ] && rm -f "$file"
|
||||||
echo "Done."
|
echo "Deleted '$file'"
|
||||||
;;
|
fi
|
||||||
*)
|
done
|
||||||
echo "Not deleting anything!"
|
done
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
Loading…
Reference in a new issue