aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-05-05 02:51:36 +0200
committerGravatar Tom Willemse2013-05-05 02:51:36 +0200
commit77513487aa995625fd7af1f9f78f6016e7058445 (patch)
treebc4babd0a36f12f6ff2756b1df8ed16d92f6cc72
parentc688bfb73e54f4e6f390f6896f51995f590f8ca8 (diff)
downloadgitto-77513487aa995625fd7af1f9f78f6016e7058445.tar.gz
gitto-77513487aa995625fd7af1f9f78f6016e7058445.zip
Load an initialization file at startup
This file is located either in XDG_CONFIG_HOME or, in case XDG_CONFIG_HOME is empty, in HOME/.config/gitto.
-rw-r--r--gitto/main.scm50
1 files changed, 31 insertions, 19 deletions
diff --git a/gitto/main.scm b/gitto/main.scm
index e47ad78..ae1ce58 100644
--- a/gitto/main.scm
+++ b/gitto/main.scm
@@ -1,3 +1,4 @@
+;; -*- coding: utf-8; -*-
;; gitto -- Keep track of your git repositories
;; Copyright (C) 2012 Tom Willemsen <tom at ryuslash dot org>
@@ -24,23 +25,15 @@
#:use-module (gitto path)
#:export (main))
-(define data-dir
- (let ((xdg (getenv "XGD_DATA_HOME"))
- (name "gitto"))
- (if xdg
- (string-append xdg "/" name)
- (string-append (getenv "HOME") "/." name))))
+(define (storage-dir xdg-env fallback)
+ (let ((xdg (getenv xdg-env)))
+ (string-append
+ (or xdg (getenv "HOME")) (unless xdg "/" fallback) "/gitto")))
-(define repositories-file
- (string-append data-dir "/repos.scm"))
-
-(define repositories
- (if (file-exists? repositories-file)
- (let* ((port (open-input-file repositories-file))
- (result (read port)))
- (close-port port)
- result)
- '()))
+(define (config-dir) (storage-dir "XDG_CONFIG_HOME" "/.config"))
+(define (config-file file) (string-append (config-dir) "/" file))
+(define (data-dir) (storage-dir "XDG_DATA_HOME" "/.local/share"))
+(define (data-file file) (string-append (data-dir) "/" file))
(define (version)
"Display version information."
@@ -78,8 +71,9 @@ gitto [options]
(define (save-repositories-list)
"Save the list of repositories."
- (if (not (file-exists? data-dir))
- (mkdir data-dir))
+ (let ((dir (data-dir)))
+ (unless (file-exists? dir)
+ (mkdir dir)))
;; Sort first
(set! repositories
@@ -202,7 +196,14 @@ to the tracked files. Utracked files will not register."
(removal? (option-ref options 'remove #f))
(list? (option-ref options 'repositories #f))
(purge? (option-ref options 'purge #f))
- (check? (option-ref options 'check #f)))
+ (check? (option-ref options 'check #f))
+ (cfg (config-file "rc.scm")))
+ (when (file-exists? cfg)
+ (save-module-excursion
+ (lambda ()
+ (set-current-module (resolve-module '(gitto main)))
+ (primitive-load cfg))))
+
(cond (version-wanted? (version))
(help-wanted? (help))
(registration-needed? => register-repository)
@@ -211,3 +212,14 @@ to the tracked files. Utracked files will not register."
(purge? (purge))
(check? => repository-registered?)
(#t (list-repositories)))))
+
+(define repositories-file
+ (data-file "repos.scm"))
+
+(define repositories
+ (if (file-exists? repositories-file)
+ (let* ((port (open-input-file repositories-file))
+ (result (read port)))
+ (close-port port)
+ result)
+ '()))