summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2020-05-26 20:20:36 -0400
committerBen Morrison <ben@gbmor.dev>2020-05-26 23:52:52 -0400
commit16fbf516e3b28d19570dd6e93e63b0efb9c249ff (patch)
tree4d31f7a98bd7527820a1cbe8f5cae74eab89b1b6
parent7d132af9766a64e8403950fee46491db45598112 (diff)
downloadclinte-16fbf516e3b28d19570dd6e93e63b0efb9c249ff.tar.gz
moved check for val of $EDITOR into ed::call()
Also removed some allocations from call() in the form of unnecessary
string clones.
-rw-r--r--src/ed.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/ed.rs b/src/ed.rs
index fa6d43b..0e1c4c8 100644
--- a/src/ed.rs
+++ b/src/ed.rs
@@ -7,22 +7,6 @@ use chrono::prelude::*;
 use crate::error;
 use crate::user;
 
-lazy_static! {
-    static ref VAR: String = match env::var("EDITOR") {
-        Ok(ed) => {
-            if &ed == "" {
-                "nano".into()
-            } else {
-                ed
-            }
-        }
-        Err(err) => {
-            log::warn!("{:?}", err);
-            "nano".into()
-        }
-    };
-}
-
 fn create_tmp_file<'a>() -> Result<String, &'a str> {
     let the_time = Utc::now().to_rfc3339();
     let file_name = format!("/tmp/clinte_ed_{}_{}", *user::NAME, the_time);
@@ -36,17 +20,33 @@ fn create_tmp_file<'a>() -> Result<String, &'a str> {
 }
 
 pub fn call() -> String {
+    // If they don't have $EDITOR set, just default to nano
+    // instead of assuming vim or emacs.
+    let editor = match env::var("EDITOR") {
+        Ok(ed) => {
+            if &ed == "" {
+                "nano".into()
+            } else {
+                ed
+            }
+        }
+        Err(_) => {
+            log::warn!("Couldn't get value of $EDITOR, defaulting to nano");
+            "nano".into()
+        }
+    };
+
     let tmp_loc = error::helper(create_tmp_file());
 
     error::helper(
-        process::Command::new(VAR.clone())
-            .arg(tmp_loc.clone())
+        process::Command::new(editor)
+            .arg(&tmp_loc)
             .stdin(process::Stdio::inherit())
             .stdout(process::Stdio::inherit())
             .output(),
     );
 
-    let body = error::helper(fs::read_to_string(tmp_loc.clone()));
+    let body = error::helper(fs::read_to_string(&tmp_loc));
     error::helper(fs::remove_file(tmp_loc));
     body
 }
3-20 20:27:01 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-03-20 20:27:01 -0700 959' href='/akkartik/mu/commit/cpp/025name?h=main&id=fc55fea025bdb1c6945e6812d49a6d41e8f3c062'>fc55fea0 ^
80b781cc ^











fc55fea0 ^







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70