Look into system hook dir if scripts not found in homedir
[gregoa/zavai.git] / src / config.vala
index 444bbc2e2a96dc23bb61e8cde1a1e96270d04936..5a982be81cb5d75cf02a99ea1a5e3162e8c2988b 100644 (file)
@@ -228,6 +228,24 @@ public class Config
         refresh_from_lua();
     }
 
+    /**
+     * Find a zavai script.
+     * 
+     * ~/.zavai/NAME is searched first, then /usr/share/zavai/hooks/
+     *
+     * If the script is not found, NULL is returned
+     */
+    public string find_script(string name)
+    {
+        string candidate = homedir + "/" + name;
+        if (FileUtils.test(candidate, FileTest.EXISTS))
+            return candidate;
+        candidate = "/usr/share/zavai/hooks/" + name;
+        if (FileUtils.test(candidate, FileTest.EXISTS))
+            return candidate;
+        return null;
+    }
+
     public void run_script(string command)
     {
         zavai.log.info("Run program: " + command);