Commit Graph

94 Commits

Author SHA1 Message Date
Juan Enrique 37f609eaeb
Update flash (#48)
Minor typo
2023-11-06 11:33:36 -08: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 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 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 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
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
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
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 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 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 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 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 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