From: W. Trevor King Date: Tue, 1 Feb 2011 15:14:31 +0000 (-0500) Subject: Add cache-file post. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d6e696aac7fa7751eeeb892b241e210580cb3982;p=blog.git Add cache-file post. --- diff --git a/posts/cache-file.mdwn b/posts/cache-file.mdwn new file mode 100644 index 0000000..c2c1ecf --- /dev/null +++ b/posts/cache-file.mdwn @@ -0,0 +1,19 @@ +[[cache-file.sh]] is a [[bash]] script to make it easy to sort +pictures using [pqiv][]. If you place `cache-file.sh` in your path, +and add + + -1 "cache-file.sh saves" + -2 "cache-file.sh trash" + +to `~/.pqivrc`, you can move the current picture to `.cache-saves/` or +`.cache-trash/` by pressing 1 or 2 respectively. The `.cache-*/` +directory is in the same directory as the image file, and will be +created if it doesn't exist. + +Not very complicated, but useful for quickly removing +almost-duplicates, blurry pictures, etc. + +[pqiv]: http://www.pberndt.com/Programme/Linux/pqiv + +[[!tag tags/bash]] +[[!tag tags/programming]] diff --git a/posts/cache-file/cache-file.sh b/posts/cache-file/cache-file.sh new file mode 100755 index 0000000..0f3f310 --- /dev/null +++ b/posts/cache-file/cache-file.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# +# Something along the lines of qiv's .qiv-save and .qiv-trash for pqiv. +# +# Copyright (C) 2010 W. Trevor King +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# +# usage: cache-file.sh TAG FILE + +PREFIX=".cache-" +TAG="$1" +FILE="$2" + +if [ ! -e "$FILE" ]; then + echo "'$FILE' doesn't exist" >&2 + exit 1 +fi +FILE_DIR=$(dirname $FILE) +if [ ! -d "$FILE_DIR" ]; then + echo "'$FILE' not in a directory" >&2 + exit 1 +fi + +CACHE_DIR="$FILE_DIR/$PREFIX$TAG" + +if [ ! -d "$CACHE_DIR" ]; then + if [ -e "$CACHE_DIR" ]; then + echo "'$CACHE_DIR' exists, but is not a directory" + exit 1 + fi + mkdir "$CACHE_DIR" +fi + +mv "$FILE" "$CACHE_DIR" + +echo "moved '$FILE' to '$CACHE_DIR'"