Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ multiple_crate_versions = { level = "allow", priority = 1 }

[package]
name = "flyline"
version = "2.0.1"
version = "2.0.2"
edition.workspace = true
rust-version.workspace = true
publish = false
Expand Down
2 changes: 1 addition & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,7 @@ impl<'a> App<'a> {
self.has_run_delayed_startup = Some(std::time::Instant::now());
log::debug!("Running delayed startup initialization");
time_it!("delayed startup", {
let _ = crate::term_info::get_term_info(&GLOBAL_EVENT_READER);
let _ = crate::term_info::get_term_info();
self.sync_viewport_top_from_cpr();

if self.terminal.viewport_top().is_none() {
Expand Down
4 changes: 4 additions & 0 deletions src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ pub(crate) const CHANGELOG: &str = r#"# Changelog
## v2.0.1 (2026-11-23)
- **Zero-size terminals**: A terminal that reports a 0x0 size (such as a freshly spawned pty) no longer makes flyline exit the shell; it assumes 80x24.
- **History path on macOS**: The help and guide now give the JSONL history path on macOS, `~/Library/Application Support/flyline/history.jsonl`.

## v2.0.2 (2026-11-23)
- **No terminal attached**: `flyline version` and other commands that detect the terminal now work when bash has no controlling terminal, such as when a script or a coding agent runs `bash -ic`.
- **Atuin import**: `flyline history import` with no path now finds Atuin's database in `~/.atuin/data` (recent Atuin) or `~/.local/share/atuin`, on macOS too.
"#;

pub(crate) fn pretty_changelog() -> String {
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ fn show_version(copy: bool) {
let term_program = term_info::term_program().unwrap_or_else(|| "unknown".to_string());
let term_program_version =
term_info::term_program_version().unwrap_or_else(|| "unknown".to_string());
let info = term_info::get_term_info(&crate::app::GLOBAL_EVENT_READER);
let info = term_info::get_term_info();
let detected_emulator = info.emulator.name().to_string();
let detected_multiplexer = info
.multiplexer
Expand Down
47 changes: 37 additions & 10 deletions src/history/importing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,47 @@ pub fn import_history_file(path: &Path, target_jsonl_path: &Path) -> anyhow::Res
Ok(imported_count)
}

pub fn import_atuin_history(target_jsonl_path: &Path) -> anyhow::Result<usize> {
let db_path = dirs::data_local_dir()
.unwrap_or_else(|| PathBuf::from("~/.local/share"))
.join("atuin")
.join("history.db");
/// Where Atuin may keep its history database, most specific first.
///
/// Recent Atuin releases use `$ATUIN_HOME/data` (default `~/.atuin/data`); older ones use
/// `$XDG_DATA_HOME/atuin` (default `~/.local/share/atuin`) on every Unix, macOS included.
fn atuin_db_candidates() -> Vec<PathBuf> {
let home = dirs::home_dir();
let mut dirs_to_try = Vec::new();
if let Some(atuin_home) = std::env::var_os("ATUIN_HOME") {
dirs_to_try.push(PathBuf::from(atuin_home).join("data"));
}
if let Some(home) = &home {
dirs_to_try.push(home.join(".atuin").join("data"));
}
if let Some(xdg) = std::env::var_os("XDG_DATA_HOME") {
dirs_to_try.push(PathBuf::from(xdg).join("atuin"));
}
if let Some(home) = &home {
dirs_to_try.push(home.join(".local").join("share").join("atuin"));
}
if let Some(data) = dirs::data_local_dir() {
dirs_to_try.push(data.join("atuin"));
}
let mut candidates: Vec<PathBuf> = dirs_to_try
.into_iter()
.map(|d| d.join("history.db"))
.collect();
candidates.dedup();
candidates
}

if !db_path.exists() {
pub fn import_atuin_history(target_jsonl_path: &Path) -> anyhow::Result<usize> {
let candidates = atuin_db_candidates();
let Some(db_path) = candidates.iter().find(|p| p.exists()) else {
let tried: Vec<String> = candidates.iter().map(|p| p.display().to_string()).collect();
return Err(anyhow::anyhow!(
"Atuin database file not found at {}",
db_path.display()
"Atuin database not found (tried {}). Pass its path: flyline history import <PATH>",
tried.join(", ")
));
}
};

import_atuin_sqlite_file(&db_path, target_jsonl_path)
import_atuin_sqlite_file(db_path, target_jsonl_path)
}

#[cfg(test)]
Expand Down
31 changes: 24 additions & 7 deletions src/term_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,24 @@ static STATIC_TERM_INFO: Mutex<Option<TermInfo>> = Mutex::new(None);
/// Access the static [`TermInfo`].
///
/// If already initialized, returns the static struct.
/// If not yet initialized, queries the terminal via `reader` (blocking),
/// initializes `TermInfo::new(reader)`, stores it in the static instance, and returns it.
pub fn get_term_info(reader: &termina::EventReader) -> TermInfo {
/// If not yet initialized, queries the terminal through the global event reader (blocking),
/// stores the result in the static instance, and returns it.
///
/// Without a controlling terminal (for example `bash -ic 'flyline version'` run by a script or
/// an agent), there is nothing to query and opening the event reader would fail, so this
/// returns [`TermInfo::from_env`] without caching it.
pub fn get_term_info() -> TermInfo {
if let Ok(guard) = STATIC_TERM_INFO.lock()
&& let Some(ref info) = *guard
{
return info.clone();
}

let info = TermInfo::new(reader);
if !has_controlling_terminal() {
return TermInfo::from_env();
}

let info = TermInfo::new(&crate::app::GLOBAL_EVENT_READER);
if let Ok(mut guard) = STATIC_TERM_INFO.lock() {
if guard.is_none() {
*guard = Some(info.clone());
Expand All @@ -506,19 +514,28 @@ pub fn get_term_info(reader: &termina::EventReader) -> TermInfo {
info
}

/// Whether this process has a controlling terminal that the event reader can open.
fn has_controlling_terminal() -> bool {
std::fs::OpenOptions::new()
.read(true)
.write(true)
.open("/dev/tty")
.is_ok()
}

/// Returns the cached [`DeviceAttributes`] if device attribute querying has been performed.
pub fn device_attributes() -> Option<DeviceAttributes> {
get_term_info(&crate::app::GLOBAL_EVENT_READER).device_attributes
get_term_info().device_attributes
}

/// Returns the detected active terminal emulator for the current process.
pub fn current() -> TerminalEmulator {
get_term_info(&crate::app::GLOBAL_EVENT_READER).emulator
get_term_info().emulator
}

/// Returns the detected active terminal multiplexer for the current process, if any.
pub fn multiplexer() -> Option<Multiplexer> {
get_term_info(&crate::app::GLOBAL_EVENT_READER).multiplexer
get_term_info().multiplexer
}

/// Helper function to perform DA query on an EventReader.
Expand Down