From 250fb36146de526d9bda079edbadb46f586c706c Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 12 Oct 2022 16:56:15 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8!=20Use=20new=20XDG=20Base=20specifica?= =?UTF-8?q?tion=20for=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switched the history from using the XDG_CACHE_HOME directory by default to use XDG_STATE_HOME by default. This makes sense since cache can (and should be prepared to) be wiped at any moment and the program functionality should not be hindered by this. Since we need to retain history through such wipes the newly introduced state directory is the perfect match for keeping the history file in. This does constitute a small breaking change for existing histories which need to be moved to the new directory if they made use of the old cache directory. Fixes #5. --- CHANGELOG.md | 5 +++++ bemoji | 8 ++++---- test/bemoji_directories.bats | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a65db0..fa7651c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Multiple command options can be combined +- History uses `XDG_STATE_HOME` directory by default: + This constitutes a slight break in behavior if you relied a lot on your pick history in the + default location. To retain your old history file, simply move it from the old cache directory + (`~/.cache/bemoji-history.txt` by default) to the new one (`~/.local/state/bemoji-history.txt` + by default). diff --git a/bemoji b/bemoji index 41dc8bc..2f01647 100755 --- a/bemoji +++ b/bemoji @@ -7,8 +7,8 @@ bm_db_location=${BEMOJI_DB_LOCATION:-"${XDG_DATA_HOME:-$HOME/.local/share}/bemoj # BEMOJI_CUSTOM_LIST=/my/location/emojis.txt # Setting custom recent emoji cache: # BEMOJI_CACHE_LOCATION=/path/to/my/recents/directory -bm_cache_dir="${BEMOJI_CACHE_LOCATION:-${XDG_CACHE_HOME:-$HOME/.cache}}" -bm_history_file="${bm_cache_dir}/bemoji-history.txt" +bm_state_dir="${BEMOJI_CACHE_LOCATION:-${XDG_STATE_HOME:-$HOME/.local/state}}" +bm_history_file="${bm_state_dir}/bemoji-history.txt" # Command to run after user chooses an emoji bm_default_cmd="$BEMOJI_DEFAULT_CMD" @@ -135,8 +135,8 @@ get_most_recent() { add_to_recent() { if [ -z "$1" ]; then return; fi - if [ ! -d "$bm_cache_dir" ]; then - mkdir -p "$bm_cache_dir" + if [ ! -d "$bm_state_dir" ]; then + mkdir -p "$bm_state_dir" fi echo "$1" >>"$bm_history_file" } diff --git a/test/bemoji_directories.bats b/test/bemoji_directories.bats index 28068e1..5438536 100644 --- a/test/bemoji_directories.bats +++ b/test/bemoji_directories.bats @@ -39,7 +39,7 @@ database=$BATS_TEST_TMPDIR/xdb-db/bemoji @test "sets XDG directory for history by default" { unset BEMOJI_CACHE_LOCATION - export XDG_CACHE_HOME="$BATS_TEST_TMPDIR/xdb-cache" + export XDG_STATE_HOME="$BATS_TEST_TMPDIR/xdb-cache" run bemoji -v assert_output --regexp " history=$BATS_TEST_TMPDIR/xdb-cache/bemoji-history.txt$" @@ -57,7 +57,7 @@ database=$HOME/.local/share/bemoji unset BEMOJI_CACHE_LOCATION run bemoji -v assert_output --regexp " -history=$HOME/.cache/bemoji-history.txt$" +history=$HOME/.local/state/bemoji-history.txt$" } @test "BEMOJI_DB_LOCATION sets correct db directory" {