Skip to content
Merged
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
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ url = "2.5.4"
hyperpolyglot_fork = { version = "0.1.7", optional = true }
theme-converter = "0.1.2"
plist = "1.8.0"
home = "0.5.11"

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion core/src/themes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub async fn parse_remote_code_theme(path: &str, code_theme: &str) -> anyhow::Re
}

pub async fn parse_code_theme(code_theme: &str) -> anyhow::Result<String> {
let remote_theme_folder_path = get_config_home_path()?.join("remote_themes");
let remote_theme_folder_path = get_config_home_path().join("remote_themes");

if !remote_theme_folder_path.exists() {
fs::create_dir_all(&remote_theme_folder_path)?;
Expand Down
18 changes: 7 additions & 11 deletions core/src/utils/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ fn create_temp_file_name() -> String {
format!("CodeSnap_{}", formatted_time)
}

pub fn parse_home_variable(path: &str) -> Result<String, VarError> {
if cfg!(windows) {
return Ok(path.to_string());
}

let home_path = var("HOME")?;
pub fn parse_home_variable(path: &str) -> String {
let home_path = home::home_dir().unwrap().to_string_lossy().to_string();
let regex = Regex::new(r"(~|$HOME)").unwrap();
let path = regex.replace_all(path, home_path);

Ok(path.to_string())
path.to_string()
}

pub fn parse_file_name(path: &str) -> Result<String, VarError> {
let path_str = parse_home_variable(path)?;
let path_str = parse_home_variable(path);
let path = Path::new(&path_str);
let parsed_path = if path.is_dir() {
path.join(create_temp_file_name())
Expand All @@ -45,13 +41,13 @@ pub fn parse_file_name(path: &str) -> Result<String, VarError> {
Ok(parsed_path)
}

pub fn get_config_home_path() -> Result<PathBuf, VarError> {
let home = parse_home_variable("~")?;
pub fn get_config_home_path() -> PathBuf {
let home = parse_home_variable("~");
let config_home_path = Path::new(&home).join(".config").join("codesnap");

if !config_home_path.exists() {
std::fs::create_dir_all(&config_home_path).unwrap();
}

Ok(config_home_path)
config_home_path
}