Created
March 11, 2019 14:10
-
-
Save jboynyc/9a22ea59e3819db37f37abf4b6570020 to your computer and use it in GitHub Desktop.
toggle active script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env guile | |
!# | |
;; Toggle symlink to current directory on and off in a directory of "active" | |
;; directories. Unless otherwise specified by a $ACTIVE_DIR environment | |
;; variable, the active directory is assumed to be located in ~/Active. | |
(use-modules (ice-9 ftw)) | |
(define (symlink? path) | |
(equal? (vector-ref (lstat path) 13) | |
'symlink)) | |
(let* ([active-dir (if (getenv "ACTIVE_DIR") | |
(getenv "ACTIVE_DIR") | |
(string-append | |
(passwd:dir (getpw (getlogin))) | |
file-name-separator-string | |
"Active"))] | |
[pwd-name (basename (getcwd))] | |
[actives (scandir active-dir)] | |
[newpath (string-append active-dir | |
file-name-separator-string | |
pwd-name)]) | |
(cond | |
[(and (member pwd-name actives) | |
(symlink? newpath)) | |
(delete-file newpath)] | |
[(member pwd-name actives) | |
#f] | |
['else | |
(symlink (getcwd) newpath)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment