mirror of https://codeberg.org/glenneth/stash.git
Removed rename option and reverted to letters choice
This commit is contained in:
parent
4c624c8498
commit
b04665ca43
68
stash2.scm
68
stash2.scm
|
|
@ -35,17 +35,30 @@
|
|||
#f))
|
||||
|
||||
(define (prompt-user-for-action)
|
||||
"Prompt the user to decide how to handle a conflict: overwrite (o), skip (s), or rename (r)."
|
||||
(display (color-message "A conflict was detected. Choose action - Overwrite (o), Skip (s), or Rename (r): " yellow-text))
|
||||
"Prompt the user to decide how to handle a conflict: overwrite (o), skip (s), or cancel (c)."
|
||||
(display (color-message "A conflict was detected. Choose action - Overwrite (o), Skip (s), or Cancel (c): " yellow-text))
|
||||
(let ((response (read-line)))
|
||||
(cond
|
||||
((string-ci=? response "o") 'overwrite)
|
||||
((string-ci=? response "s") 'skip)
|
||||
((string-ci=? response "r") 'rename)
|
||||
((string-ci=? response "c") 'cancel)
|
||||
(else
|
||||
(display (color-message "Invalid input. " red-text))
|
||||
(display (color-message "Invalid input. Please try again.\n" red-text))
|
||||
(prompt-user-for-action))))) ; Recursive call on invalid input.
|
||||
|
||||
|
||||
;; (define (prompt-user-for-action)
|
||||
;; "Prompt the user to decide how to handle a conflict: overwrite (o), skip (s), or rename (r)."
|
||||
;; (display (color-message "A conflict was detected. Choose action - Overwrite (o), Skip (s), or Rename (r): " yellow-text))
|
||||
;; (let ((response (read-line)))
|
||||
;; (cond
|
||||
;; ((string-ci=? response "o") 'overwrite)
|
||||
;; ((string-ci=? response "s") 'skip)
|
||||
;; ((string-ci=? response "r") 'rename)
|
||||
;; (else
|
||||
;; (display (color-message "Invalid input. " red-text))
|
||||
;; (prompt-user-for-action))))) ; Recursive call on invalid input.
|
||||
|
||||
(define (file-is-symlink? path)
|
||||
;; Use lstat to check if the file is a symbolic link without following it
|
||||
(let ((stat (lstat path)))
|
||||
|
|
@ -70,14 +83,9 @@
|
|||
(define (handle-conflicts source target)
|
||||
;; Display the conflict message in yellow (warning).
|
||||
(display (color-message (format #f "Conflict detected! A symbolic link already exists at ~a.\n" target) yellow-text))
|
||||
(display "Do you want to:\n")
|
||||
(display "1. Remove the existing symbolic link and create a new one\n")
|
||||
(display "2. Keep the existing symbolic link\n")
|
||||
(display "3. Cancel the operation\n")
|
||||
(display "> ")
|
||||
(let ((choice (read)))
|
||||
(let ((choice (prompt-user-for-action))) ;; Call the updated prompt-user-for-action
|
||||
(cond
|
||||
((eq? choice 1)
|
||||
((eq? choice 'overwrite)
|
||||
;; Check if the target is a symlink, and remove the symlink (not the directory it points to).
|
||||
(if (file-is-symlink? target)
|
||||
(begin
|
||||
|
|
@ -86,19 +94,51 @@
|
|||
;; Now, recreate the symlink after removing the old one
|
||||
(create-symlink source (dirname target)))
|
||||
(display (color-message "Error: Target is not a symbolic link.\n" red-text))))
|
||||
((eq? choice 2)
|
||||
((eq? choice 'skip)
|
||||
;; Do nothing; keep the existing symbolic link.
|
||||
(display (color-message "Keeping existing symbolic link.\n" green-text)))
|
||||
((eq? choice 3)
|
||||
((eq? choice 'cancel)
|
||||
;; Cancel the operation and exit
|
||||
(display (color-message "Operation cancelled.\n" yellow-text))
|
||||
(exit 0))
|
||||
(else
|
||||
;; Invalid input, so retry.
|
||||
;; Invalid input (this should never happen because prompt-user-for-action handles it).
|
||||
(display (color-message "Invalid choice. Please try again.\n" red-text))
|
||||
(handle-conflicts source target)))))
|
||||
|
||||
|
||||
;; (define (handle-conflicts source target)
|
||||
;; ;; Display the conflict message in yellow (warning).
|
||||
;; (display (color-message (format #f "Conflict detected! A symbolic link already exists at ~a.\n" target) yellow-text))
|
||||
;; (display "Do you want to:\n")
|
||||
;; (display "1. Remove the existing symbolic link and create a new one\n")
|
||||
;; (display "2. Keep the existing symbolic link\n")
|
||||
;; (display "3. Cancel the operation\n")
|
||||
;; (display "> ")
|
||||
;; (let ((choice (read)))
|
||||
;; (cond
|
||||
;; ((eq? choice 1)
|
||||
;; ;; Check if the target is a symlink, and remove the symlink (not the directory it points to).
|
||||
;; (if (file-is-symlink? target)
|
||||
;; (begin
|
||||
;; (delete-file target) ;; Safely delete the symlink.
|
||||
;; (display (color-message "Removed the existing symbolic link.\n" green-text))
|
||||
;; ;; Now, recreate the symlink after removing the old one
|
||||
;; (create-symlink source (dirname target)))
|
||||
;; (display (color-message "Error: Target is not a symbolic link.\n" red-text))))
|
||||
;; ((eq? choice 2)
|
||||
;; ;; Do nothing; keep the existing symbolic link.
|
||||
;; (display (color-message "Keeping existing symbolic link.\n" green-text)))
|
||||
;; ((eq? choice 3)
|
||||
;; ;; Cancel the operation and exit
|
||||
;; (display (color-message "Operation cancelled.\n" yellow-text))
|
||||
;; (exit 0))
|
||||
;; (else
|
||||
;; ;; Invalid input, so retry.
|
||||
;; (display (color-message "Invalid choice. Please try again.\n" red-text))
|
||||
;; (handle-conflicts source target)))))
|
||||
|
||||
|
||||
;; (define (handle-conflicts source target)
|
||||
;; ;; Display the conflict message in yellow (warning).
|
||||
;; (display (color-message (format #f "Conflict detected! A symbolic link already exists at ~a.\n" target) yellow-text))
|
||||
|
|
|
|||
Loading…
Reference in New Issue