From 154c9de51579675d87dd1506a67b6439434707b4 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Tue, 19 Mar 2024 11:48:10 +0300 Subject: [PATCH] mod/gitignore: add editors --- src/cli/gitignore.rs | 3 +++ src/config/gitignore.rs | 2 ++ src/module/gitignore.rs | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/src/cli/gitignore.rs b/src/cli/gitignore.rs index 3f754ed..4d212dd 100644 --- a/src/cli/gitignore.rs +++ b/src/cli/gitignore.rs @@ -2,6 +2,8 @@ use crate::module::gitignore::GitIgnoreModuleArgs; #[derive(Debug, Clone, clap::Args)] pub struct GitIgnoreModuleCliArgs { + #[clap(long)] + pub editors: bool, #[clap(long)] pub env: bool, #[clap(long)] @@ -17,6 +19,7 @@ pub struct GitIgnoreModuleCliArgs { impl From for GitIgnoreModuleArgs { fn from(args: GitIgnoreModuleCliArgs) -> Self { GitIgnoreModuleArgs { + editors: args.editors, env: args.env, direnv: args.direnv, rust: args.rust, diff --git a/src/config/gitignore.rs b/src/config/gitignore.rs index fa457c9..630cadf 100644 --- a/src/config/gitignore.rs +++ b/src/config/gitignore.rs @@ -2,6 +2,7 @@ use crate::module::gitignore::GitIgnoreModuleArgs; #[derive(Default, serde::Deserialize, serde::Serialize)] pub struct GitIgnoreModuleConfig { + pub editors: Option, pub env: Option, pub direnv: Option, pub rust: Option, @@ -12,6 +13,7 @@ pub struct GitIgnoreModuleConfig { impl From for GitIgnoreModuleArgs { fn from(cfg: GitIgnoreModuleConfig) -> Self { GitIgnoreModuleArgs { + editors: cfg.editors.unwrap_or_default(), env: cfg.env.unwrap_or_default(), direnv: cfg.direnv.unwrap_or_default(), rust: cfg.rust.unwrap_or_default(), diff --git a/src/module/gitignore.rs b/src/module/gitignore.rs index 0c9868d..1d6777b 100644 --- a/src/module/gitignore.rs +++ b/src/module/gitignore.rs @@ -2,6 +2,12 @@ use std::collections::HashMap; use super::Module; +const EDITORS_PART: &str = "\ +# editors +.idea/ +.vscode/ +*.swp"; + const ENV_PART: &str = "\ # env .env* @@ -21,6 +27,7 @@ const NODEJS_PART: &str = "\ node_modules/"; pub struct GitIgnoreModuleArgs { + pub editors: bool, pub env: bool, pub direnv: bool, pub rust: bool, @@ -30,6 +37,7 @@ pub struct GitIgnoreModuleArgs { fn make_gitignore_content(args: GitIgnoreModuleArgs) -> String { [ + args.editors.then_some(EDITORS_PART), args.env.then_some(ENV_PART), args.direnv.then_some(DIRENV_PART), args.rust.then_some(RUST_PART),