/** * Get the readline history file path. * * Defaults to `/history` inside the shell's base config dir unless * explicitly overridden. * * @return string */ public function getHistoryFile() { if (isset($this->historyFile)) { return $this->historyFile; } foreach ($this->getConfigDirs() as $dir) { $file = $dir . '/psysh_history'; if (@is_file($file)) { return $this->historyFile = $file; } $file = $dir . '/history'; if (@is_file($file)) { return $this->historyFile = $file; } } // fallback: create our own if (isset($this->configDir)) { $dir = $this->configDir; } else { $xdg = new Xdg(); $dir = $xdg->getHomeConfigDir(); } if (!is_dir($dir)) { mkdir($dir, 0700, true); } $file = $dir . '/psysh_history'; return $this->historyFile = $file; }
/** * Get potential home config directory paths. * * Returns `~/.psysh`, `%APPDATA%/PsySH` (when on Windows), and the * XDG Base Directory home config directory: * * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html * * @return string[] */ public static function getHomeConfigDirs() { $xdg = new Xdg(); return self::getDirNames(array($xdg->getHomeConfigDir())); }
/** * Get the readline history file path. * * Defaults to `/history` inside the shell's base config dir unless * explicitly overridden. * * @return string */ public function getHistoryFile() { if (isset($this->historyFile)) { return $this->historyFile; } // Deprecation warning for incorrect psysh_history path. // projects: remove this before v0.8.0 $xdg = new Xdg(); $oldHistory = $xdg->getHomeConfigDir() . '/psysh_history'; if (@is_file($oldHistory)) { $dir = $this->configDir ?: ConfigPaths::getCurrentConfigDir(); $newHistory = $dir . '/psysh_history'; $msg = sprintf("PsySH history file found at '%s'. Please delete it or move it to '%s'.", strtr($oldHistory, '\\', '/'), $newHistory); trigger_error($msg, E_USER_DEPRECATED); return $this->historyFile = $oldHistory; } $files = ConfigPaths::getConfigFiles(array('psysh_history', 'history'), $this->configDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && count($files) > 1) { $msg = sprintf('Multiple history files found: %s. Using %s', implode($files, ', '), $files[0]); trigger_error($msg, E_USER_NOTICE); } return $this->historyFile = $files[0]; } // fallback: create our own history file $dir = $this->configDir ?: ConfigPaths::getCurrentConfigDir(); if (!is_dir($dir)) { mkdir($dir, 0700, true); } return $this->historyFile = $dir . '/psysh_history'; }
/** * {@inheritdoc} */ public function getConfigDir() { return $this->xdg->getHomeConfigDir() . '/sw-cli-tools'; }