Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't fail if config path is unavailable #838

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/ConfigPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ private function windowsHomeDir()
return null;
}

private function homeConfigDir()
private function homeConfigDir(): ?string
{
if ($homeConfigDir = $this->getEnv('XDG_CONFIG_HOME')) {
return $homeConfigDir;
}

$homeDir = $this->homeDir();
if ($homeDir === null) {
return null;
}

return $homeDir === '/' ? $homeDir.'.config' : $homeDir.'/.config';
}
Expand Down Expand Up @@ -130,7 +133,7 @@ public function configDirs(): array
*
* @see self::homeConfigDir
*/
public function currentConfigDir(): string
public function currentConfigDir(): ?string
{
if ($this->configDir !== null) {
return $this->configDir;
Expand All @@ -144,7 +147,7 @@ public function currentConfigDir(): string
}
}

return $configDirs[0];
return $configDirs[0] ?? null;
}

/**
Expand Down Expand Up @@ -259,6 +262,7 @@ public function which($command)
*/
private function allDirNames(array $baseDirs): array
{
$baseDirs = \array_filter($baseDirs);
$dirs = \array_map(function ($dir) {
return \strtr($dir, '\\', '/').'/psysh';
}, $baseDirs);
Expand Down
6 changes: 5 additions & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public function setHistoryFile(string $file)
* Defaults to `/history` inside the shell's base config dir unless
* explicitly overridden.
*/
public function getHistoryFile(): string
public function getHistoryFile(): ?string
{
if (isset($this->historyFile)) {
return $this->historyFile;
Expand All @@ -674,6 +674,10 @@ public function getHistoryFile(): string
$this->setHistoryFile($files[0]);
} else {
// fallback: create our own history file
$currentConfDir = $this->configPaths->currentConfigDir();
if ($currentConfDir === null) {
return null;
}
$this->setHistoryFile($this->configPaths->currentConfigDir().'/psysh_history');
}

Expand Down
Loading