commit 6855d24e3a3393c124e18a4dacc5d007eb463a3a
parent 4a0bd8f1f48f7a4262c02c71cb2a658a3fb7084d
Author: Chris Down <chris@chrisdown.name>
Date: Tue, 24 Oct 2017 19:14:09 +0200
Prefer $XDG_RUNTIME_DIR for storage
Closes #51.
Diffstat:
4 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/clipmenu b/clipmenu
@@ -1,13 +1,13 @@
#!/bin/bash
: "${CM_LAUNCHER=dmenu}"
-: "${TMPDIR=/tmp}"
+: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
major_version=3
shopt -s nullglob
-cache_dir=$TMPDIR/clipmenu.$major_version.$USER
+cache_dir=$CM_DIR/clipmenu.$major_version.$USER
cache_file=$cache_dir/line_cache
if [[ $1 == --help ]] || [[ $1 == -h ]]; then
@@ -20,7 +20,7 @@ All arguments are passed through to dmenu itself.
Environment variables:
- $CM_LAUNCHER: specify a dmenu-compatible launcher (default: dmenu)
-- $TMPDIR: specify the base directory to store the cache dir in (default: /tmp)
+- $CM_DIR: specify the base directory to store the cache dir in (default: $XDG_RUNTIME_DIR, $TMPDIR, or /tmp)
EOF
exit 0
fi
diff --git a/clipmenud b/clipmenud
@@ -3,11 +3,11 @@
: "${CM_ONESHOT=0}"
: "${CM_OWN_CLIPBOARD=1}"
: "${CM_DEBUG=0}"
-: "${TMPDIR=/tmp}"
+: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
: "${CM_MAX_CLIPS=1000}"
major_version=3
-cache_dir=$TMPDIR/clipmenu.$major_version.$USER/
+cache_dir=$CM_DIR/clipmenu.$major_version.$USER/
cache_file=$cache_dir/line_cache
lock_file=$cache_dir/lock
lock_timeout=2
@@ -64,7 +64,7 @@ Environment variables:
- $CM_DEBUG: turn on debugging output (default: 0)
- $CM_OWN_CLIPBOARD: take ownership of the clipboard (default: 1)
- $CM_MAX_CLIPS: maximum number of clips to store, 0 for inf (default: 1000)
-- $TMPDIR: specify the base directory to store the cache dir in (default: /tmp)
+- $CM_DIR: specify the base directory to store the cache dir in (default: $XDG_RUNTIME_DIR, $TMPDIR, or /tmp)
EOF
exit 0
fi
diff --git a/tests/test-clipmenu b/tests/test-clipmenu
@@ -4,8 +4,10 @@ set -x
set -e
set -o pipefail
+: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
+
major_version=3
-dir=/tmp/clipmenu.$major_version.$USER
+dir=$CM_DIR/clipmenu.$major_version.$USER
cache_file=$dir/line_cache
if [[ $0 == /* ]]; then
diff --git a/tests/test-perf b/tests/test-perf
@@ -6,7 +6,9 @@ msg() {
printf '>>> %s\n' "$@" >&2
}
-dir=/tmp/clipmenu.$major_version.$USER
+: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
+
+dir=$CM_DIR/clipmenu.$major_version.$USER
cache_file=$dir/line_cache
log=$(mktemp)