Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
15 changes: 14 additions & 1 deletion docs/wayshot.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,20 @@ Wayshot - Screenshot tool for compositors implementing zwlr_screencopy_v1 such a

Example: *wayshot --config config.toml*


*--set-default-path <SET_DEFAULT_PATH>*
Sets the default screenshot saving path in the config file.

Example: *wayshot --set-default-path "/home/user/screenshots"*

*--set-cursor <SET_CURSOR>*
Sets the default cursor visibility when taking screenshots.

Example: *wayshot --set-cursor true*

*--set-clipboard <SET_CLIPBOARD>*
Sets the default behavior for copying screenshots to the clipboard.

Example: *wayshot --set-clipboard true*
# SEE ALSO
- wayshot(5)
- wayshot(7)
Expand Down
2 changes: 1 addition & 1 deletion wayshot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ wl-clipboard-rs = "0.9.2"
rustix = { version = "1.0", features = ["process", "runtime"] }

shellexpand = "3.1.0"
toml = { version = "0.8.20", default-features = false, features = ["parse"] }
toml = { version = "0.8.20", default-features = false, features = ["parse","display"] }
serde = { version = "1.0.219", features = ["derive"] }
dirs = "6.0.0"
libwaysip = "0.3.0"
Expand Down
9 changes: 9 additions & 0 deletions wayshot/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ pub struct Cli {
/// 3. `None` -- if the config isn't found, the `Config::default()` will be used
#[arg(long, verbatim_doc_comment)]
pub config: Option<PathBuf>,

#[arg(long,verbatim_doc_comment, help = "Sets the default screenshot saving path in the config file")]
pub set_default_path: Option<PathBuf>,

#[arg(long, verbatim_doc_comment, help = "Set default cursor visibility (true/false)")]
pub set_cursor: Option<bool>,

#[arg(long,verbatim_doc_comment,help = "Set default clipboard behavior (true/false)")]
pub set_clipboard: Option<bool>,
}
12 changes: 12 additions & 0 deletions wayshot/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ impl Config {
.map(|path| path.join("wayshot").join("config.toml"))
.unwrap_or_default()
}
pub fn save(&self, path: &PathBuf) -> Result<(), eyre::Error> {
let toml = toml::to_string(self)?;
// Create parent directories if needed
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)
.map_err(|e| eyre::eyre!("Failed to create config directory: {}", e))?;
}

std::fs::write(path, toml)
.map_err(|e| eyre::eyre!("Failed to write config file: {}", e))?;
Ok(())
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
40 changes: 40 additions & 0 deletions wayshot/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
path::{Path, PathBuf},
str::FromStr,
};
use crate::config::{Config,File, Base};

use chrono::Local;
use libwayshot::Result;
Expand Down Expand Up @@ -166,3 +167,42 @@ pub fn get_full_file_name(path: &Path, filename_format: &str, encoding: Encoding
base_dir.join(format!("{}.{}", stem, encoding))
}
}

pub fn update_config(
config_path: &PathBuf,
new_path: Option<PathBuf>,
cursor: Option<bool>,
clipboard: Option<bool>,
) -> eyre::Result<()> {
let mut config = Config::load(config_path).unwrap_or_default();

if let Some(path) = new_path {
let expanded_path = get_expanded_path(&path);

if !expanded_path.is_dir() {
return Err(eyre::eyre!(
"Path '{}' is not a directory",
expanded_path.display()
));
}
// addinng/updating path
let file = config.file.get_or_insert(File::default());
file.path = Some(expanded_path);
//updating
let base = config.base.get_or_insert(Base::default());
base.file = Some(true);
}

if let Some(cursor_val) = cursor {
let base = config.base.get_or_insert(Base::default());
base.cursor = Some(cursor_val);
}

if let Some(clipboard_val) = clipboard {
let base = config.base.get_or_insert(Base::default());
base.clipboard = Some(clipboard_val);
}

config.save(config_path)?;
Ok(())
}
13 changes: 13 additions & 0 deletions wayshot/src/wayshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ where
fn main() -> Result<()> {
let cli = cli::Cli::parse();
let config_path = cli.config.unwrap_or(Config::get_default_path());

if cli.set_default_path.is_some() || cli.set_cursor.is_some() || cli.set_clipboard.is_some() {

utils::update_config(
&config_path,
cli.set_default_path,
cli.set_cursor,
cli.set_clipboard,
)?;
return Ok(());
}


let config = Config::load(&config_path).unwrap_or_default();
let base = config.base.unwrap_or_default();
let file = config.file.unwrap_or_default();
Expand Down
Loading