From 6855d24e3a3393c124e18a4dacc5d007eb463a3a Mon Sep 17 00:00:00 2001 From: Chris Down Date: Tue, 24 Oct 2017 19:14:09 +0200 Subject: [PATCH] Prefer $XDG_RUNTIME_DIR for storage Closes #51. --- clipmenu | 6 +++--- clipmenud | 6 +++--- tests/test-clipmenu | 4 +++- tests/test-perf | 4 +++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/clipmenu b/clipmenu index 9c67c8c..51058a6 100755 --- 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 index 2fc2fde..3997819 100755 --- 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 index 43af5d5..c7e89eb 100755 --- 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 index a393de6..bb2a5c2 100755 --- 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)