mirror of
https://github.com/Yvee1/hascard.git
synced 2024-10-26 07:41:15 +03:00
Automatically remove deleted files from recents
This commit is contained in:
parent
ccba78b2cc
commit
243293736b
10
README.md
10
README.md
@ -16,11 +16,6 @@ A minimal commandline utility for reviewing notes. 'Flashcards' can be written i
|
||||
## Installation
|
||||
Installation on Windows is not possible sadly, aside from WSL. This is because hascard depends on vty which only supports unix operating systems (this includes macOS).
|
||||
|
||||
### Snapcraft
|
||||
Hascard is also on [snapcraft](https://snapcraft.io/hascard). Installation instructions are on that site. If you already have snap installed you can just install hascard via `sudo snap install hascard`. By default snap applications are isolated from the system and run in a sandbox. This means that hascard does not have permission to read or write any files on the system aside from those under `%HOME/snap/hascard`. To be able to read cards also in other directories under the home directory, hascard makes use of the `home` interface which might need to be enabled manually using `sudo snap connect hascard:home :home`.
|
||||
|
||||
**Note**: The installation with snapcraft does not work with all terminals, [known issues are with alacritty and st](https://github.com/Yvee1/hascard/issues/3), because of problems with terminfo that I do not know how to solve. With me, this did not happen with the other installation methods so try those if you have a somewhat non-standard terminal. If anyone knows what the problem might be, let me know!
|
||||
|
||||
### Homebrew (for macOS)
|
||||
For macOS users an installation using homebrew is provided via a custom tap. You can run
|
||||
```
|
||||
@ -31,6 +26,11 @@ brew install Yvee1/tools/hascard
|
||||
### Binary
|
||||
Linux and macOS binaries are available under [releases](https://github.com/Yvee1/hascard/releases/). To be able to run it from any directory, it has to be added to the PATH. This can be done by copying it to e.g. the `/usr/local/bin` directory.
|
||||
|
||||
### Snapcraft
|
||||
Hascard is also on [snapcraft](https://snapcraft.io/hascard). Installation instructions are on that site. If you already have snap installed you can just install hascard via `sudo snap install hascard`. By default snap applications are isolated from the system and run in a sandbox. This means that hascard does not have permission to read or write any files on the system aside from those under `%HOME/snap/hascard`. To be able to read cards also in other directories under the home directory, hascard makes use of the `home` interface which might need to be enabled manually using `sudo snap connect hascard:home :home`.
|
||||
|
||||
**Note**: The installation with snapcraft does not work with all terminals, [known issues are with alacritty and st](https://github.com/Yvee1/hascard/issues/3), because of problems with terminfo that I do not know how to solve. With me, this did not happen with the other installation methods so try those if you have a somewhat non-standard terminal. If anyone knows what the problem might be, let me know!
|
||||
|
||||
### Install from source
|
||||
Another option is to build hascard and install it from source. For this you can use the Haskell build tool called [stack](https://docs.haskellstack.org/en/stable/README/#how-to-install), or [nix](https://nixos.org/). Then for example clone this repository somewhere:
|
||||
```
|
||||
|
@ -11,6 +11,7 @@ import Brick.Widgets.Border
|
||||
import Brick.Widgets.Border.Style
|
||||
import Brick.Widgets.Center
|
||||
import Control.Exception (displayException, try)
|
||||
import Control.Monad (filterM)
|
||||
import Control.Monad.IO.Class
|
||||
import Data.Functor (void)
|
||||
import Data.List (sort)
|
||||
@ -146,9 +147,16 @@ getRecents = do
|
||||
rf <- getRecentsFile
|
||||
exists <- D.doesFileExist rf
|
||||
if exists
|
||||
then S.fromList . lines <$> IOS.readFile rf
|
||||
then removeDeletedFiles rf
|
||||
else return S.empty
|
||||
|
||||
removeDeletedFiles :: FilePath -> IO (Stack FilePath)
|
||||
removeDeletedFiles fp = do
|
||||
file <- IOS.readFile fp
|
||||
existing <- S.fromList <$> filterM D.doesFileExist (lines file)
|
||||
writeRecents existing
|
||||
return existing
|
||||
|
||||
maxRecents :: Int
|
||||
maxRecents = 5
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user