Skip to content

Instantly share code, notes, and snippets.

@jboynyc
Created March 11, 2019 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jboynyc/9a22ea59e3819db37f37abf4b6570020 to your computer and use it in GitHub Desktop.
Save jboynyc/9a22ea59e3819db37f37abf4b6570020 to your computer and use it in GitHub Desktop.
toggle active script
#!/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