mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 00:31:04 +00:00
20 lines
490 B
Rust
20 lines
490 B
Rust
use std::path::Path;
|
|
|
|
use anyhow::{bail, Result};
|
|
use tokio::process::Command;
|
|
|
|
use crate::config::PREVIEW;
|
|
|
|
pub async fn jq(path: &Path) -> Result<String> {
|
|
let output = Command::new("jq")
|
|
.args(["-C", "--indent", &PREVIEW.tab_size.to_string(), "."])
|
|
.arg(path)
|
|
.kill_on_drop(true)
|
|
.output()
|
|
.await?;
|
|
|
|
if !output.status.success() {
|
|
bail!("failed to get json: {}", String::from_utf8_lossy(&output.stderr));
|
|
}
|
|
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
|
}
|