rm shellexpend
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 14m17s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 14m17s
This commit is contained in:
Submodule .config/ai/scpt updated: 7a4d642e41...a1905d104b
@ -9,7 +9,6 @@ description = "latest@2024-08-18"
|
|||||||
seahorse = "*"
|
seahorse = "*"
|
||||||
reqwest = { version = "*", features = ["blocking", "json"] }
|
reqwest = { version = "*", features = ["blocking", "json"] }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
shellexpand = "*"
|
|
||||||
config = "*"
|
config = "*"
|
||||||
serde = "*"
|
serde = "*"
|
||||||
serde_json = "*"
|
serde_json = "*"
|
||||||
|
82
src/data.rs
82
src/data.rs
@ -5,37 +5,50 @@ use std::fs;
|
|||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
/// ホームディレクトリパスを展開するユーティリティ関数
|
||||||
|
/// "~"で始まるパスをユーザーのホームディレクトリに展開します
|
||||||
|
fn expand_home_path(path: &str) -> PathBuf {
|
||||||
|
if path.starts_with("~") {
|
||||||
|
let home = env::var("HOME").unwrap_or_else(|_| ".".to_string());
|
||||||
|
let path_without_tilde = path.strip_prefix("~/").unwrap_or(&path[1..]);
|
||||||
|
PathBuf::from(home).join(path_without_tilde)
|
||||||
|
} else {
|
||||||
|
PathBuf::from(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn data_file(s: &str) -> String {
|
pub fn data_file(s: &str) -> String {
|
||||||
let file = "/.config/ai/";
|
let path = expand_home_path("~/.config/ai");
|
||||||
let mut f = shellexpand::tilde("~").to_string();
|
|
||||||
f.push_str(&file);
|
if !path.is_dir() {
|
||||||
let path = Path::new(&f);
|
let _ = fs::create_dir_all(&path);
|
||||||
if path.is_dir() == false {
|
|
||||||
let _ = fs::create_dir_all(f.clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut path_str = path.to_string_lossy().to_string();
|
||||||
match &*s {
|
match &*s {
|
||||||
"toml" => f + &"token.toml",
|
"toml" => path_str + "/token.toml",
|
||||||
"json" => f + &"token.json",
|
"json" => path_str + "/token.json",
|
||||||
"refresh" => f + &"refresh.toml",
|
"refresh" => path_str + "/refresh.toml",
|
||||||
_ => f + &"." + &s,
|
_ => path_str + "/." + &s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_file(s: &str) -> String {
|
pub fn log_file(s: &str) -> String {
|
||||||
let file = "/.config/ai/txt/";
|
let path = expand_home_path("~/.config/ai/txt");
|
||||||
let mut f = shellexpand::tilde("~").to_string();
|
|
||||||
f.push_str(&file);
|
if !path.is_dir() {
|
||||||
let path = Path::new(&f);
|
let _ = fs::create_dir_all(&path);
|
||||||
if path.is_dir() == false {
|
|
||||||
let _ = fs::create_dir_all(f.clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut path_str = path.to_string_lossy().to_string();
|
||||||
match &*s {
|
match &*s {
|
||||||
"n1" => f + &"notify_cid.txt",
|
"n1" => path_str + "/notify_cid.txt",
|
||||||
"n2" => f + &"notify_cid_run.txt",
|
"n2" => path_str + "/notify_cid_run.txt",
|
||||||
"c1" => f + &"comment_cid.txt",
|
"c1" => path_str + "/comment_cid.txt",
|
||||||
_ => f + &s,
|
_ => path_str + "/" + &s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,11 +275,9 @@ pub fn data_refresh(s: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn data_scpt(s: &str) -> String {
|
pub fn data_scpt(s: &str) -> String {
|
||||||
let s = String::from(s);
|
let mut path = expand_home_path("~/.config/ai/scpt");
|
||||||
let file = "/.config/ai/scpt/".to_owned() + &s + &".zsh";
|
path.push(format!("{}.zsh", s));
|
||||||
let mut f = shellexpand::tilde("~").to_string();
|
path.to_string_lossy().to_string()
|
||||||
f.push_str(&file);
|
|
||||||
return f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@ -603,11 +614,10 @@ pub fn w_cid(cid: String, file: String, t: bool) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn c_follow_all() {
|
pub fn c_follow_all() {
|
||||||
let file = "/.config/ai/scpt/follow_all.zsh";
|
let path = expand_home_path("~/.config/ai/scpt/follow_all.zsh");
|
||||||
let mut f = shellexpand::tilde("~").to_string();
|
|
||||||
f.push_str(&file);
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
let output = Command::new(&f).output().expect("zsh");
|
let output = Command::new(path.to_str().unwrap()).output().expect("zsh");
|
||||||
let d = String::from_utf8_lossy(&output.stdout);
|
let d = String::from_utf8_lossy(&output.stdout);
|
||||||
let d = "\n".to_owned() + &d.to_string();
|
let d = "\n".to_owned() + &d.to_string();
|
||||||
println!("{}", d);
|
println!("{}", d);
|
||||||
@ -617,9 +627,10 @@ pub fn c_openai_key(c: &Context) {
|
|||||||
let api = c.args[0].to_string();
|
let api = c.args[0].to_string();
|
||||||
let o = "api='".to_owned() + &api.to_string() + &"'".to_owned();
|
let o = "api='".to_owned() + &api.to_string() + &"'".to_owned();
|
||||||
let o = o.to_string();
|
let o = o.to_string();
|
||||||
let l = shellexpand::tilde("~") + "/.config/ai/openai.toml";
|
|
||||||
let l = l.to_string();
|
let path = expand_home_path("~/.config/ai/openai.toml");
|
||||||
let mut l = fs::File::create(l).unwrap();
|
|
||||||
|
let mut l = fs::File::create(&path).unwrap();
|
||||||
if o != "" {
|
if o != "" {
|
||||||
l.write_all(&o.as_bytes()).unwrap();
|
l.write_all(&o.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
@ -628,9 +639,10 @@ pub fn c_openai_key(c: &Context) {
|
|||||||
|
|
||||||
impl Open {
|
impl Open {
|
||||||
pub fn new() -> Result<Self, ConfigError> {
|
pub fn new() -> Result<Self, ConfigError> {
|
||||||
let d = shellexpand::tilde("~") + "/.config/ai/openai.toml";
|
let path = expand_home_path("~/.config/ai/openai.toml");
|
||||||
|
|
||||||
let s = Config::builder()
|
let s = Config::builder()
|
||||||
.add_source(File::with_name(&d))
|
.add_source(File::with_name(path.to_str().unwrap()))
|
||||||
.add_source(config::Environment::with_prefix("APP"))
|
.add_source(config::Environment::with_prefix("APP"))
|
||||||
.build()?;
|
.build()?;
|
||||||
s.try_deserialize()
|
s.try_deserialize()
|
||||||
|
Reference in New Issue
Block a user