From 61ce618ed735145179b6fcd4887c3f2a75cdcbe9 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Mon, 21 Dec 2020 13:09:49 +0100 Subject: [PATCH] use xdg cache paths - should fix permission errors --- scripts/hooks.sh | 6 ++++-- scripts/reshctl.sh | 7 ++++--- scripts/shellrc.sh | 2 ++ scripts/util.sh | 26 ++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/scripts/hooks.sh b/scripts/hooks.sh index ff57610..cbe7b88 100644 --- a/scripts/hooks.sh +++ b/scripts/hooks.sh @@ -16,11 +16,12 @@ __resh_preexec() { # core __RESH_COLLECT=1 __RESH_CMDLINE="$1" # not local to preserve it for postcollect (useful as sanity check) + local tmp_file="$__RESH_XDG_CACHE_HOME/collect_last_run_out.txt" __resh_collect --cmdLine "$__RESH_CMDLINE" \ --recall-actions "$__RESH_HIST_RECALL_ACTIONS" \ --recall-strategy "$__RESH_HIST_RECALL_STRATEGY" \ --recall-last-cmdline "$__RESH_HIST_PREV_LINE" \ - >| /tmp/resh_collect_last_run_out.txt 2>&1 || echo "resh-collect ERROR: $(head -n 1 /tmp/resh_collect_last_run_out.txt)" + >| $tmp_file 2>&1 || echo "resh-collect ERROR: $(head -n 1 $tmp_file)" } # used for collect and collect --recall @@ -153,6 +154,7 @@ __resh_precmd() { fi fi if [ "$__RESH_VERSION" = "$(resh-postcollect -version)" ] && [ "$__RESH_REVISION" = "$(resh-postcollect -revision)" ]; then + local tmp_file="$__RESH_XDG_CACHE_HOME/postcollect_last_run_out.txt" resh-postcollect -requireVersion "$__RESH_VERSION" \ -requireRevision "$__RESH_REVISION" \ -cmdLine "$__RESH_CMDLINE" \ @@ -169,7 +171,7 @@ __resh_precmd() { -gitRemoteExitCodeAfter "$__RESH_GIT_REMOTE_EXIT_CODE_AFTER" \ -realtimeAfter "$__RESH_RT_AFTER" \ -timezoneAfter "$__RESH_TZ_AFTER" \ - >| /tmp/resh_postcollect_last_run_out.txt 2>&1 || echo "resh-postcollect ERROR: $(head -n 1 /tmp/resh_postcollect_last_run_out.txt)" + >| $tmp_file 2>&1 || echo "resh-postcollect ERROR: $(head -n 1 $tmp_file)" fi __resh_reset_variables fi diff --git a/scripts/reshctl.sh b/scripts/reshctl.sh index 44200b0..6a5f9df 100644 --- a/scripts/reshctl.sh +++ b/scripts/reshctl.sh @@ -121,9 +121,10 @@ resh() { elif [ $status_code = 130 ]; then true else - echo "$buffer" >| ~/.resh/cli_last_run_out.txt + local tmp_file="$__RESH_XDG_CACHE_HOME/search_last_run_out.txt" + echo "$buffer" >| "$tmp_file" echo "resh-cli ERROR:" - cat ~/.resh/cli_last_run_out.txt + cat "$tmp_file" fi } @@ -216,4 +217,4 @@ reshctl() { return "$_status" ;; esac -} \ No newline at end of file +} diff --git a/scripts/shellrc.sh b/scripts/shellrc.sh index 7b55f9b..8200d7e 100644 --- a/scripts/shellrc.sh +++ b/scripts/shellrc.sh @@ -69,6 +69,8 @@ export __RESH_VERSION=$(resh-collect -version) # shellcheck disable=2155 export __RESH_REVISION=$(resh-collect -revision) +__resh_set_xdg_home_paths + __resh_run_daemon # block for anything we only want to do once per session diff --git a/scripts/util.sh b/scripts/util.sh index 02637d5..12b3f64 100644 --- a/scripts/util.sh +++ b/scripts/util.sh @@ -163,3 +163,29 @@ __resh_session_init() { >| ~/.resh/session_init_last_run_out.txt 2>&1 || echo "resh-session-init ERROR: $(head -n 1 ~/.resh/session_init_last_run_out.txt)" fi } + +__resh_set_xdg_home_paths() { + if [ -z "${XDG_CONFIG_HOME-}" ]; then + __RESH_XDG_CONFIG_FILE="$HOME/.config" + else + __RESH_XDG_CONFIG_FILE="$XDG_CONFIG_HOME" + fi + mkdir -p "$__RESH_XDG_CONFIG_FILE" >/dev/null 2>/dev/null + __RESH_XDG_CONFIG_FILE="$__RESH_XDG_CONFIG_FILE/resh.toml" + + + if [ -z "${XDG_CACHE_HOME-}" ]; then + __RESH_XDG_CACHE_HOME="$HOME/.cache/resh" + else + __RESH_XDG_CACHE_HOME="$XDG_CACHE_HOME/resh" + fi + mkdir -p "$__RESH_XDG_CACHE_HOME" >/dev/null 2>/dev/null + + + if [ -z "${XDG_DATA_HOME-}" ]; then + __RESH_XDG_DATA_HOME="$HOME/.local/share/resh" + else + __RESH_XDG_DATA_HOME="$XDG_DATA_HOME/resh" + fi + mkdir -p "$__RESH_XDG_DATA_HOME" >/dev/null 2>/dev/null +}