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ECUFHQ5ZUJVDU6QC
WOYAD3FWIOSSZLM76DX6ZCRG6YILONICJ25UYMOJ52BGRLRPGRGAC
* Ignore commands starting with ' ' (space). This should make it
easier to not record sensitive commands. This is configurable in a
configuration file with the option `ignore_space`. By default this
is enabled.
* Add configuration option `log_level` to change the default log level
to run under.
## Configuration
There is also a way to configure `histdb-rs`. By default the configuration is stored under `$HOME/.config/histdb-rs/config.toml`. A different path can be specified using the `--config-path` option.
The default configuration looks like this:
```toml
# When true will not save commands that start with a space.
# Default: true
ignore_space = true
# The log level to run under.
# Default: Warn
log_level = "Warn"
```
# When true will not save commands that start with a space.
# Default: true
ignore_space = true
# The log level to run under.
# Default: Warn
log_level = "Warn"
use log::{
debug,
LevelFilter,
};
use std::path::Path;
use thiserror::Error;
use serde::Deserialize;
#[derive(Debug, Error)]
pub enum Error {
#[error("can not read config file: {0}")]
ReadFile(std::io::Error),
#[error("can not parse config file: {0}")]
ParseConfig(toml::de::Error),
}
#[derive(Debug, Deserialize)]
#[serde(default)]
pub struct Config {
/// Then true disables recording commands that start with a space
pub ignore_space: bool,
/// The log level to run under
pub log_level: LevelFilter,
}
impl Default for Config {
fn default() -> Self {
Self {
ignore_space: true,
log_level: LevelFilter::Warn,
}
}
}
impl Config {
pub fn open(path: impl AsRef<Path>) -> Result<Self, Error> {
if !path.as_ref().is_file() {
debug!("no config file found using default");
return Ok(Self::default());
}
let config_data = std::fs::read(path).map_err(Error::ReadFile)?;
let config = toml::de::from_slice(&config_data).map_err(Error::ParseConfig)?;
Ok(config)
}
}
pub fn zsh_add_history(command: String, socket_path: PathBuf) -> Result<(), Error> {
let data = CommandStart::from_env(command)?;
client::new(socket_path).send(&Message::CommandStart(data))?;
pub fn zsh_add_history(
config: &config::Config,
command: String,
socket_path: PathBuf,
) -> Result<(), Error> {
if config.ignore_space && command.starts_with(' ') {
debug!("not recording a command starting with a space");
} else {
let data = CommandStart::from_env(command)?;
client::new(socket_path).send(&Message::CommandStart(data))?;
}