subtree(users/wpcarro): docking briefcase at '24f5a642'
git-subtree-dir: users/wpcarro git-subtree-mainline:464bbcb15cgit-subtree-split:24f5a642afChange-Id: I6105b3762b79126b3488359c95978cadb3efa789
This commit is contained in:
commit
019f8fd211
766 changed files with 175420 additions and 0 deletions
70
users/wpcarro/emacs/.emacs.d/wpc/fs.el
Normal file
70
users/wpcarro/emacs/.emacs.d/wpc/fs.el
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
;;; fs.el --- Make working with the filesystem easier -*- lexical-binding: t -*-
|
||||
|
||||
;; Author: William Carroll <wpcarro@gmail.com>
|
||||
;; Version: 0.0.1
|
||||
;; URL: https://git.wpcarro.dev/wpcarro/briefcase
|
||||
;; Package-Requires: ((emacs "24.1"))
|
||||
|
||||
;;; Commentary:
|
||||
;; Ergonomic alternatives for working with the filesystem.
|
||||
|
||||
;;; Code:
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Dependencies
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(require 'dash)
|
||||
(require 'f)
|
||||
(require 's)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Library
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun fs-ensure-file (path)
|
||||
"Ensure that a file and its directories in `PATH' exist.
|
||||
Will error for inputs with a trailing slash."
|
||||
(when (s-ends-with? "/" path)
|
||||
(error (format "Input path has trailing slash: %s" path)))
|
||||
(->> path
|
||||
f-dirname
|
||||
fs-ensure-dir)
|
||||
(f-touch path))
|
||||
|
||||
(f-dirname "/tmp/a/b/file.txt")
|
||||
|
||||
(defun fs-ensure-dir (path)
|
||||
"Ensure that a directory and its ancestor directories in `PATH' exist."
|
||||
(->> path
|
||||
f-split
|
||||
(apply #'f-mkdir)))
|
||||
|
||||
(defun fs-ls (dir &optional full-path?)
|
||||
"List the files in `DIR' one-level deep.
|
||||
Should behave similarly in spirit to the Unix command, ls.
|
||||
If `FULL-PATH?' is set, return the full-path of the files."
|
||||
(-drop 2 (directory-files dir full-path?)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Tests
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(ert-deftest fs-test-ensure-file ()
|
||||
(let ((file "/tmp/file/a/b/c/file.txt"))
|
||||
;; Ensure this file doesn't exist first to prevent false-positives.
|
||||
(f-delete file t)
|
||||
(fs-ensure-file file)
|
||||
(should (and (f-exists? file)
|
||||
(f-file? file)))))
|
||||
|
||||
(ert-deftest fs-test-ensure-dir ()
|
||||
(let ((dir "/tmp/dir/a/b/c"))
|
||||
;; Ensure the directory doesn't exist.
|
||||
(f-delete dir t)
|
||||
(fs-ensure-dir dir)
|
||||
(should (and (f-exists? dir)
|
||||
(f-dir? dir)))))
|
||||
|
||||
(provide 'fs)
|
||||
;;; fs.el ends here
|
||||
Loading…
Add table
Add a link
Reference in a new issue