-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow setting
YAZI_ID
as a command line argument (#1305)
Co-authored-by: sxyazi <sxyazi@gmail.com>
- Loading branch information
1 parent
67fb66c
commit f0cb365
Showing
19 changed files
with
206 additions
and
172 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::process; | ||
|
||
pub(crate) struct Actions; | ||
|
||
impl Actions { | ||
pub(crate) fn act(args: &crate::Args) { | ||
if args.debug { | ||
println!("{}", Self::debug().unwrap()); | ||
process::exit(0); | ||
} | ||
|
||
if args.version { | ||
println!("Yazi {}", Self::version()); | ||
process::exit(0); | ||
} | ||
|
||
if args.clear_cache { | ||
Self::clear_cache(); | ||
process::exit(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use yazi_config::PREVIEW; | ||
use yazi_shared::Xdg; | ||
|
||
use super::Actions; | ||
|
||
impl Actions { | ||
pub(super) fn clear_cache() { | ||
if PREVIEW.cache_dir == Xdg::cache_dir() { | ||
println!("Clearing cache directory: \n{:?}", PREVIEW.cache_dir); | ||
std::fs::remove_dir_all(&PREVIEW.cache_dir).unwrap(); | ||
} else { | ||
println!( | ||
"You've changed the default cache directory, for your data's safety, please clear it manually: \n{:?}", | ||
PREVIEW.cache_dir | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
use std::{env, ffi::OsStr, fmt::Write}; | ||
|
||
use regex::Regex; | ||
use yazi_shared::Xdg; | ||
|
||
use super::Actions; | ||
|
||
impl Actions { | ||
pub(super) fn debug() -> Result<String, std::fmt::Error> { | ||
use std::env::consts::{ARCH, FAMILY, OS}; | ||
let mut s = String::new(); | ||
|
||
writeln!(s, "\nYazi")?; | ||
writeln!(s, " Version: {}", Self::version())?; | ||
writeln!(s, " Debug : {}", cfg!(debug_assertions))?; | ||
writeln!(s, " OS : {}-{} ({})", OS, ARCH, FAMILY)?; | ||
|
||
writeln!(s, "\nYa")?; | ||
writeln!(s, " Version: {}", Self::process_output("ya", "--version"))?; | ||
|
||
writeln!(s, "\nEmulator")?; | ||
writeln!(s, " Emulator.via_env: {:?}", yazi_adapter::Emulator::via_env())?; | ||
writeln!(s, " Emulator.via_csi: {:?}", yazi_adapter::Emulator::via_csi())?; | ||
writeln!(s, " Emulator.detect : {:?}", yazi_adapter::Emulator::detect())?; | ||
|
||
writeln!(s, "\nAdapter")?; | ||
writeln!(s, " Adapter.matches: {:?}", yazi_adapter::Adapter::matches())?; | ||
|
||
writeln!(s, "\nDesktop")?; | ||
writeln!(s, " XDG_SESSION_TYPE: {:?}", env::var_os("XDG_SESSION_TYPE"))?; | ||
writeln!(s, " WAYLAND_DISPLAY : {:?}", env::var_os("WAYLAND_DISPLAY"))?; | ||
writeln!(s, " DISPLAY : {:?}", env::var_os("DISPLAY"))?; | ||
|
||
writeln!(s, "\nSSH")?; | ||
writeln!(s, " shared.in_ssh_connection: {:?}", yazi_shared::in_ssh_connection())?; | ||
|
||
writeln!(s, "\nWSL")?; | ||
writeln!( | ||
s, | ||
" /proc/sys/fs/binfmt_misc/WSLInterop: {:?}", | ||
std::fs::symlink_metadata("/proc/sys/fs/binfmt_misc/WSLInterop").is_ok() | ||
)?; | ||
|
||
writeln!(s, "\nVariables")?; | ||
writeln!(s, " SHELL : {:?}", env::var_os("SHELL"))?; | ||
writeln!(s, " EDITOR : {:?}", env::var_os("EDITOR"))?; | ||
writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?; | ||
writeln!(s, " YAZI_FILE_ONE : {:?}", env::var_os("YAZI_FILE_ONE"))?; | ||
writeln!(s, " YAZI_CONFIG_HOME : {:?}", env::var_os("YAZI_CONFIG_HOME"))?; | ||
|
||
writeln!(s, "\nText Opener")?; | ||
writeln!( | ||
s, | ||
" default: {:?}", | ||
yazi_config::OPEN.openers("f75a.txt", "text/plain").and_then(|a| a.first().cloned()) | ||
)?; | ||
writeln!(s, " block : {:?}", yazi_config::OPEN.block_opener("bulk.txt", "text/plain"))?; | ||
|
||
writeln!(s, "\ntmux")?; | ||
writeln!(s, " TMUX : {:?}", *yazi_adapter::TMUX)?; | ||
writeln!(s, " Version: {}", Self::process_output("tmux", "-V"))?; | ||
|
||
writeln!(s, "\nDependencies")?; | ||
writeln!( | ||
s, | ||
" file : {}", | ||
Self::process_output(env::var_os("YAZI_FILE_ONE").unwrap_or("file".into()), "--version") | ||
)?; | ||
writeln!(s, " ueberzugpp : {}", Self::process_output("ueberzugpp", "--version"))?; | ||
writeln!(s, " ffmpegthumbnailer: {}", Self::process_output("ffmpegthumbnailer", "-v"))?; | ||
writeln!(s, " magick : {}", Self::process_output("magick", "--version"))?; | ||
writeln!(s, " fzf : {}", Self::process_output("fzf", "--version"))?; | ||
writeln!(s, " fd : {}", Self::process_output("fd", "--version"))?; | ||
writeln!(s, " rg : {}", Self::process_output("rg", "--version"))?; | ||
writeln!(s, " chafa : {}", Self::process_output("chafa", "--version"))?; | ||
writeln!(s, " zoxide : {}", Self::process_output("zoxide", "--version"))?; | ||
writeln!(s, " unar : {}", Self::process_output("unar", "--version"))?; | ||
writeln!(s, " jq : {}", Self::process_output("jq", "--version"))?; | ||
|
||
writeln!(s, "\n\n--------------------------------------------------")?; | ||
writeln!( | ||
s, | ||
"When reporting a bug, please also upload the `yazi.log` log file - only upload the most recent content by time." | ||
)?; | ||
writeln!(s, "You can find it in the {:?} directory.", Xdg::state_dir())?; | ||
|
||
Ok(s) | ||
} | ||
|
||
fn process_output(name: impl AsRef<OsStr>, arg: impl AsRef<OsStr>) -> String { | ||
match std::process::Command::new(name.as_ref()).arg(arg).output() { | ||
Ok(out) if out.status.success() => { | ||
let line = | ||
String::from_utf8_lossy(&out.stdout).trim().lines().next().unwrap_or_default().to_owned(); | ||
Regex::new(r"\d+\.\d+(\.\d+-\d+|\.\d+|\b)") | ||
.unwrap() | ||
.find(&line) | ||
.map(|m| m.as_str().to_owned()) | ||
.unwrap_or(line) | ||
} | ||
Ok(out) => format!("{:?}, {:?}", out.status, String::from_utf8_lossy(&out.stderr)), | ||
Err(e) => format!("{e}"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![allow(clippy::module_inception)] | ||
|
||
mod actions; | ||
mod clear_cache; | ||
mod debug; | ||
mod version; | ||
|
||
pub(super) use actions::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use super::Actions; | ||
|
||
impl Actions { | ||
pub(super) fn version() -> String { | ||
format!( | ||
"{} ({} {})", | ||
env!("CARGO_PKG_VERSION"), | ||
env!("VERGEN_GIT_SHA"), | ||
env!("VERGEN_BUILD_DATE") | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.