From 8beb28b2b9601771add2bb1b23228b69a2271da7 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 3 Nov 2022 15:35:06 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=8A=20BREAKING:=20Use=20new=20XDG=20Ba?= =?UTF-8?q?se=20specification=20for=20state=20(#5)?= 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 breaking change for existing histories which need to be moved to the new directory if they made use of the old cache directory. Concurrent with this we are renaming `XDG_CACHE_LOCATION` environment variable to `XDG_HISTORY_LOCATION` so this is a second breaking change for those using a custom location for their histories. This change attempts to make the naming scheme coherent and remove some left-over naming cruft from the old location being the cache directory. This provides one of the larger changes to the program so far. Fixes #5. --- CHANGELOG.md | 6 ++++++ README.md | 8 ++++---- bemoji | 14 +++++++------- test/bemoji_cmds.bats | 4 ++-- test/bemoji_directories.bats | 16 ++++++++-------- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a65db0..c12113d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,12 @@ 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 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). +- (!) `XDG_CACHE_LOCATION` renamed to `XDG_HISTORY_LOCATION` to better signify its purpose diff --git a/README.md b/README.md index 185fb0a..bf6cef8 100644 --- a/README.md +++ b/README.md @@ -144,14 +144,14 @@ If you don't wish those to show up, make use of these options. ### Setting custom directories -By default bemoji stores your recent history in `$XDG_CACHE_HOME/bemoji-history.txt`, -so most often in `~/.cache/bemoji-history.txt` +By default bemoji stores your recent history in `$XDG_STATE_HOME/bemoji-history.txt`, +so most often in `~/.local/state/bemoji-history.txt` You can overwrite the directories bemoji uses for its emoji lists and history files with the following two environment variables: ``` BEMOJI_DB_LOCATION=/path/to/my/emoji/directory -BEMOJI_CACHE_LOCATION=/path/to/my/cache/directory +BEMOJI_HISTORY_LOCATION=/path/to/my/state/directory ``` There are no equivalent commandline arguments to overwrite these two settings. @@ -241,7 +241,7 @@ with their default settings ```bash BEMOJI_DB_LOCATION=$XDG_DATA_HOME/bemoji # where the emoji lists reside -BEMOJI_CACHE_LOCATION=$XDG_CACHE_HOME # where the cache file resides +BEMOJI_HISTORY_LOCATION=$XDG_STATE_HOME # where the state file resides BEMOJI_CUSTOM_LIST="" # the custom emoji list to display BEMOJI_DOWNLOAD_LIST="" # the default emoji lists to download to database BEMOJI_DEFAULT_COMMAND= # which command to invoke by default diff --git a/bemoji b/bemoji index 41dc8bc..a17597a 100755 --- a/bemoji +++ b/bemoji @@ -5,10 +5,10 @@ bm_version=0.2.0 bm_db_location=${BEMOJI_DB_LOCATION:-"${XDG_DATA_HOME:-$HOME/.local/share}/bemoji"} # Setting custom emoji list file location: # 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" +# Setting custom recent emoji history: +# BEMOJI_HISTORY_LOCATION=/path/to/my/recents/directory +bm_state_dir="${BEMOJI_HISTORY_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" @@ -57,7 +57,7 @@ while getopts ":f:D:tcenpPhv" o; do t) bm_cmds+=(_typer) ;; c) bm_cmds+=(_clipper) ;; e) bm_cmds+=(cat) ;; - n) bm_echo_newline=false;; + n) bm_echo_newline=false ;; D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;; p) bm_private_mode=true ;; P) bm_ignore_recent=true ;; @@ -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_cmds.bats b/test/bemoji_cmds.bats index 2b0a937..2d0f324 100644 --- a/test/bemoji_cmds.bats +++ b/test/bemoji_cmds.bats @@ -15,8 +15,8 @@ setup() { # set up small default set of test emoji for each test export BEMOJI_DB_LOCATION="$BATS_TEST_TMPDIR/database" - export BEMOJI_CACHE_LOCATION="$BATS_TEST_TMPDIR/cache" - mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_CACHE_LOCATION" + export BEMOJI_HISTORY_LOCATION="$BATS_TEST_TMPDIR/history" + mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_HISTORY_LOCATION" cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt" } diff --git a/test/bemoji_directories.bats b/test/bemoji_directories.bats index 28068e1..ede78a0 100644 --- a/test/bemoji_directories.bats +++ b/test/bemoji_directories.bats @@ -15,8 +15,8 @@ setup() { # set up small default set of test emoji for each test export BEMOJI_DB_LOCATION="$BATS_TEST_TMPDIR/database" - export BEMOJI_CACHE_LOCATION="$BATS_TEST_TMPDIR/cache" - mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_CACHE_LOCATION" + export BEMOJI_HISTORY_LOCATION="$BATS_TEST_TMPDIR/history" + mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_HISTORY_LOCATION" cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt" } @@ -38,8 +38,8 @@ 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" + unset BEMOJI_HISTORY_LOCATION + export XDG_STATE_HOME="$BATS_TEST_TMPDIR/xdb-cache" run bemoji -v assert_output --regexp " history=$BATS_TEST_TMPDIR/xdb-cache/bemoji-history.txt$" @@ -54,10 +54,10 @@ database=$HOME/.local/share/bemoji } @test "falls back to default history location if no XDG found" { - unset BEMOJI_CACHE_LOCATION + unset BEMOJI_HISTORY_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" { @@ -67,8 +67,8 @@ database=$BATS_TEST_TMPDIR/database " } -@test "BEMOJI_CACHE_LOCATION sets correct cache directory" { +@test "BEMOJI_HISTORY_LOCATION sets correct history directory" { run bemoji -v assert_output --regexp " -history=$BATS_TEST_TMPDIR/cache/bemoji-history.txt$" +history=$BATS_TEST_TMPDIR/history/bemoji-history.txt$" }