#!/usr/bin/guile !# ; move a file or directory and replace it with a symlink to the new place. ; depends on guile and sph-lib. ; (import (sph filesystem) (sph cli) (sph) (sph alist) (sph process)) (define command-line-interface (cli-create #:options (q (((target-directory source-path ...) #:required? #t) (keep-directory-structure? #:names #\k))) #:description "move files and replace the source paths with symlinks to the move destination")) (define (move-and-link target-path source-path) "string ... -> (boolean ...) move a file or directory and replace it with a symlink to the new place" (let (target-path (path->full-path target-path)) (and (ensure-directory-structure target-path) (execute-and-check-result "mv" "-t" target-path source-path) (execute-and-check-result "ln" "-s" (string-append (ensure-trailing-slash target-path) (basename source-path)) (dirname source-path))))) (define (move-and-link-cli) (let* ((cli-options (command-line-interface)) (source-paths (alist-ref cli-options (q source-path)))) (if source-paths (let (target-directory (alist-ref cli-options (q target-directory))) (map (if (alist-ref-q cli-options keey-directory-structure?) (l (e) (move-and-link (path-append target-directory (dirname e)) e)) (l (e) (move-and-link target-directory e))) source-paths)) (command-line-interface (list "--help"))))) (move-and-link-cli)