Skip to content

Commit

Permalink
Defaulting to xdg directory for history files (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed Jul 10, 2023
1 parent bb08ee6 commit 8131524
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
-----

Expand Down Expand Up @@ -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
-----
Expand Down
12 changes: 11 additions & 1 deletion src/PHPCR/Shell/Console/Application/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 8131524

Please sign in to comment.