blob: 2e51a1e29a0be891cfb5a1aba1768995ee0f0176 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
use clap::Subcommand;
use eyre::Result;
#[cfg(not(windows))]
use rustix::{fs::Mode, process::umask};
mod client;
mod contributors;
mod gen_completions;
#[derive(Subcommand)]
#[command(infer_subcommands = true)]
#[expect(clippy::large_enum_variant)]
pub(crate) enum AtuinCmd {
#[command(flatten)]
Client(client::Cmd),
/// Generate a UUID
Uuid,
Contributors,
/// Generate shell completions
GenCompletions(gen_completions::Cmd),
}
impl AtuinCmd {
pub(crate) fn run(self) -> Result<()> {
#[cfg(not(windows))]
{
// set umask before we potentially open/create files
// or in other words, 077. Do not allow any access to any other user
let mode = Mode::RWXG | Mode::RWXO;
umask(mode);
}
match self {
Self::Client(client) => client.run(),
Self::Contributors => {
contributors::run();
Ok(())
}
Self::Uuid => {
println!("{}", turtle_common::utils::uuid_v7().as_simple());
Ok(())
}
Self::GenCompletions(gen_completions) => gen_completions.run(),
}
}
}
#[cfg(unix)]
#[inline]
fn is_truthy_env(name: &str) -> bool {
std::env::var(name)
.ok()
.as_ref()
.is_some_and(|value| !value.trim().is_empty() && value.trim() != "false")
}
pub(crate) fn current_session() -> Result<String> {
std::env::var("ATUIN_SESSION").map_err(|_| {
eyre::eyre!("Failed to find $ATUIN_SESSION in the environment. Check that you have correctly set up your shell.")
})
}
|