From 8131524e7f8d3f97ae0e92dc349395017418a7f8 Mon Sep 17 00:00:00 2001 From: mamazu <14860264+mamazu@users.noreply.github.com> Date: Mon, 10 Jul 2023 12:16:51 +0200 Subject: [PATCH] Defaulting to xdg directory for history files (#217) --- CHANGELOG.md | 8 +++++++- src/PHPCR/Shell/Console/Application/Shell.php | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9130c36a..882a26cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= +1.5.0 +----- + +- If `XDG_DATA_HOME` is defined, it is now used as location where to store the history. + If you have set `XDG_DATA_HOME` to something else than `HOME`, you can preserve your phpcr-shell history by moving the directory `~/.history_PHPCRSH` to `$XDB_DATA_HOME/.history_PHPCRSH`. + 1.4.0 ----- @@ -44,7 +50,7 @@ beta4 - [node:property:show] Text fields are truncated - [profile] Workspace given from CLI does not override profile workspace - [command] Removed node:definition command: Jackalope now supports this, and - this command would never have worked, see: + this command would never have worked, see: beta2 ----- diff --git a/src/PHPCR/Shell/Console/Application/Shell.php b/src/PHPCR/Shell/Console/Application/Shell.php index 6b8227cf..bb308350 100644 --- a/src/PHPCR/Shell/Console/Application/Shell.php +++ b/src/PHPCR/Shell/Console/Application/Shell.php @@ -41,11 +41,21 @@ public function __construct(Application $application) { $this->hasReadline = function_exists('readline'); $this->application = $application; - $this->history = getenv('HOME').'/.history_'.$application->getName(); + $this->history = $this->getHistoryDirectory(); $this->output = new ConsoleOutput(); $this->prompt = $application->getName().' > '; } + public function getHistoryDirectory(): string + { + $dataDirectory = getenv('XDG_DATA_HOME'); + if ($dataDirectory !== '') { + return $dataDirectory.'/'.$this->application->getName(); + } + + return getenv('HOME').'/.history_'.$this->application->getName(); + } + /** * Runs the shell. */