!! Recover -- fetch file from ~/backup ---- #!/bin/sh IFS=" " exec scsh -s "$0" "$@" !# (if (not (= (length (command-line)) 2)) (error (string-append "usage: " (car (command-line)) " file-to-recover"))) (define file-name (absolute-file-name (cadr (command-line)))) (define backup-name (cond ((regexp-search (rx (seq "/home/" (submatch (** 4 8 lower-case)))) file-name) => (lambda (m) (regexp-substitute #f m 'pre "/home/" 1 "/backup" 'post))) (else (error "cannot match in " file-name)))) (if (file-not-exists? backup-name) (error (format #f "Cannot find the backup file ~a\n of file ~a" backup-name file-name))) (if (file-exists? file-name) (begin (format #t "File ~a exists.\nDo you want to overwrite it? (y or n) " file-name) (let ((answer (read))) (if (not (eq? answer 'y)) (error "abort by user choice"))))) (run (cp -pv ,backup-name ,file-name))