Commit Graph

296 Commits (fdff1d81cd558d916eef9bcd3ce6f81a34b9af5b)

Author SHA1 Message Date
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 8d5d9073ce
Merge pull request #1999 from gaelicWizard/utilities
lib/utilities: refactor `_bash-it-pluralize-component()` & other improvements
2022-01-18 19:39:45 +02:00
John D Pell 7430a06ec2 lib/utilities: Use variable indirection
Don't use `local -n var` so that we can support v3.2...

Note: function names and variable names are different namespaces, so we can have a variable named the same as the function...which makes it really easy to predict default names for results when returning this way.
2022-01-09 00:53:39 -08:00
John D Pell 2b5e531396 lib/utilities: update `_bash-it-component-cache-file()`
Match idiom of `_bash-it-component-singularize()`
2022-01-09 00:53:39 -08:00
John D Pell 4f700dfb3b lib/utilities: rewrite _bash-it-component-pluralize
Fix up and rename `_bash-it-pluralize-component()` to `_bash-it-component-pluralize()`, and add matching function `_bash-it-component-singularize()`.
2022-01-09 00:53:39 -08:00
John D Pell c3eaa606de lib/utilities: fix `_bash-it-component-help()` for long component names
Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity.

This fixes Bash-It/bash-it#1978.
2022-01-09 00:53:39 -08:00
John D Pell e3bd30f98d lib/utilities: autonomize `_bash-it-component-item-is-enabled()`
Make `_bash-it-component-item-is-enabled()` operate *without* using `_bash-it-component-help()`...so it's now *much* faster.
2022-01-09 00:53:39 -08:00
John D Pell e71ea4ad02 lib/log: function `_bash-it-log-prefix-by-path()`
...to replace `_set-prefix-based-on-path()` in `scripts/reloader`.

Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway.
2022-01-09 00:49:44 -08:00
John D Pell 6dec28b5df lib/log: rename `_log_general()`
...to `_bash-it-log-message()`.

alsö, add common log levels with common names.
2022-01-09 00:49:44 -08:00
John D Pell b772e6ace7 lib/log: `shellcheck` && `shfmt`
Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut

Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again.

My apologies to future `git blame` hunters ♥
2022-01-09 00:49:44 -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
John D Pell 253d1213e0 lib/utilities: new function `_bash-it-egrep()`
The existing function `_bash-it-grep()` is weird. New function `_bash-it-egrep()` just does the thing without requiring two subshells and manual invocation.
2021-10-18 09:14:32 -04:00
John D Pell b8ee63c67d lib/utilities: quote SC2295
Doesn't show up on my shellcheck 0.7.2, but does for NoahGorny!
2021-10-18 09:14:32 -04:00
John D Pell b986c39040 lib/utilities: XDG_CACHE_HOME
Use $XDG_CACHE_HOME environment constant instead of placing a tmp/cache folder inside the bash-it data repo. If not defined, fall back to current behavior.

This resolves Bash-It/Bash-It#1904.
2021-10-18 09:14:32 -04:00
John D Pell 7cd02781f8 lib/utilities: `_bash-it-component-help()`
No need to `rm` when we overwrite the file the line after next. Alsö, use `>|` in case the user sets `noclobber`; we do expressly intend to overwrite the file in this case.
2021-10-13 21:13:45 -07:00
John D Pell f7cc442af4 lib/utilities: simplify `_bash-it-array-dedup()`
alsö fix usage example of `_bash-it-array-contains-element()`
2021-10-13 09:28:21 -07: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
Noah Gorny 7fb7bb9cb8
Merge pull request #1952 from gaelicWizard/uncle
lib/helpers: new function `_bash-it-find-in-ancestor()`
2021-09-28 16:51:30 +03:00
John D Pell 3eed0f033f
Lint: prepare `lib/utilities` for `shellcheck` (#1933)
* lib/utilities: shellcheck

SC2059

* lib/utilities: fix `_bash-it-get-component-type-from-path()`

Account for plugins with names that contain periods.

* lib/utilities: fix `_bash-it-array-dedup()`

Use fewer subprocesses and newline-delimited not space-delimited.

* lib/utilities: fix `_bash-it-component-list()`

Use fewer subprocesses and return newline-delimited, not space-delimited.

* lib/utilities: fix `_bash-it-component-list-matching()`

Use `sort -u` instead of `sort | uniq`

* lib/utilities: fix `_bash-it-component-list-enabled()`

Use fewer subprocesses, return newline-delimited instead of space-delimited, and use `sort -u` instead of `uniq | sort`

* lib/utilities: fix `_bash-it-component-list-disabled()`

Use fewer subprocesses, return newline-delimited instead of space-delimited, and use `sort -u` instead of `uniq | sort`

* lib/utilities: fix `_bash-it-grep()`

1. Executing `'/usr/bin/grep'` does *not* return the path to grep...
2. use `type -p` instead of external binary `which`.
3. Simplify parameter definition.
4. Why was there a space after `%s`?

* lib/utilities: use `_bash-it-grep`

Alsö, lose a spurious `cat`

* lib/utilities: lint `_bash-it-component-help`

* lib/utilities: lint `_bash-it-component-cache-file()`

* lib/utilities: `shfmt`

My apologies to future `git blame` hunters ♥

* lib/helpers: fix `_bash-it-get-component-name-from-path()`

Use `${BASH_IT_LOAD_PRIORITY_SEPARATOR}`
2021-09-28 15:24:18 +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 dee55a03cc drop `dirname` in favor of native Bash strings (1 of 2)
Convert `var=${dirname $filename)` to `var="${filename%/*}` in cases where there is no ambiguity.

Make sure that the path in `$BASH_IT` is absolute because this path gets embedded in the template `.bash_profile` file if selected by the user.
2021-09-16 16:59:02 -07:00
John D Pell 85408743fa lib/log: default to no logging at all
Set the default when BASH_IT_LOG_LEVEL is unbound to log level none: no warnings or errors are reported at all.
2021-08-26 14:11:41 -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
John D Pell 8fb75cf0e3 lib/helpers: handle unbound parameter
Expressly handle $BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE being not-set as being blank.
2021-08-26 14:11:41 -07:00
John D Pell 0eff44930c lib/utilities: handle unbound parameter
Expressly handle unbound $BASH_IT_GREP when testing for value
2021-08-26 14:11:41 -07:00
John D Pell 233fcc3091 lib/log: handle undefined variable
Expressly deal with if $echo_yellow hasn’t been defined
2021-08-26 14:11:41 -07:00
John D Pell bcd67db4ab lib/preview: handle unbound parameter
If $BASH_PREVIEW is unset, treat it as blank.
2021-08-26 14:11:41 -07:00
John D Pell 02c13b7921 lib/log: handle undefined variables
If the user hasn't defined BASH_IT_LOG_LEVEL, then the integer comparison fails. Handle it by defaulting to '1'.
If lib/log is loaded improperly, the BASH_IT_LOG_PREFIX may be undefined. Unlikely, but no harm in handling it too.
Likewise, if no theme is loaded, then $echo_green, $echo_normal, et al are not defined.
2021-08-26 14:11:41 -07:00
John D Pell 0f28824ad5 lib/helpers: invert test in _bash_it_homebrew_check()
Check if `brew` is installed every time, and *unset* `$BASH_IT_HOMEBREW_PREFIX` if not found. This accounts for the edge-case of a user _uninstalling_ Homebrew without restarting the shell.
2021-08-22 12:48:48 -07:00
John D Pell 9e255c2139 lib/helpers: new function to set BASH_IT_HOMEBREW_PREFIX
New function `_bash_it_homebrew_check()` sets global variable `$BASH_IT_HOMEBREW_PREFIX` using `brew --prefix` if `brew` exists as a valid command. If `brew` isn't installed, then return failure.

Plugins can test for `brew` by calling this function and, if it succeeds, they can rely on `$BASH_IT_HOMEBREW_PREFIX` being defined properly.
2021-08-22 12:48:48 -07:00
Noah Gorny 9566a3ec18 helpers: Improve pull_and_update_inner by restoring old pwd
Renamed the function to _bash-it_update_migrate_and_restart
Use pushd/popd instead of passing another parameter
Document the function so it will be clear that it does not return
2021-08-18 00:29:45 +03:00
Noah Gorny caec973c18 helpers: Pop pwd correctly when not needing to update 2021-08-17 23:50:58 +03:00
John D Pell de9ea54b81
Don't call external `uname` when `$OSTYPE` will do (#1911)
* lib/helpers: use `$OSTYPE` instead of `$(uname)`

* plugins/osx: use `$OSTYPE` instead of `$(uname)`

* plugins/boot2docker: use `$OSTYPE` instead of `$(uname)`

* plugins/python: use `$OSTYPE` instead of `$(uname)`

* plugins/base: use `$OSTYPE` instead of `$(uname)`

Alsö, use `[[` instead of `[` as the former has less insane argument handling being shell syntax rather than a builtin command that must emulate being a real binary

* completion/brew: use `$OSTYPE` instead of `$(uname)`

* completion/git: use `$OSTYPE` instead of `$(uname)`

Alsö, use `[[` instead of `[`.

* completion/fabric: use `$OSTYPE` instead of `uname`

* theme/demula: use `$OSTYPE` instead of `$(uname)`

* theme/rana: use `$OSTYPE` instead of `$(uname)`
2021-08-14 10:20:12 +03:00
Gurkirat Singh e51fe1fe2b
Abort upgrade if unsaved changes found in bashit directory (#1890)
helper (improvement): added safeguard for unsaved changes
2021-06-23 13:25:42 +03:00
Gurkirat Singh 01b916c544 helpers (bugfix): restart bashit after upgrade 2021-06-11 12:41:28 +05:30
Noah Gorny 7b5f758eba helpers: Fix broken compoure references after vendor change 2021-03-21 21:52:47 +02:00
buhl 49d7d2e8c4 Getting Bash-it to use the vendored composure
Fixed tests
Fixed install.sh and bash_it.sh
Added gitattributes to the vendor folder
Changed documentation
2021-02-02 16:34:04 +01:00
Noah Gorny 2b66100c47 helpers: Add _completion_exists helper 2021-01-28 17:40:20 +02:00
buhl 29855ed1e6 Adding preexec as a vendored library
Added a vendored lib loading routine in bash-it.sh
Added documentation on how to vendor libs in bash-it
Added and fixed plugins using preexec
Added tests for two plugins
Removed the old preexec lib
2021-01-23 18:31:18 +01:00
cornfeedhobo 61f727fb96
refactor all history modifications into discrete plugins 2021-01-15 11:53:28 -06:00
Noah Gorny 6914a2345a version: Fix url in case it is ssh based one 2020-12-21 00:30:56 +02:00
Noah Gorny e023d6f851 Improve bash-it version output
As we now have "stable" releases and "dev" type of versions, `version` command should
provide usefull output on that
2020-10-27 20:01:50 +02:00
Noah Gorny 825fc88a8f Rename _bash-it_update to _bash-it-update 2020-10-25 15:24:19 +02:00
Noah Gorny 8a36f21ca1 Add _binary_exists and use in github-cli completion
gh was also used as an git alias, and caused _command_exists to not fail as expected
2020-10-21 00:14:11 +03:00
Noah Gorny c387517122
Merge pull request #1626 from NoahGorny/update-to-stable-or-unstable
bash-it update to stable or dev
2020-10-16 14:16:06 +03:00
Noah Gorny a1adfaaa3e lib: helpers: Handle stable revert update 2020-10-13 15:41:28 +03:00
Noah Gorny 6bed26eccb lib: helpers: Rename Upgrading -> Updating 2020-10-13 15:30:19 +03:00
Noah Gorny 0a9b43e86d lib: Fetch from remote before calculating latest tag in bash-it update 2020-10-13 15:30:19 +03:00
Noah Gorny 4ca6dd9a36 helpers: Add --slient option to bash-it update 2020-10-13 14:42:02 +03:00
Noah Gorny 9b208e7d5c lib: Update no-op message in case of stable update 2020-10-13 14:42:02 +03:00
Noah Gorny 8e6876719b lib: Add BASH_IT_DEVELOPMENT_BRANCH variable 2020-10-13 14:42:02 +03:00
Noah Gorny ecf65569ce lib: Update to stable now correctly fails if no tags are present 2020-10-13 14:42:02 +03:00
Noah Gorny 96295e92a5 lib: Improve bash-it update so it can update to latest tag 2020-10-13 14:42:02 +03:00
Noah Gorny f4279e63c1 Add bash-it restart command
Also add completion and completion tests
2020-10-12 15:29:36 +03:00
Noah Gorny 24c05995e7 helpers: Auto reload now only reloads and not reset the shell 2020-10-10 04:02:30 +03:00
cornfeedhobo 97bb1fc7ba
allow the caller to pass a custom log message when the command is not found 2020-08-03 14:20:04 -05:00
Noah Gorny 72dbfd2480 lib: log: Insert log level before message prefix
Also fix tests accordinly
2020-07-02 21:11:40 +03:00
Noah Gorny e6ebcda608 log: Fix logging to comply with the tests 2020-07-02 21:11:40 +03:00
Noah Gorny 8d9f81fce0 lib: Add get-component-name/type-from-path 2020-07-02 20:13:57 +03:00
Noah Gorny 8a3cf76307 lib: Move _has_colors to log module 2020-07-02 20:13:42 +03:00
Noah Gorny 5daecc9381 lib: Log in case _command_exists fails 2020-06-30 20:58:09 +03:00
Noah Gorny 9a23725ce0 log: Add BASH_IT_LOG_PREFIX option
Also add a new test to check it
2020-06-25 00:16:16 +03:00
Noah Gorny 3e7a95660f lib: Add _has_colors function and use it in log output 2020-06-23 15:42:22 +03:00
Noah Gorny 86824a93ed helpers: Add bash-it doctor command 2020-06-23 15:12:43 +03:00
Noah Gorny 802c45b401 lib: Add log module 2020-06-23 15:12:43 +03:00
Noah Gorny 3eac73f613 plugins: Rename gitstatusd plugin to gitstatus 2020-06-22 14:57:05 +03:00
Noah Gorny bda85c3679 lib: Add on-disable-callback for plugins to use 2020-06-22 14:56:13 +03:00
Eduardo Bellido Bellido 1bf9bbde0d Use new line character instead semicolon in the preexec hook 2020-03-14 22:56:30 +01:00
cornfeedhobo d4c2f8b73f
nit pick cleanup 2020-03-08 23:53:27 -05:00
John McBride 036c26dbed Update jump plugin
- remove z plugin
- remove fasd plugin
- update test that referenced fsad

Signed-off-by: John McBride <jpmmcbride@gmail.com>
2020-02-03 11:43:24 -07:00
Nils Winkler f29a195f49 Make sed replacements work for both BSD and GNU sed
Fixes #1411
2019-07-31 08:50:33 +02:00
Eivind Uggedal 4ea5fe57c9
utilities.bash: fix tiny typo 2019-04-14 22:31:38 +02:00
Nils Winkler 04937aa2ec
Merge pull request #1312 from kylewelsby/bugfix/1203-bug-enable-alias-all
Fixes #1203 convert alias to aliases
2019-01-21 08:36:38 +01:00