Commit Graph

189 Commits (c04167d2415a2a21aa4022e114597c93da9b7807)

Author SHA1 Message Date
David Farrell 00062bfcb6
chore: Use grep -E / grep -F instead of egrep / fgrep (#2164)
Ensures that the -E or -F option, when used, is the first option
* i.e. grep -oE => grep -E -o

Updates _bash-it-grep to invoke grep with just the provided arguments
* This function was (and still is) unused, but decided this new functionality was actually more useful

Introduces _bash-it-fgrep to invoke grep -F

Removes type -P egrep from the _bash-it-*grep functions

For usages that were already going to be modified, use -F if appropriate
* Does not touch grep usages that may have benefited from -F, but were not otherwise considered for this PR

Adds shellcheck header to modified .bash files that didn't already have it
2022-10-13 10:34:57 -07:00
Gurkirat Singh 6ccd9f5adf
fix (helpers): bashit_update function return to source path and --no-merges in log 2022-03-21 08:52:46 +05:30
John D Pell 47bbc73744 lib/helpers: `_bash-it-find-in-ancestor()`
Use new `composure.sh` feature to avoid `cite()`.
2022-02-24 12:47:22 -08:00
John D Pell fe48deda2d lib: rename `_bash-it-clean-component-cache()`
…to `_bash-it-component-cache-clean()`
2022-02-20 12:01:05 -08:00
John D Pell 150f73ee50 bash-it update: show change log once 2022-02-18 03:06:17 -08:00
John D Pell 95353f1a98 lib/helpers: the last remnants of the `$OSTYPE` have been swept away
- Figure out which `sed` we have by checking, not guessing.
2022-02-17 20:46:28 -08:00
John D Pell 35ecc260c2 lib/helpers: handle unbound parameters 2022-02-17 20:46:28 -08:00
John D Pell 31751624c0 lib/helpers: cleanup `_bash-it-profile-load-parse-profile()` a bit 2022-02-17 20:45:37 -08:00
John D Pell e7818dbaca lib/helpers: handle unbound positional parameters
Alsö, don't `pushd`/`popd` when restarting shell.
2022-02-17 20:45:37 -08:00
John D Pell 60c10004d1 lib/helpers: fix `_bash-it-component-pluralize()` 2022-02-17 20:45:27 -08:00
Puneeth Chaganti b3ef9ea209 lib/helpers: Don't rm "$profile_path" before writing to it
When the file is being re-created, we write to it, instead of appending to
it. So, the rm here is unnecessary and prevents users from linking the profile
file to another location that is potentially under version control. For
instance, once could link to a profile file located at
"$BASH_IT_CUSTOM/profiles/*.bash_it".
2022-02-16 20:55:08 +05:30
John D Pell a9a40a3cad lib/helpers: add `preview` to `bash-it` spaghetti 2022-02-07 15:27:03 -08:00
Nariyasu Heseri 1e77c26c00 helpers: fix `awk: unterminated regexp` 2022-01-31 23:54:14 +09:00
John D Pell c08267e25d lib/helpers: eliminate assumptions about login shells
Bash loads initialization files on Mac just the same as it does on Linux or WSL. Our previous assumptions were wrong, and my fix was alsö wrong because I made more assumptions!

This patch eliminates the assumptions. Literally just load either the startup file the shell started with, or fall back to `~/.bashrc`. Don't check `shopt -q login_shell` and don't check `$OSTYPE` or anything else.
2022-01-28 03:59:02 -08:00
souhaiebtar a312e5a9b9
fix wrong function name in `helpers.bash`
when i tried to install, i got a message `_bash-it-pluralize-component` command not found; after checking `utilities.bash` the correct function name was `_bash-it-component-pluralize`
2022-01-22 12:33:33 +00:00
John D Pell 0f0093dd4b lib/helpers: quotes for consistency
Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too.

lib/helpers: simplify some quote escapes
2022-01-18 11:06:21 -08:00
John D Pell dfc3fa4339 lib/helpers: delete `_bash-it-determine-component-status-from-path()`
Duplicate function of existing `_bash-it-component-item-is-enabled()`.
2022-01-18 11:06:21 -08:00
John D Pell 22b290b94f lib/helpers: simplify some functions
- add some `local` variables,
- don't subshell `_typeset_functions`,
2022-01-18 11:02:37 -08:00
John D Pell bc25810069 lib/helpers: juse use `awk`, insteado of `grep | awk` 2022-01-18 11:02:37 -08:00
John D Pell 4719e43d0b lib/helpers: remove weird non-globs
Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries.

Alsö, see mvdan/sh issue 558

lib/helpers: unbound positional parameters
2022-01-18 11:02:37 -08:00
John D Pell 251e23a3fa lib/helpers: use `awk` to count lines instead of piping to `wc -l`
Co-authored-by: Kostas Giapis <45879751+tsiflimagas@users.noreply.github.com>
2022-01-18 11:02:37 -08:00
John D Pell 317ff77810 lib/helpers: be extra careful with word splitting
Use curly braces when `$1` is unseparated from words in a string.
2022-01-18 11:02:37 -08:00
John D Pell 550f808884 lib/helpers: fix `_bash-it-describe()`
Use `_bash-it-component-item-is-enabled()`

Fix SC2295
2022-01-18 11:02:37 -08:00
John D Pell 4c473853e9 lib/helpers: cleanup
- Improve `pushd`/`popd` somewhat
- local some parameters
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
2022-01-18 11:02:37 -08:00
John D Pell 003b0ce802 lib/helpers: `shfmt`
My apologies to future `git blame` hunters ♥
2022-01-18 11:02:36 -08:00
John D Pell 6ed006a167 lib/helpers: second `shellcheck` pass
lib/helpers: lint `_bash-it-migrate()`

lib/helpers: lint `_disable-thing()`

lib/helpers: lint `_enable-thing()`

lib/helpers: lint `_help-list-aliases()`

lib/helpers: lint `_help-plugins()`

lib/helpers: some SC2034 fixes

And SC2154 in `_make_reload_alias()`

lib/helpers: lint `all_groups()`
2022-01-18 11:02:21 -08:00
John D Pell 5eab3bd288 lib/helpers: first `shellcheck` pass
Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c.

Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible.

Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here?

Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`.

Finally, merge PR #1865 from NoahGorny...and clean it a bit...
2022-01-18 11:02:21 -08:00
John D Pell 9b51dc0b5f lib/helpers: fix `_command_exists()`
The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!
2022-01-18 11:02:10 -08:00
John D Pell 180fb93df8 lib/helpers: fix `all_groups()`
- Don't write to disk, just pipe.
- Don't loop, just do all functions.

Performance of old implementation on my system:
```
real    0m9.996s
user    0m5.318s
sys     0m9.126s
```

Performance of new implementation on my system:
```
real    0m0.052s
user    0m0.069s
sys     0m0.025s
```
2022-01-18 11:02:10 -08:00
Noah Gorny c81c9dcc8c
Merge pull request #1865 from NoahGorny/add-profile-subcommand
add profile subcommand
2022-01-03 14:00:39 +02:00
John D Pell 00f5f2a62e Use `_bash-it-egrep()` 2021-10-18 22:08:56 -04:00
Noah Gorny e1017513d0 helpers: Disallow removing the default profile with bash-it profile rm 2021-09-29 00:30:24 +03:00
Noah Gorny 1ae407150c helpers: Improve bash-it profile messages 2021-09-29 00:30:24 +03:00
Noah Gorny 337e188d25 helpers: Add bash-it profile rm 2021-09-29 00:30:24 +03:00
Noah Gorny 81b17f795b helpers: Add bash-it profile list 2021-09-29 00:30:24 +03:00
Noah Gorny 6a923760d8 helpers: Add help message for bash-it profile 2021-09-29 00:30:24 +03:00
Noah Gorny d4ec41bef7 helpers: Add useful log in case of empty config 2021-09-29 00:30:24 +03:00
Noah Gorny cea95d72b3 lib: helpers: Rename _bash-it-process-component to _bash-it-determine-component-status-from-path 2021-09-29 00:30:23 +03:00
Noah Gorny 7f60b73a2a helpers: Add new bash-it profile subcommand 2021-09-29 00:30:23 +03:00
Noah Gorny 41cba9d7e4 helpers: Add enable-plugin and enable-alias aliases 2021-09-29 00:30:23 +03:00
Noah Gorny ffeb770593 helpers: Print type when using disable all 2021-09-29 00:30:23 +03:00
Noah Gorny 6e03a726a6 helpers: Split some processing code out of _bash-it-describe 2021-09-29 00:30:23 +03:00
John D Pell e8966ea2a5 lib/helpers: cite `_bash-it-find-in-ancestor()`
Add `composure.sh` citation with examples and rewrite internal comments to describe the code flow.
2021-09-23 10:00:52 -07:00
John D Pell 0471a20c7c lib/helpers: new function `_bash-it-find-in-ancestor()`
New function to do a search looking for a sibling to a parent of the current directory, for example to find `../../.git` to indicate that `$PWD` is inside a git repository.
2021-09-22 15:30:07 -07:00
John D Pell 8a03f451b2 lib/helpers: simplify `_command_exists()` and `_binary_exists()`
Remove subshell and just use a regular `if`
2021-09-19 21:58:48 -07:00
John D Pell 5fc418e479 Use `${PWD}` instead of `$(pwd)`
Don't subshell when there's a shell parameter for it.
2021-09-18 13:15:13 -07:00
Noah Gorny 0dbf1d593c
Merge pull request #1926 from gaelicWizard/basenamed
Use parameter substitution instead of `dirname`/`basename`, where safe to do so
2021-09-18 18:26:55 +03:00
John D Pell 1c3cbf7ca6
Delete `.shellcheckrc` (#1947)
* CI: disable Ubuntu 16.04 as it's EOL

https://github.blog/changelog/2021-04-29-github-actions-ubuntu-16-04-lts-virtual-environment-will-be-removed-on-september-20-2021/

* main: lint false positive

* install: lint

* plugins/cmd-returned-notify: don't `export`

* plugins/xterm: lint

* plugins/git: lint

* plugins/goenv: lint

* plugins/alias-completion: lint false positives

* plugins/alias-completion: fix SC2155, SC2154

Declare `locals` at the top of the function

* completion: lint completions using `bash_completion` functions

Match the style of the existing code

* completion/knife: lint false positives

* completion/knife: lint

* completion/sdkman: lint

* completion/composer: lint

* Move `.shellcheckrc` under `themes/`

* lib/theme: fix SC2155, SC2154, SC2034

* lib/colors: don't warn on unused variables

We assign a large number of variables here and they may or may not be used anywhere else, so disable SC2034 for this file (only).

Alsö disable SC2005 as the functions in this file were written before `printf` was invented and have to do some fancy metascripting to get escape sequences interpreted reliably. I’m not smart enough to fix this to use `printf`, so leave it for now.

* themes/agnoster: lint

* themes: disable SC2154 for colors

Each one of these themes will need it’s own fix for SC2154, possibly upstream.

Due to the way themes are, it's entirely normal to have a *lot* of false positives for SC2034. So much so, that I have to admit that it is probably just not worth linting for SC2034 despite my dislike of blanket ignore rules.

* themes: disable SC2154, fix SC2155

Each one of these themes will need it’s own fix for SC2154, possibly upstream.

Due to the way themes are, it's entirely normal to have a *lot* of false positives for SC2034. So much so, that I have to admit that it is probably just not worth linting for SC2034 despite my dislike of blanket ignore rules.

* Delete `.shellcheckrc`

* remove executable bit
2021-09-18 12:50:59 +03:00
John D Pell 470341b23a Drop `basename` in favor of Bash strings
Convert `var=$(basename $file)` to `var="${file##*/}"`
2021-09-16 16:59:02 -07:00
John D Pell bd9f4015a7 lib/helpers: handle unset parameter
Expressly handle $BASH_IT_REMOTE as blank when variable is not set.
2021-08-26 14:11:41 -07:00