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" {