lens-filesystem

[ bsd3, library, unclassified ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/ChrisPenner/lens-fs#readme


[Skip to Readme]
Versions [faq] 0.0.0.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), directory, filepath, lens, lens-action [details]
License BSD-3-Clause
Copyright 2019 Chris Penner
Author Chris Penner
Maintainer example@example.com
Home page https://github.com/ChrisPenner/lens-filesystem#readme
Bug tracker https://github.com/ChrisPenner/lens-filesystem/issues
Source repo head: git clone https://github.com/ChrisPenner/lens-filesystem
Uploaded by ChrisPenner at Fri Jun 21 12:03:27 UTC 2019
Distributions NixOS:0.0.0.0
Downloads 47 total (10 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for lens-filesystem-0.0.0.0

[back to package description]

lens-filesystem

HACKAGE

A lensy style interface to your filesystem.

This is pretty experimental; I wouldn't recommend using it in production code at the moment; Using the read-only operations should be fine, but I'd strongly recommend doing lots of testing with print before you run destructive filesystem operations.

This library is meant to be used in conjunction with the lens-action library.

The interface to this package could change at any time.

Examples:

Many of the combinators you see here come from `lens-action`.

-- Find all files in ~ or ~/config with a .vim or .conf extension
>>> "/Users/chris" ^!! including (path "config") . ls . traversed . exts ["vim", "conf"]
["/Users/chris/.vim","/Users/chris/tmux.conf","/Users/chris/config/plugins.vim"]

-- Check whether a filename is a dotfile
>>> let isDotfile = has (filename . _head . only '.')
-- Crawl a filetree according to a given fold, 
-- e.g. crawl all dirs that aren't dotfiles (a.k.a. .git, .stack-work)
>>> "." ^!! crawling (ls'ed . dirs . filtered (not . isDotfile))
[ "." , "./app" , "./test" , "./src" , "./src/Control"
, "./src/Control/Lens", "./src/Control/Lens/FileSystem"]

-- Crawl ALL files in "src" collecting "*.hs" files, then make file paths absolute
>>> "src" ^!! crawled . exts ["hs"] . absolute
[ "/Users/chris/dev/lens-fs/src/Control/Lens/FileSystem/Combinators.hs"
, "/Users/chris/dev/lens-fs/src/Control/Lens/FileSystem.hs" ]

-- Find all executables in the 'scripts' directory and copy them to bin
>>> "scripts" ^! crawled . withPerms [executable] . act (`copyFile` "/Users/chris/bin")

-- Read all markdown files and get their contents with filename
>>> "./test" ^!! crawled . exts ["md"] . contents . withIndex
[("./test/data/flat/file.md","markdown\n")]

See more examples in the tests