1
0
Fork 0
forked from wry/wry

config: allow running commands privileged

This commit is contained in:
Julian Orth 2024-04-01 13:16:34 +02:00
parent 4558bdb7c1
commit affea49e49
11 changed files with 74 additions and 5 deletions

View file

@ -245,6 +245,7 @@ pub struct Exec {
pub prog: String,
pub args: Vec<String>,
pub envs: Vec<(String, String)>,
pub privileged: bool,
}
#[derive(Debug, Clone)]

View file

@ -2,7 +2,7 @@ use {
crate::{
config::{
context::Context,
extractor::{arr, opt, str, val, Extractor, ExtractorError},
extractor::{arr, bol, opt, recover, str, val, Extractor, ExtractorError},
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
parsers::{
env::{EnvParser, EnvParserError},
@ -11,7 +11,7 @@ use {
Exec,
},
toml::{
toml_span::{Span, Spanned, SpannedExt},
toml_span::{DespanExt, Span, Spanned, SpannedExt},
toml_value::Value,
},
},
@ -45,6 +45,7 @@ impl Parser for ExecParser<'_> {
prog: string.to_string(),
args: vec![],
envs: vec![],
privileged: false,
})
}
@ -61,6 +62,7 @@ impl Parser for ExecParser<'_> {
prog,
args,
envs: vec![],
privileged: false,
})
}
@ -70,8 +72,12 @@ impl Parser for ExecParser<'_> {
table: &IndexMap<Spanned<String>, Spanned<Value>>,
) -> ParseResult<Self> {
let mut ext = Extractor::new(self.0, span, table);
let (prog, args_val, envs_val) =
ext.extract((str("prog"), opt(arr("args")), opt(val("env"))))?;
let (prog, args_val, envs_val, privileged) = ext.extract((
str("prog"),
opt(arr("args")),
opt(val("env")),
recover(opt(bol("privileged"))),
))?;
let mut args = vec![];
if let Some(args_val) = args_val {
for arg in args_val.value {
@ -86,6 +92,7 @@ impl Parser for ExecParser<'_> {
prog: prog.value.to_string(),
args,
envs,
privileged: privileged.despan().unwrap_or(false),
})
}
}

View file

@ -7,7 +7,7 @@ keymap = """
};
"""
on-graphics-initialized = { type = "exec", exec = "mako" }
on-graphics-initialized = { type = "exec", exec = { prog = "mako", privileged = true } }
[shortcuts]
alt-h = "focus-left"

View file

@ -823,6 +823,9 @@ fn create_command(exec: &Exec) -> Command {
for (k, v) in &exec.envs {
command.env(k, v);
}
if exec.privileged {
command.privileged();
}
command
}