lens-filesystem: Lens interface for your filesystem; still a bit experimental

[ bsd3, control, library ] [ Propose Tags ] [ Report a vulnerability ]

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


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.0.0, 0.1.0.0, 0.1.0.1
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 christopher.penner@gmail.com
Category Control
Home page https://github.com/ChrisPenner/lens-filesystem
Bug tracker https://github.com/ChrisPenner/lens-filesystem/issues
Source repo head: git clone https://github.com/ChrisPenner/lens-filesystem
Uploaded by ChrisPenner at 2020-10-21T04:00:50Z
Distributions
Downloads 744 total (13 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for lens-filesystem-0.1.0.1

[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