hopefully fixed this dumpster fire of code up?
parent
cf4af31cd7
commit
525326c5dd
|
@ -41,9 +41,12 @@
|
||||||
'couldnt-find-file
|
'couldnt-find-file
|
||||||
(format (string-append "Error: Couldn't find ~a" newline
|
(format (string-append "Error: Couldn't find ~a" newline
|
||||||
"Either the file doesn't exist, or the permissions are incorrect." newline
|
"Either the file doesn't exist, or the permissions are incorrect." newline
|
||||||
"If the file exists, try running chmod 600 ~a")
|
"If the file exists, try running chmod 600 ~a"
|
||||||
|
"If the file doesn't exist, try running ~a ~a")
|
||||||
program-path
|
program-path
|
||||||
program-path)
|
program-path
|
||||||
|
program-name
|
||||||
|
init-command)
|
||||||
|
|
||||||
'error-something-exists
|
'error-something-exists
|
||||||
(format "Error: It looks like ~a already exists." program-path)
|
(format "Error: It looks like ~a already exists." program-path)
|
||||||
|
@ -107,7 +110,7 @@
|
||||||
(close-output-port (open-output-file string)))
|
(close-output-port (open-output-file string)))
|
||||||
|
|
||||||
(define (has-read-permissions? string)
|
(define (has-read-permissions? string)
|
||||||
(equal? program-permissions (file-or-directory-permissions string 'bits)))
|
(equal? read-permissions (file-or-directory-permissions string 'bits)))
|
||||||
|
|
||||||
;; ------------------------------------------------
|
;; ------------------------------------------------
|
||||||
;; init
|
;; init
|
||||||
|
@ -148,10 +151,13 @@
|
||||||
(displayln item))))
|
(displayln item))))
|
||||||
|
|
||||||
(define (ls)
|
(define (ls)
|
||||||
|
(if (and (file-exists? program-file)
|
||||||
|
(has-read-permissions? program-file))
|
||||||
(let ([listof-items (file->lines program-path)])
|
(let ([listof-items (file->lines program-path)])
|
||||||
(if (null? listof-items)
|
(if (null? listof-items)
|
||||||
(displayln-messages-ref 'empty-list)
|
(displayln-messages-ref 'empty-list)
|
||||||
(ls/display-list listof-items))))
|
(ls/display-list listof-items)))
|
||||||
|
(displayln-messages-ref 'couldnt-file-file)))
|
||||||
|
|
||||||
;; ------------------------------------------------
|
;; ------------------------------------------------
|
||||||
;; rm
|
;; rm
|
||||||
|
@ -168,22 +174,28 @@
|
||||||
(displayln-messages-ref 'error-item-not-found))))
|
(displayln-messages-ref 'error-item-not-found))))
|
||||||
|
|
||||||
(define (rm arg)
|
(define (rm arg)
|
||||||
|
(if (and (file-exists? program-file)
|
||||||
|
(has-read-permissions? program-file))
|
||||||
(let ([item-number (string->number arg)])
|
(let ([item-number (string->number arg)])
|
||||||
(if item-number
|
(if item-number
|
||||||
(rm/remove-nicething item-number)
|
(rm/remove-nicething item-number)
|
||||||
(displayln-format-messages-ref 'error-not-a-number arg))))
|
(displayln-format-messages-ref 'error-not-a-number arg)))
|
||||||
|
(displayln-messages-ref 'couldnt-find-file)))
|
||||||
|
|
||||||
;; ------------------------------------------------
|
;; ------------------------------------------------
|
||||||
;; add
|
;; add
|
||||||
;; ------------------------------------------------
|
;; ------------------------------------------------
|
||||||
(define (add nicething)
|
(define (add nicething)
|
||||||
|
(if (and (file-exists? program-file)
|
||||||
|
(has-read-permissions? program-file))
|
||||||
;; The removing and adding of the '\n' is to
|
;; The removing and adding of the '\n' is to
|
||||||
;; ensure only one '\n' exists at the end of the
|
;; ensure only one '\n' exists at the end of the
|
||||||
;; item to be added.
|
;; item to be added.
|
||||||
(let* ([nicething-no-newline (string-replace nicething "\n" "")]
|
(let* ([nicething-no-newline (string-replace nicething "\n" "")]
|
||||||
[nicething-newline (string-append nicething-no-newline "\n")])
|
[nicething-newline (string-append nicething-no-newline "\n")])
|
||||||
(display-to-file nicething-newline program-path #:exists 'append)
|
(display-to-file nicething-newline program-path #:exists 'append)
|
||||||
(displayln-format-messages-ref 'added nicething-no-newline)))
|
(displayln-format-messages-ref 'added nicething-no-newline))
|
||||||
|
(displayln-messages-ref 'couldnt-find-file)))
|
||||||
|
|
||||||
;; ------------------------------------------------
|
;; ------------------------------------------------
|
||||||
;; random message
|
;; random message
|
||||||
|
@ -193,7 +205,7 @@
|
||||||
;; `#:build? #t` Builds full paths for all items listed in /home/
|
;; `#:build? #t` Builds full paths for all items listed in /home/
|
||||||
[listof-home-directories (directory-list root-home #:build? #t)]
|
[listof-home-directories (directory-list root-home #:build? #t)]
|
||||||
[listof-nicethings-paths (map (lambda (x) (build-path x program-file))
|
[listof-nicethings-paths (map (lambda (x) (build-path x program-file))
|
||||||
(listof-home-directories))]
|
listof-home-directories)]
|
||||||
[paths-with-nicethings (filter file-exists? listof-nicethings-paths)]
|
[paths-with-nicethings (filter file-exists? listof-nicethings-paths)]
|
||||||
[paths-readable (filter has-read-permissions? paths-with-nicethings)]
|
[paths-readable (filter has-read-permissions? paths-with-nicethings)]
|
||||||
[listof-nicethings (apply append (map file->lines paths-readable))]
|
[listof-nicethings (apply append (map file->lines paths-readable))]
|
||||||
|
@ -243,9 +255,6 @@
|
||||||
[(vector _ ...) (displayln-messages-ref 'error-incorrect-usage)]))
|
[(vector _ ...) (displayln-messages-ref 'error-incorrect-usage)]))
|
||||||
|
|
||||||
(define (main vectorof-args)
|
(define (main vectorof-args)
|
||||||
(if (and (file-exists program-file)
|
(process-args vectorof-args))
|
||||||
(has-read-permissions? program-file))
|
|
||||||
(process-args vectorof-args)
|
|
||||||
(displayln-messages-ref 'couldnt-find-file)))
|
|
||||||
|
|
||||||
(main (current-command-line-arguments))
|
(main (current-command-line-arguments))
|
||||||
|
|
Loading…
Reference in New Issue