Compare commits

...

112 Commits
v1.0 ... master

Author SHA1 Message Date
Rafal Paluch 846349613f poprawka flash aby dzialala punktacja 2025-12-10 20:28:16 +01:00
pali112 942a39114f Update README.md 2025-12-09 13:25:26 -08:00
Juan Enrique 37f609eaeb
Update flash (#48)
Minor typo
2023-11-06 11:33:36 -08:00
Shubham Swapneel Shah 47a635a645
Updated Readme file (#43)
Co-authored-by: Bryan Jenks <bryanjenks@protonmail.com>
2021-10-11 01:17:34 -07:00
Sami Kankaristo 8915b54e22
Remove unnecessary `cd` commands; Output errors to stderr (#40)
As discussed in a YouTube comment (https://www.youtube.com/watch?v=KEWhOzDCfLg&lc=UgzqmZf7hgBRjGLe-Pp4AaABAg), the `cd` commands to "return" back to the original directory are unnecessary, because it is *impossible* for a script to change the working directory of a shell.

When you run a `cd` command in a script, the working directory does change, but only for the script. When the script exits, nothing has happened to the working directory of the shell where you ran the script.

In fact, it is *impossible* for a script to change the working directory of the shell, even if you wanted to do that. Some ways you can change the working directory:
- an alias that runs a `cd` command (an alias is equivalent to running the commands in your shell)
    - `alias gohome="cd ~"
- a shell function that runs a `cd` command (this is the primary reason why things like z.lua are implemented as a shell function, not a script)
    - `function gohome() { cd ~ }`
- sourcing a script (so there is a way to do it with a script, but you have to run the script in a specific way, and this will also make exit quit the shell, not just the script)
    - `source ./script-name`

These are the ways I know of doing it, there may be some others.

Even if a script could change the shell's working directory, `fla.sh` is doing `cd "$PWD"`, which is basically a no-op, because `$PWD` is automatically updated:
```bash
echo "$PWD"

# go to the flashcard decks directory
cd "$DIR"

echo "$PWD"
```

The above outputs:
```
/home/sami
/home/sami/.local/share/flash
```

So, doing `cd $PWD` actually would not return back to the original directory, it would stay in whatever directory you've cd'd into.

-----

Another minor change in this PR is to output errors to stderr instead of stdout (before this change, errors were output to stdout).

With `fla.sh`, this doesn't really make much of a difference, but generally you want to output errors to stderr. This is useful, if you want to run a script quietly, but still want to see errors. If errors are output to stderr, this can be done with by running e.g.:
```bash
./script-name > /dev/null
```

The above will hide all regular output (redirecting stdout to `/dev/null`), but will still show anything output to stderr (i.e. error messages). To also hide error messages (make a script run completely silently), you can run:
```bash
./script-name > /dev/null 2>&1
```

The above `2>&1` syntax redirects stderr (`2>`) to the same place where stdout is redirected, and `> /dev/null` is redirecting stdout to `/dev/null`.

To only hide error messages, but show regular output, you could run `./script-name 2> /dev/null`, but that might not be a smart thing to do (if there are errors, you probably want to know about them).

The proposed change uses `>&2`, which redirects stdout to stderr, so that regular print commands (e.g. `echo`) are displayed on stderr. Both stdout and stderr are shown similarly in a terminal, but they're still separate, so they can be redirected, etc. Some terminals may also show stderr messages differently.

Both `echo "..." >&2` and `>&2 echo "..."` work identically, but I've used `>&2 echo "..."` because I think it's more intentional ("the following output is an error"), and if there's a long error message, the `>&2` could get "lost" at the end of a line. I picked it up on Stack Overflow, and I've used it ever since:
https://stackoverflow.com/a/23550347
2021-01-24 14:52:57 -08:00
Bryan Jenks f5ebff2e15
update version? 2021-01-24 14:23:08 -08:00
bryan 960f0b4316 bye bye travis 2020-12-12 23:27:35 -08:00
Bryan Jenks a16bd4393c
try this one? 2020-12-12 23:22:36 -08:00
Bryan Jenks d98f6a4a0b
fix name 2020-12-12 23:19:47 -08:00
Bryan Jenks 3876b727d5
add shell check gh action 2020-12-12 23:19:26 -08:00
Bryan Jenks 7b5b838965
add GH sponsors 2020-12-09 09:23:13 -08:00
bryan 58763294be Merge branch 'master' of https://github.com/tallguyjenks/fla.sh into master 2020-12-06 18:53:33 -08:00
bryan 8876db2694 --number to -b for portability solves #39 2020-12-06 18:53:10 -08:00
Bryan Jenks bf17b7d3c0
Version update in the command 2020-10-16 09:43:03 -07:00
Bryan Jenks 3ea4c26568
test workflows 2020-09-29 21:34:44 -07:00
Bryan Jenks 5ebdfbe263
test stale workflow 2020-09-29 21:31:08 -07:00
Bryan Jenks eeb7ed900a
smart phone verbiage 2020-09-29 14:55:47 -07:00
Bryan Jenks c6e14ac11e
fix weird commit 2020-09-17 11:14:22 -07:00
bryan 032ed7b627 Auto stash before merge of "master" and "origin/master" 2020-08-16 00:43:28 -07:00
eriteric 1f9a0ea7c8
provided extension for sed backups (#35)
* provided extension for sed backups

* Use ./*glob* in rm so names with dashes won't become options
2020-08-09 21:15:06 -07:00
anntnzrb 55b8b9a896
shfmt formatting & if-else shortened (minor) (#33)
* Applied shfmt formatting

* Minor optimizations

Some if-else flows only contained 1 statement, in shell, a shorter
version of those can be achieved by using the conditional operators,
among other tiny edits.

* Extra safety for multiple conditions

This is probably unnecessary, but just for extra safety, braces can be
added.
2020-08-05 22:42:58 -07:00
Bryan Jenks 81ca45379b
fix last merge conflict 2020-07-19 19:05:43 -07:00
Bryan Jenks f7293945b0
fix merge issue
cli can be a pain sometimes
2020-07-19 19:01:25 -07:00
bryan jenks 4813d37150 Merge branch 'master' of https://github.com/tallguyjenks/fla.sh 2020-07-19 18:59:30 -07:00
bryan jenks 1444e989bb fix date for mac in .review 2020-07-19 18:51:11 -07:00
Gustavo 96762bab04
Fix bug: review log (#32)
* Make the cards look more like cards.

* travis

* travis

* travis 2

* Fix bug: review log

* travis 3

Co-authored-by: Bryan Jenks <bryanjenks@protonmail.com>
2020-07-19 18:12:21 -07:00
bryan jenks e087cefecd increase portability for mac 2020-07-19 18:06:03 -07:00
Gustavo 748b79e8d4
Make the cards look more like cards. (#31)
* Make the cards look more like cards.

* travis

* travis

* travis 2
2020-07-17 12:19:48 -07:00
Bryan Jenks e2384023d0 prevent word splitting 2020-07-16 08:22:16 -07:00
Bryan Jenks 929c8e3bbc resolves #30 thanks @gnstaxo 2020-07-16 08:13:47 -07:00
Bryan Jenks 19ce0564bc move function higher for no hoisting 2020-05-25 21:28:15 -07:00
Bryan Jenks 511e721456 resolves #24 2020-05-25 21:27:12 -07:00
Bryan Jenks 33171e44fc fully resolves #27 and extention to it 2020-05-25 21:21:02 -07:00
Bryan Jenks f8da7b93df resolves 27 2020-05-25 21:15:12 -07:00
Bryan Jenks ae3158e30e add exit code numbers 2020-05-25 21:07:40 -07:00
Bryan Jenks 58e6c296ad update documentation 2020-05-15 14:41:19 -07:00
Bryan Jenks 99ff56fa07 formatting help text 2020-05-15 14:36:54 -07:00
Bryan Jenks eb8d41e7f3 colorize more output and linebreak on quit 2020-05-15 14:34:21 -07:00
Bryan Jenks 9b8abbe476
Merge pull request #28 from jsnal/master
Add the ability to change the FZF previewer.
2020-05-15 14:30:20 -07:00
jsnal 51ab50d081 refactor(pull request): update quotes and new line
Add quotes around variables so the script is more POSIX compliant. Also
add new line for styling.
2020-05-15 17:11:19 -04:00
jsnal 8a87104009 fix(shellcheck): fix mangled backslashes with read
Fixes SC2162

https://github.com/koalaman/shellcheck/wiki/SC2162
2020-05-15 15:00:24 -04:00
jsnal 8683c4d974 refactor(pull request): update usage and sleep command per pull request
Add a list of supported binaries for the `-p` flag and use read instead
of sleep when falling back onto the bat.
2020-05-15 14:57:20 -04:00
jsnal 0c11309a4d fix(shellcheck): fix oneline if-then-else shellcheck
Fixes SC2015 and SC2086

https://github.com/koalaman/shellcheck/wiki/SC2015
https://github.com/koalaman/shellcheck/wiki/SC2086
2020-05-14 20:17:32 -04:00
Bryan Jenks 12815c487a update shellcheck to allow bashishms since its a bash script anyhow 2020-05-14 17:16:44 -07:00
jsnal 864d0149ce feat(usage): update usage for new previewer feature
Add the documentation for changing the FZF previewer binary. The help
page kind of looks weird now that the alignment is off. That is
something that might need to be refactored in the future.
2020-05-14 19:47:08 -04:00
jsnal 5f50b2e042 feat(flash): allow the use of previewers other than bat
This commit adds a way of changing the FZF previewer by using the `-p`
flag. An example of this might look like:

$ flash -p cat

This will use cat has the FZF previewer instead of bat. However, it keeps bat as
the default program in all cases unless specifically changed by the `-p`
parameter. There are also checks to see if the provided binary actually
exists on the system. If it exists on the system, it checks if it
supported by flash. If it isn't supported by flash, it falls back onto
bat as the default previewer. For now, only bat and cat are supported but it.
can easily be expanded.
2020-05-14 19:41:11 -04:00
Bryan Jenks c746f2545b update for real, last overwritten by git pull 2020-05-14 12:39:36 -07:00
Bryan Jenks b5351f7826 Merge branch 'master' of github.com:tallguyjenks/fla.sh 2020-05-14 12:37:04 -07:00
Bryan Jenks d13b0b5cbe updated examples screen shot 2020-05-14 12:36:44 -07:00
Bryan Jenks 73e4ea3f3e
update README after #11 resolution 2020-05-14 11:43:34 -07:00
Bryan Jenks 922484fbe5
Merge pull request #26 from jsnal/master
Fix macOS installation function
2020-05-14 11:38:52 -07:00
jsnal 18c3e510f2 fix(setup): fix setup on macOS
Fix the setup function on macOS by removing the `eval` in the `touch`
statement. This fix worked for me on macOS 10.14.6, however, this hasn't
been tested with other versions of macOS. I checked that the script still works in
Linux as well.
2020-05-14 14:31:34 -04:00
Bryan Jenks e81305222b
downloads tag doesnt function
kill it
2020-05-10 08:26:40 -07:00
Bryan Jenks d73faea243 less echo cmd calls, same output 2020-05-09 05:31:26 -07:00
Bryan Jenks 1ba3b21993 resolves #23 2020-05-07 20:12:58 -07:00
Bryan Jenks b879ece0ac add troubeshoot sect. fill out with issues, when stable 2020-05-07 19:09:52 -07:00
Bryan Jenks a1e17bad9d fix function close brace 2020-05-07 14:05:14 -07:00
Bryan Jenks 15e8648e4b when mac install coreutils, alias gshuf to shuf 2020-05-07 13:59:20 -07:00
Bryan Jenks e239411053 messed up mac home variable creation 2020-05-07 13:57:18 -07:00
Bryan Jenks 448648ca84 fix final shell checks 2020-05-05 20:55:57 -07:00
Bryan Jenks 3530948c4a new help/info system resolves #14 2020-05-05 20:54:02 -07:00
Bryan Jenks a37873cf0c version number aesthetics completed 2020-05-05 20:15:36 -07:00
Bryan Jenks a0b1582aaa building opts capturing for version and help msg 2020-05-05 20:11:40 -07:00
Bryan Jenks d68ba42e4d Merge branch 'master' of github.com:tallguyjenks/fla.sh 2020-05-05 19:43:18 -07:00
Bryan Jenks 5273ba6410 shell checks completed and functionality retained 2020-05-05 19:42:55 -07:00
Bryan Jenks 516cd4016c shell check cleanup and clear on answer screen exit 2020-05-05 19:33:33 -07:00
Bryan Jenks dcace35df8
fix travis badge 2020-05-05 19:23:39 -07:00
Bryan Jenks d05da35ba8 resolve #22 2020-05-05 19:16:55 -07:00
Bryan Jenks e30be22339 prefer XDG over hard coded paths, resolves #17 2020-05-04 13:07:23 -07:00
Bryan Jenks 2f6e8b6c11 Add opt to quit at question screen & clear output 2020-05-04 13:05:45 -07:00
Bryan Jenks 10ac67e47c another #15 fix for control of keys on scoring 2020-05-04 11:26:55 -07:00
Bryan Jenks 949d92fde7 add prompts for keypresses resolves #15 2020-05-04 11:22:54 -07:00
Bryan Jenks 24975ea398 comments and change whitespace to escape chars 2020-05-04 10:59:21 -07:00
Bryan Jenks cc7869561e minor edits 2020-05-04 10:59:10 -07:00
Bryan Jenks 59dea80580 Merge branch 'master' of github.com:tallguyjenks/fla.sh 2020-05-03 15:49:27 -07:00
Bryan Jenks 3de1eb344f change diplay in terminal from flash.sh to fla.sh 2020-05-03 15:48:55 -07:00
Bryan Jenks 3180294579
Merge pull request #21 from macxcool/master
Fixed up grammar and syntax in the examples
2020-05-03 09:42:39 -07:00
Mark Coolen 032afa2f53 Fixed up grammar and syntax in the examples 2020-05-03 08:10:36 -04:00
Bryan Jenks 87ad14476e update name refs in all links and content 2020-05-02 15:55:24 -07:00
Bryan Jenks 8a54999d02 update header image 2020-05-02 15:53:22 -07:00
Bryan Jenks cd5d74016f remove slash from find command, why did i even... 2020-05-02 15:18:17 -07:00
Bryan Jenks 739088a887 rmeove that backslash for mac, doesnt work 2020-05-02 15:17:14 -07:00
Bryan Jenks b04dc856bf Add Brodie's vid to README 2020-05-02 14:54:55 -07:00
Bryan Jenks 23baa6d535 escape mac path space for tocu cmd 2020-05-01 19:12:27 -07:00
Bryan Jenks 5c717b1537 remove a command substitution 2020-05-01 14:20:59 -07:00
Bryan Jenks 0b1f60a960 change find commands from no path to './' 2020-05-01 13:56:01 -07:00
Bryan Jenks 9ab26d58fd try a command substitution 2020-04-29 15:26:40 -07:00
Bryan Jenks 1a243be7d0 replace brace expansion, try eval 2020-04-29 15:19:30 -07:00
Bryan Jenks 620e8474bd make setup code into function 2020-04-28 23:08:11 -07:00
Bryan Jenks c8391d9b25 seperate out touch commands for mac 2020-04-28 22:40:21 -07:00
Bryan Jenks 11b847b635 Revert "add path arg to find command"
This reverts commit 46deb034fd.
2020-04-28 22:37:06 -07:00
Bryan Jenks 9341bdac98 move around brace expansion for file gen 2020-04-28 15:23:01 -07:00
Bryan Jenks e3e6f5f50d please work 2020-04-27 15:05:46 -07:00
Bryan Jenks 46deb034fd add path arg to find command 2020-04-27 14:18:46 -07:00
Bryan Jenks d163f26445 fix cmd substitution for mac version? 2020-04-27 13:55:30 -07:00
Bryan Jenks 6b03a3b76e fix duplicative path section in info msg 2020-04-27 13:54:37 -07:00
Bryan Jenks 871f493f33 change hard coded file path in info msg 2020-04-27 13:52:30 -07:00
Bryan Jenks a842f6a7c7 remove hard coded number of recursive DIR searches 2020-04-27 13:49:17 -07:00
Bryan Jenks 397155be10 quote more filepaths for mac build 2020-04-27 13:26:36 -07:00
Bryan Jenks 7ce1aa4197 quote a variable that broke mac build 2020-04-27 12:55:21 -07:00
Bryan Jenks 469230d343 Merge branch 'master' of github.com:tallguyjenks/flash.sh 2020-04-26 19:25:37 -07:00
Bryan Jenks 4d98f47c25 mac friendly version 2020-04-26 19:25:02 -07:00
Bryan Jenks 7bf1f77052
add intended hyperlink to README for issue 11 2020-04-24 07:44:28 -07:00
Bryan Jenks db2baeef06
update readme on OS availability 2020-04-22 22:15:24 -07:00
Bryan Jenks a62cd44939 make other variables flexible, rely on $DIR 2020-04-22 22:10:57 -07:00
Bryan Jenks 5d8b4b6637 resolves #8, average, and session logging 2020-04-21 22:07:57 -07:00
Bryan Jenks be5930a376 allow user to quit at score entry too 2020-04-21 20:54:32 -07:00
Bryan Jenks 4a9862bb02 resolves #7, highscore feature 2020-04-21 20:47:40 -07:00
Bryan Jenks b2a3168454 resolves #9 + tidying and commenting 2020-04-21 20:18:31 -07:00
Bryan Jenks 4427fdd48d fix license label 2020-04-21 19:36:37 -07:00
Bryan Jenks 70fb1b3581 add more and move shields 2020-04-21 19:34:17 -07:00
Bryan Jenks dfd630b950 add downloads shield 2020-04-21 19:25:18 -07:00
9 changed files with 351 additions and 94 deletions

2
.github/FUNDING.yml vendored
View File

@ -1,5 +1,5 @@
# These are supported funding model platforms
patreon: bryanjenks
github: tallguyjenks
custom: ["https://www.buymeacoffee.com/tallguyjenks", "https://www.paypal.me/tallguyjenks"]

View File

@ -28,6 +28,13 @@ If applicable, add screenshots to help explain your problem.
- Terminal Emulator [e.g. st, kitty, etc]
- Shell [e.g. bash, zsh, fish]
## Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

13
.github/workflows/greetings.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Greetings
on: [pull_request, issues]
jobs:
greeting:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'This was your first issue! Thank you for contributing!'' first issue'
pr-message: 'This was your first Pull Request! Thank you for contributing!'' first pr'

17
.github/workflows/shellcheck.yml vendored Normal file
View File

@ -0,0 +1,17 @@
# from here: https://github.com/marketplace/actions/shellcheck
on:
push:
branch:
- master
name: 'Trigger: Push action'
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: ShellCheck
uses: ludeeus/action-shellcheck@1.0.0

19
.github/workflows/stale.yml vendored Normal file
View File

@ -0,0 +1,19 @@
name: Mark stale issues and pull requests
on:
schedule:
- cron: "30 1 * * *"
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'

View File

@ -1,12 +1,17 @@
<!-- Header & Preview Image -->
<h1 align="center">
<img src="/img/flashheader.png" height="50%" width="50%">
</h1>
<!-- Shields -->
<p align="center">
<a href="https://github.com/tallguyjenks/fla.sh/blob/master/LICENSE"><img src="https://img.shields.io/static/v1.svg?style=flat&label=License&message=MIT&logoColor=eceff4&logo=github&colorA=black&colorB=green"/></a>
<img src="https://img.shields.io/github/commit-activity/m/tallguyjenks/fla.sh">
<a href="https://github.com/tallguyjenks/fla.sh/graphs/contributors"><img src="https://img.shields.io/github/contributors/tallguyjenks/fla.sh"></a>
<img src="https://img.shields.io/github/v/release/tallguyjenks/fla.sh">
</p>
<!-- Description -->
> flashcards in your terminal! This script was inspired by a basic script i saw in a youtube video by a user named nixcasts. I Like the Anki flashcard system and so im working to replicate it in a simple manner using plain text documents and a shell script to aid my ability to study with active recall and spaced repetition.
> Flashcards in your terminal!
>
> This script was inspired by a basic script that I had seen in a youtube video by a user named nixcasts. I like the Anki flashcard system, hence I'm working to replicate it in a simple manner using plain text documents and a shell script to aid my ability to study with active recall and spaced repetition.
![Preview of flash.sh](./img/flash_preview.png)
![Preview of fla.sh](./img/flash_preview.png)
This script is an expanded version of the one featured in [This nixcasts Video](https://www.youtube.com/watch?v=lX8jqo70r1I)
@ -19,14 +24,39 @@ You can have as many 'decks' in the `flash` directory as you want, and having di
This script uses:
- [fzf](https://github.com/junegunn/fzf)
- [bat](https://github.com/sharkdp/bat)
- [bat](https://github.com/sharkdp/bat) (optional if you use `flash -p cat` to use the core utility instead of `bat`)
- (if on macOS the GNU core utilities are a dependency (namely the `shuf` utility))
Install these prior to running the script.
## Installation
### Windows
Untested, not sure if this script and its dependencies will work with WSL or not.
### Mac
Will need to have `brew` to install dependencies listed below and also `brew install coreutils` to get the GNU core utilities as `shuf` is not in macOS by default.
You will need to put the script itself somewhere in your `$PATH` and execute it to initialize the setup.
Confirmed to work on macOS 10.14.6 more recent version welcome to test and file an issue/pull request to update README if other versions run the script as it should.
### Linux
To utilize this script copy/move it to your `~/.local/bin/` folder or any place in your `$PATH`
## Troubleshooting
> Common issues will be added here as they arise during the stability stage of this script.
Checks:
- Is your system supported? see above
- Are all necessary dependencies installed?
- what version of bash do you have installed? or do you have bash installed?
## Usage
The `deck.csv` file should have colon `:` separated values in 4 columns
@ -43,17 +73,18 @@ Organized like this:
**Fourth Field:** _The Score*_
> \* The score determines how often which cards are shown to you. A good idea is to start all your cards out at 0 so they are all served to you equally. As you study and review and mark the more familiar cards as 'Mild' or 'Easy' more points will be added. The lower point cards are sorted to the top and the top 10 are taken and shuffled and then drawn from. This way as you learn the material the items you are less familiar with bubble up into the shuffled pool for drawing and those that go up in points due to increased familiarity go down because you're rating the material as easier.
> \* The score determines how often and which cards are shown to you. A good idea is to start all your cards out at 0 so that all are served to you equally. As you study, review, and mark the more familiar cards as 'Mild' or 'Easy', more points will be added. The lower point cards are sorted to the top and the top 10 are taken, shuffled, and then drawn from. This way as you learn the material and the items you are less familiar with bubble up into the shuffled pool for drawing and those that go up in points due to increased familiarity go down because you're rating the material as easier.
### Decks
If you would like to browse a collection of decks readily available in your subject matter that are comaptible with [flash.sh](https://github.com/tallguyjenks/flash.sh) then you should check out [Flash Decks](https://github.com/tallguyjenks/Flash-Decks).
If you would like to browse through a collection of decks readily available in your subject matter that are comaptible with [fla.sh](https://github.com/tallguyjenks/fla.sh) then you should check out [Flash Decks](https://github.com/tallguyjenks/Flash-Decks).
## Media (accepting contributions)
- [(OLD)Flash.sh Plain Text Flashcards in your Terminal](https://www.youtube.com/watch?v=DbakjEAc_MU)
- [Flash Cards In Your Terminal With Flash.sh](https://www.youtube.com/watch?v=KEWhOzDCfLg)
- [Flash.sh++ A Comprehensive Walk Through of My Bash Flashcard Script Project](https://www.youtube.com/watch?v=nPNPXEh6BUA)
- [Fla.sh Plain Text Flashcards in your Terminal](https://www.youtube.com/watch?v=DbakjEAc_MU)
- [Flash Cards In Your Terminal With Fla.sh](https://www.youtube.com/watch?v=KEWhOzDCfLg)
- [Fla.sh++ A Comprehensive Walk Through of My Bash Flashcard Script Project](https://www.youtube.com/watch?v=nPNPXEh6BUA)
- [Even Exam Prep Can Be Done From The Terminal With Fla.sh](https://www.youtube.com/watch?v=RJ094P7wxaU)
## Support
@ -69,5 +100,3 @@ This is free, open-source software. If you'd like to support the development of
<img src="/img/flashfooter.png">
</h3>
<!-- Shields -->
<p align="center"><a href="https://github.com/tallguyjenks/flash.sh/blob/master/LICENSE"><img src="https://img.shields.io/static/v1.svg?style=flat-square&label=License&message=MIT&logoColor=eceff4&logo=github&colorA=black&colorB=green"/></a></p>

324
flash
View File

@ -23,150 +23,322 @@
# bat - https://github.com/sharkdp/bat
#==============================================================#
#ANSI FOREGROUND ESCAPE COLORS
# USER CUSTOMIZABLE VARIABLES
CARD_POOL_SIZE=10 ######## How large the pool size is for shuf to draw from
SEARCH_DEPTH=999 ######### How many levels to recursively search for .csv's in .local/share/flash
PREVIEWER='bat' ########## What fzf previewer to use when searching through decks
CURR_DECK_DISPLAY="file" # Options are 'file' or 'path'
# ANSI FOREGROUND ESCAPE COLORS
RED='\033[0;31m'
LRED='\033[1;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
LGREEN='\033[1;32m'
LBLUE='\033[1;34m'
CYAN='\033[0;36m'
LCYAN='\033[1;36m'
ORANGE='\033[0;33m'
LGREY='\033[0;37m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
#ANSI BACKGROUND ESCAPE COLORS
# ANSI BACKGROUND ESCAPE COLORS
WHITEBG='\033[1;47m'
# FONT FORMAT EXCAPE CODES
BOLD='\e[1m'
PWD="$(pwd)" # Remember User's Starting Directory
DIR="$HOME/.local/share/flash" # Where Decks Are Located
EXAMPLE_DECK="$HOME/.local/share/flash/deck.csv"
# Remember User's Starting Directory
PWD="$(pwd)"
# Where Decks Are Located for linux & mac
# Prefer XDG Configuration before hard coded file paths
OS="$(uname)"
case "$OS" in
"Darwin") DIR="${XDG_DATA_HOME:-$HOME/Library/Application Support}/flash" && alias shuf=gshuf ;;
"Linux") DIR="${XDG_DATA_HOME:-$HOME/.local/share}/flash" ;;
*) DIR="${XDG_DATA_HOME:-$HOME/.local/share}/flash" ;;
esac
# Where the example deck will be placed and named
EXAMPLE_DECK="$DIR/deck.csv"
# Track High score
HIGH_SCORE="$DIR/.highscore"
# Track number of cards reviewed per session
REVIEW_LOG="$DIR/.reviews"
# Iterator for Count of cards reveiwed
COUNTER=0
# Success message of setup process
DIR_MADE_MSG="
Your ${LRED}~/.local/share/flash${NC} directory has been made and
Your ${LRED}$DIR${NC} directory has been made and
your ${ORANGE}deck.csv${NC} file is ready for you to enter your flashcard data
If you want to see information about ${ORANGE}fla.sh${NC} then use the option
${YELLOW}flash -i${NC}.
"
# User has .local/share directory but no decks inside
NO_DECKS="
No decks were found, please make a new deck
using ${ORANGE}:${NC} as a delimiter in a ${ORANGE}.csv${NC} file in
the ${LRED}.local/share/flash${NC} directory.
the ${LRED}$DIR${NC} directory.
An example of a card:
${GREEN}Math:What is the square root of 4?:2:0${NC}
"
# The example flashcard deck to be made
DECK_TEMPLATE="History:When was the declaration of independence signed?:1776:0
Math:What is the square root of 4?:2:4
Science:What is the charge of a proton?:Positive:2
Philosophy:What was socrates known as?:The Gadfly of Athens:0
Programming:What is the typical starting value of an array?:0:5
History:What did Abraham Lincoln Typically Keep In his hat?:Mail:0
Math:what is the first 2 decimal places of PI:3.14:4
Science:What is the charge of an electron?:Negative:3
Science:What is the charge on a proton?:Positive 1:2
Philosophy:What was Socrates known as?:The Gadfly of Athens:0
Programming:What is the typical starting index of an array?:0:5
History:What did Abraham Lincoln typically keep in his hat?:Mail:0
Math:What is the value of PI to 2 decimal places?:3.14:4
Science:What is the charge on an electron?:Negative 1:3
Programming:What does OOP stand for?:Object Oriented Programming:2
History:What did socrates drink to commit suicide?:Hemlock Tea:2
Math:What is the equation for a slope of a line?:y=mx+b:4
Science:What is the charge of a neutron?:Neutral:1
History:What did Socrates drink to commit suicide?:Hemlock Tea:2
Math:What is the general equation for the slope of a line?:y=mx+b:4
Science:What is the charge on a neutron?:Neutral:1
Programming:What is Vim?:God's Text Editor:999
History:What were the british known buy during the american revolution?:The redcoats:1
History:What were the British known by during the American Revolution?:The Redcoats:1
Math:What is the value of this equation - log10(100)?:2:0
Science:What are protons/neutrons/electrons made of?:quarks:5
Science:What are protons and neutrons made of?:quarks:5
Programming:What does RAM stand for?:Random Access Memory:1
History:What was the year 2000 also known as?:Y2K:0
Math:What is the formula for mean?:Sum/count:4
Math:What is the formula for the mean?:Sum/count:4
Science:What is cold?:The absense of heat:3
Programming:What languages are the worst?:Proprietary:999
History:When did man land on the moon?:1969:4
Math:10^3=?:1000:1
Science:The _____ ______ Project mapped all of man's genes.:Human Genome:3
Programming:What is the best computer to program on?:Thinkpad:999
History:When was flash.sh created?:April 2020:999
History:When was fla.sh created?:April 2020:999
Math:What do you call a number only divisible by itself and 1?:Prime:0
Science:What is the distance between the Earth and Sol called?:An Astronomical Unit (AU):1
Programming:Best operating system?:Arch, because BTW i run Arch:999"
Programming:What is the best operating system?:Arch, because BTW i run Arch:999"
if [ ! -d $DIR ];then # If Directory does NOT exist
echo -e "No ${LRED}.local/share/flash${NC} directory, make it? ${LGREEN}y${NC}/${LRED}n${NC}"
# Define setup process in a function and create necessary files for user
setup() {
mkdir "$DIR" &&
touch {"$EXAMPLE_DECK","$HIGH_SCORE","$REVIEW_LOG"} &&
echo "$DECK_TEMPLATE" >>"$EXAMPLE_DECK" &&
echo -e "$DIR_MADE_MSG"
}
# Test if .local/share exists and wether to offer setup process
if [ ! -d "$DIR" ]; then
echo -e "No ${LRED}$DIR${NC} directory, make it? ${LGREEN}Y${NC}/${LRED}N${NC}"
# shellcheck disable=SC2162
read RESPONSE
case "$RESPONSE" in
[QqNn]) exit ;;
[Yy]) mkdir "$DIR" && touch $EXAMPLE_DECK && echo "$DECK_TEMPLATE" >> $EXAMPLE_DECK && echo -e "$DIR_MADE_MSG" && exit;;
*) echo -e "invalid choice, please select either ${LGREEN}y${NC} or ${LRED}n${NC}" && exit ;;
[QqNn]) exit 0 ;;
[Yy]) setup && exit 0 ;;
*) >&2 echo -e "invalid choice, please select either ${LGREEN}y${NC} or ${LRED}n${NC}" && exit 1 ;;
esac
fi
cd "$DIR"
# go to the flashcard decks directory
cd "$DIR" || exit 1
if [ "$(find -maxdepth 999 -iname "*.csv" | wc -l)" = 0 ]; then # If there are no flashcard decks available
echo -e "$NO_DECKS" && cd "$PWD" && exit
fi
# If there are no flashcard decks available return user to starting location
# while also displaying explanatory text of issue
[ "$(find . -maxdepth "$SEARCH_DEPTH" -iname "*.csv" | wc -l)" = 0 ] &&
>&2 echo -e "$NO_DECKS" && exit 1
# Show pretty FZF preview of decks using BAT
DECK="$(find -maxdepth 999 -iname "*.csv" | fzf --preview='bat --theme="Solarized (dark)" --style=numbers --color=always {} | head -500')"
if [ -z $DECK ]; then # If Variable String Length is 0
exit
fi
# if highscore file was removed, remake it.
[ ! -e "$HIGH_SCORE" ] && touch "$HIGH_SCORE"
main(){
IFS=$':'; read -a q <<<$(sort "$DECK" -n --field-separator=: --key=4 | head | shuf -n 1)
clear
echo -e "${WHITEBG} Flash.sh - Flash Cards In Your Terminal ${NC}"
echo -e "${ORANGE}${BOLD}Cards ${BOLD}Reviewed:${NC} $COUNTER"
echo -e "${LGREY}Category:${NC}
${q[0]}"
echo -e "${LGREY}Question:${NC}
${q[1]}"
echo -e ""
read -sn 1 NEXT
if [ "$NEXT" = q ]; then
cd "$PWD" && exit
# if reviewed file was removed, remake it.
[ ! -e "$REVIEW_LOG" ] && touch "$REVIEW_LOG"
print_usage() {
echo -e "\n${LCYAN}fla.sh --- Flash card system by Bryan Jenks${NC} ${LBLUE}<BryanJenks@protonmail.com>${NC}\n\n${YELLOW}${BOLD}Usage:${NC}\n\t${GREEN}flash -h:${NC} Print this help text\n\t${GREEN}flash -i:${NC} Print Information about the flashcard system\n\t${GREEN}flash -v:${NC} Print version Number\n\t${GREEN}flash -p [BINARY]:${NC} Change the previewer when selecting decks.\n\t\tDefault: ${GREEN}bat${NC}\n\t\tSupported: ${GREEN}bat${NC}, ${GREEN}cat${NC}\n"
}
print_info() {
echo -e "\nThis flash card system works via colon ${YELLOW}:${NC} separated ${YELLOW}.csv${NC} files\n
with entries that look like this: ${LGREY}category:question:answer:0${NC}\n
These ${YELLOW}.csv${NC} files should be stored in your
\t${YELLOW}\$XDG_DATA_HOME/flash${NC}
OR
\t${YELLOW}~/.local/share/flash${NC} for Linux
\t${YELLOW}~/Library/Application Support/flash${NC} for mac
-------------------------------------------------------------------------------
${LCYAN}Exiting:${NC}\n
\tYou can exit the application at any time by pressing either ${RED}q${NC} or ${RED}Q${NC}
${LCYAN}Usage:${NC}\n
\tYou will first be prompted with a question and will need to press ${RED}[Enter]${NC}
\tto reveal the answer. Once the answer is revealed you will need to either
\tquit, or give a rating to how difficult the question was.
${LCYAN}The Scoring System:${NC}\n
\tThe last field in the ${YELLOW}.csv${NC} files is the current point score of the 'card'
\tEvery time you rate a card the point score will either increase, decrease,
\tor stay the same. zero is the lowest value, and the upper limit is over
\t100 billion.
\t${CYAN}Scoring Results:${NC}
\t\t[${LRED}Hard${NC}]\t\t-2 points
\t\t[${RED}Difficult${NC}]\t-1 point
\t\t[${YELLOW}Normal${NC}]\tNo Change
\t\t[${GREEN}Mild${NC}]\t\t+1 point
\t\t[${LGREEN}Easy${NC}]\t\t+2 points
\tThe cards with the lowest scores (you scored them as ${LRED}Hard${NC}/${RED}Difficult${NC}) are
\tsorted to the top, a pool of them are picked and from that pool 1 card is
\trandomly drawn. As you become more familair with the material and rate it
\tas easier, the point values will go up and the cards will appear less
\tfrequently making room for those cards that are still difficult and have
\tlower point values.
It is a good idea to start all cards off at ${YELLOW}0${NC} initially so that they all
have an equal chance of being drawn initially.
"
}
while getopts 'hivp:' flag; do
case "${flag}" in
h) print_usage && exit 0 ;;
i) print_info && exit 0 ;;
v) echo -e "\n${YELLOW}fla.sh Current Version:${NC} ${RED}1.2${NC}\n" && exit 0 ;;
p) { [[ $(command -v "$OPTARG" 2>&1) ]] && PREVIEWER=$OPTARG; } || >&2 echo "Unable to find previewer $OPTARG. Exiting..." && exit 1 ;;
*) print_usage && exit 1 ;;
esac
done
# Set some parameters for preview command used by FZF
while [ -z "$PREVIEWER_PARAMTERS" ]; do
case "$PREVIEWER" in
bat) PREVIEWER_PARAMTERS="--theme='Solarized (dark)' --style=numbers --color=always" ;;
cat) PREVIEWER_PARAMTERS="-b" ;;
*) echo -e "${RED}$PREVIEWER${NC} is not a valid previewer. Use '${GREEN}bat${NC}' or '${GREEN}cat${NC}'. Falling back on default...\n" && read -r -s -p 'Press [Enter] to continue...' && echo -e "\n" && PREVIEWER='bat' ;;
esac
done
# Show pretty FZF preview of decks using $PREVIEWER. Default: BAT
DECK="$(find . -maxdepth "$SEARCH_DEPTH" -iname "*.csv" | fzf --preview="$PREVIEWER $PREVIEWER_PARAMTERS {} | head -500")"
# Get current deck name for display
case "$CURR_DECK_DISPLAY" in
file) CURRENT_DECK="$(echo "$DECK" | awk -F/ '{print $NF}')" ;;
path) CURRENT_DECK="$DECK" ;;
*) CURRENT_DECK="$(echo "$DECK" | awk -F/ '{print $NF}')" ;;
esac
# The top part of the flash display so that code is not duplicated twice
print_head() {
QUESTION=$(echo "${q[1]}" | fold -w 59)
echo -e "${WHITEBG} Fla.sh - Flash Cards In Your Terminal ${NC}
${ORANGE}${BOLD} Current Deck:${BOLD}${NC}\t$(basename -s .csv "$CURRENT_DECK")
${ORANGE}${BOLD}Cards Reviewed:${BOLD}${NC}\t$COUNTER
\t${ORANGE}${BOLD}High Score:${BOLD}${NC}\t$(cat "$HIGH_SCORE")
\t${ORANGE}${BOLD}Avg review:${BOLD}${NC}\t$(awk '{ sum += $7; n++ } END { if (n > 0) print sum / n; }' "$REVIEW_LOG")
${LGREY}Category:${NC} ${q[0]}
___________________________________________________________
$([ ${#QUESTION} -lt 59 ] && printf "%$(((59 - ${#QUESTION}) / 2))s")$QUESTION"
}
# Creating new entries in the log for the average score generation
add_usage_entry() {
if [ ! "$COUNTER" = 0 ]; then
# Create a New Entry
TIME_STAMP=$(date +"%Y%m%d %H:%M:%S")
printf -v ENTRY "TimeStamp: %s Deck: %s cardsReviewed: %s" "$TIME_STAMP" "$CURRENT_DECK" "$COUNTER"
echo "$ENTRY" >>"$REVIEW_LOG"
fi
echo -e "${LGREY}Answer:${NC}
${q[2]}"
echo -e ""
echo -e "${WHITEBG}${WHITE}===========================================================${NC}"
echo -e ""
echo -e "${LGREY}How Difficult Was This Question?${NC}"
echo -e ""
echo -e "${LRED}Hard${NC} [1] ${RED}Difficult${NC} [2] ${YELLOW}Normal${NC} [3] ${GREEN}Mild${NC} [4] ${LGREEN}Easy${NC} [5]"
echo -e ""
}
# If no deck is selected in fzf menu
# return user to start location
# and exit quietly
[ -z "$DECK" ] && clear && exit 1
main() {
IFS=$':'
# shellcheck disable=SC2162
read -a q <<<"$(sort "$DECK" -n --field-separator=: --key=4 | head -n "$CARD_POOL_SIZE" | shuf -n 1)"
clear
print_head
echo -e "
${LGREY}──────────────── Press [Enter] to continue ────────────────${NC}"
# shellcheck disable=SC2162
read -sn 1 NEXT
while [ ! "$NEXT" = "" ] && [ ! "$NEXT" = q ] && [ ! "$NEXT" = Q ]; do
# shellcheck disable=SC2162
read -sn 1 NEXT
done
clear
print_head
{ [ "$NEXT" = q ] || [ "$NEXT" = Q ]; } && add_usage_entry && clear && exit 0
ANSWER=$(echo "${q[2]}" | fold -w 59)
echo -e "___________________________________________________________
$([ ${#ANSWER} -lt 59 ] && printf "%$(((59 - ${#ANSWER}) / 2))s")$ANSWER
${WHITEBG}${WHITE}===========================================================${NC}
${LGREY}How Difficult Was This Question?${NC}
${LRED}Hard${NC} [1] ${RED}Difficult${NC} [2] ${YELLOW}Normal${NC} [3] ${GREEN}Mild${NC} [4] ${LGREEN}Easy${NC} [5]
${LGREY}Select a number to continue, or${NC} ${LRED}Q${NC} ${LGREY}to quit...${NC}"
# shellcheck disable=SC2162
read -sn 1 DIFFICULTY_SCORE
while [[ ! "$DIFFICULTY_SCORE" =~ [12345qQ] ]]; do
# shellcheck disable=SC2162
read -sn 1 DIFFICULTY_SCORE
done
{ [ "$DIFFICULTY_SCORE" = q ] || [ "$DIFFICULTY_SCORE" = Q ]; } &&
add_usage_entry && clear && exit 0
clear
COUNTER="$(($COUNTER+1))" # Increment count for above test and card review count increment
COUNTER="$((COUNTER + 1))" # Increment count for card review count increment
if [ "${q[3]}" = 0 ]; then
NEW_ITEM_SCORE=0
case "$DIFFICULTY_SCORE" in
[123]) NEW_ITEM_SCORE=0 ;;#HARD DIFFICULTY & NORMAL
4) NEW_ITEM_SCORE=1 ;;#MILD
5) NEW_ITEM_SCORE=2 ;;#EASY
*) NEW_ITEM_SCORE=0 ;;#INVALID
[123]) NEW_ITEM_SCORE=0 ;; #HARD DIFFICULTY & NORMAL
4) NEW_ITEM_SCORE=1 ;; #MILD
5) NEW_ITEM_SCORE=2 ;; #EASY
*) NEW_ITEM_SCORE=0 ;; #INVALID
esac
elif [ "${q[3]}" = 1 ]; then
case "$DIFFICULTY_SCORE" in
1) NEW_ITEM_SCORE=0 ;;#HARD
2) NEW_ITEM_SCORE=0 ;;#DIFFICULT
3) NEW_ITEM_SCORE=1 ;;#NORMAL
4) NEW_ITEM_SCORE=2 ;;#MILD
5) NEW_ITEM_SCORE=3 ;;#EASY
*) NEW_ITEM_SCORE=1 ;;#INVALID
1) NEW_ITEM_SCORE=0 ;; #HARD
2) NEW_ITEM_SCORE=0 ;; #DIFFICULT
3) NEW_ITEM_SCORE=1 ;; #NORMAL
4) NEW_ITEM_SCORE=2 ;; #MILD
5) NEW_ITEM_SCORE=3 ;; #EASY
*) NEW_ITEM_SCORE=1 ;; #INVALID
esac
else
case "$DIFFICULTY_SCORE" in
1) NEW_ITEM_SCORE="$((${q[3]}-2))" ;;#HARD
2) NEW_ITEM_SCORE="$((${q[3]}-1))" ;;#DIFFICULTY
3) NEW_ITEM_SCORE="${q[3]}" ;;#NORMAL
4) NEW_ITEM_SCORE="$((${q[3]}+1))" ;;#MILD
5) NEW_ITEM_SCORE="$((${q[3]}+2))" ;;#EASY
*) NEW_ITEM_SCORE="${q[3]}" ;;#INVALID
1) NEW_ITEM_SCORE="$((q[3] - 2))" ;; #HARD
2) NEW_ITEM_SCORE="$((q[3] - 1))" ;; #DIFFICULTY
3) NEW_ITEM_SCORE="${q[3]}" ;; #NORMAL
4) NEW_ITEM_SCORE="$((q[3] + 1))" ;; #MILD
5) NEW_ITEM_SCORE="$((q[3] + 2))" ;; #EASY
*) NEW_ITEM_SCORE="${q[3]}" ;; #INVALID
esac
fi
# Update item score for each flashcard item
sed -i "s/${q[0]}:${q[1]}:${q[2]}:${q[3]}/${q[0]}:${q[1]}:${q[2]}:$NEW_ITEM_SCORE/g" "$DECK"
## Remove forward slashes in the Questions and answers
QUESTION_REGEX="$(sed "s/\(\/\|\[\|\]\|\*\)/\\\\\1/g" <<<"${q[1]}")"
ANSWER_REGEX="$(sed "s/\(\/\|\[\|\]\|\*\)/\\\\\1/g" <<<"${q[2]}")"
sed -i "s/${q[0]}:$QUESTION_REGEX:$ANSWER_REGEX:${q[3]}/${q[0]}:$QUESTION_REGEX:$ANSWER_REGEX:$NEW_ITEM_SCORE/g" "$DECK"
# If no highscore currently set, set it.
[ -z "$(cat "$HIGH_SCORE")" ] && echo "$COUNTER" >"$HIGH_SCORE"
# If Cards Reviewed > Current High Score, Update
[ "$COUNTER" -gt "$(cat "$HIGH_SCORE")" ] && echo "$COUNTER" >"$HIGH_SCORE"
}
while true; do

Binary file not shown.

Before

Width:  |  Height:  |  Size: 702 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 31 KiB