Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax: turn FunctionNextLine into an option that applies to "{", "then", and "do" #721

Open
mvdan opened this issue Aug 16, 2021 · 7 comments

Comments

@mvdan
Copy link
Owner

mvdan commented Aug 16, 2021

See #229 (comment).

The existing https://pkg.go.dev/mvdan.cc/sh/v3/syntax#FunctionNextLine option is available via shfmt -fn. It works fairly well:

$ echo 'f() { foo; bar; }' | shfmt
f() {
	foo
	bar
}
$ echo 'f() { foo; bar; }' | shfmt -fn
f()
{
	foo
	bar
}

However, it only affects the { opening token, and not others:

$ echo 'for i in 1 2 3; do if true; then foo; bar; fi; baz; done' | shfmt
for i in 1 2 3; do
	if true; then
		foo
		bar
	fi
	baz
done

I propose to replace FunctionNextLine and -fn with a more general option, which would put all opening tokens on a separate line. For example, if we called the flag -tn for TokenNextLine, the behavior would be:

$ shfmt -tn input.sh
f() { foo; } # single-line still permitted
f()
{
	foo
	bar
}

if true; then foo; fi # single-line still permitted
for i in 1 2 3
do
	if true
	then
		foo
		bar
	fi
	baz
done

This could either be implemented in v3, keeping -fn and FunctionNextLine deprecated, or in a future v4 replacing the existing option. The existing option would be removed in v4 either way; the question is whether we should prioritize adding this option sooner, or pushing for v4 instead.

@mvdan
Copy link
Owner Author

mvdan commented Aug 16, 2021

I should also clarify that this option would apply to all { tokens as well, not just those for functions. For example:

for i in 1 2 3
{ # this newline doesn't break anything
	foo
}

coproc foo { # note that a newline before "{" changes the program here
	bar
}

@mvdan mvdan changed the title syntax: turn FunctionNextLine into an option that also applies to "then" and "do" syntax: turn FunctionNextLine into an option that also applies to "{", "then", and "do" Aug 16, 2021
@mvdan mvdan changed the title syntax: turn FunctionNextLine into an option that also applies to "{", "then", and "do" syntax: turn FunctionNextLine into an option that applies to "{", "then", and "do" Aug 16, 2021
@gaelicWizard
Copy link

fwiw, I'd love to have this available sooner than later 😃

@wwalker
Copy link

wwalker commented Aug 30, 2021

I, also, would love to have this available sooner than later.

However, I would ask that it be separate.

  • -fn still for {
  • -i-dislike-semicolons-in-if-and-while-and-until for ; then and ; do
    • might want a shorter option name :-)

@mvdan
Copy link
Owner Author

mvdan commented Aug 31, 2021

However, I would ask that it be separate.

If you mean keep the current -fn flag as-is, and add a new flag for then and do, that's very unlikely to happen. More options make my job harder, the tool more difficult to document and use, and add long-term maintenance and testing work.

So I really only add options when I have to. This disctinction you bring up feels like a minor preference in an opt-in feature, and I don't think there's any style/formatting guide that strongly separates the two cases.

gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 9, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 10, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 12, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 12, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 12, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 17, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 17, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 17, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 18, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 18, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 18, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 18, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 19, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 19, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 19, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 19, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 20, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 20, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Sep 20, 2021
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Jan 26, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Jan 26, 2022
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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Jan 26, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Jan 26, 2022
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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Jan 26, 2022
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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Jan 30, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Jan 30, 2022
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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 1, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 1, 2022
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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 7, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 7, 2022
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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 8, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 8, 2022
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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 9, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 9, 2022
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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 13, 2022
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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 14, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 14, 2022
- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
- Place `composure.sh` init all in one place
- remove 10-years-deprecated backwards compatibility: Deprecated in `b59ee658f78ec6ff8c6c2754216e0322b7fe18e2` dated 2011-10-29.

main: adopt `_bash-it-log-prefix-by-path()`

main: variable name cleanup

pathmunge tests

lib/appearance: `shellcheck` && `shfmt`

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: don't redefine battery_char()

Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both.

Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: `shellcheck` SC2154

These variables are referenced by themes already linted.

lib/theme.githelpers: unbound varbl

lib/theme: don't use `date` for `$THEME_CLOCK_FORMAT`

lib: delete `appearance.bash`

This adds *three* lines to `bash_it.sh`, and two to `plugin/base`. Just not worth an extra file requiring special handling.

make aliases load very late

...and update all the tests...

plugins/go: simplify _bash-it-gopath-pathmunge()

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

completion/grunt: shellcheck

plugins/xterm: not just Xterm

lib/battery: rename `plugin/battery`

This plugin *only* provides utility functions, so it has zero cost to just being enabled. This allows us to eliminate assumptions from `lib/theme` and several themes.

main: load custom theme

Allow for simpler directory strucutre when loading theme from `$CUSTOM_THEME_DIR`/`$BASH_IT_CUSTOM`

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/todo: lint

plugin/base: use `_bash-it-component-item-is-enabled()`

plugins/alias: remove old `SC2154` flag

This is no logner needed because the `local` keyword was moved higher up in the function.

install: use `.bashrc` and notify user

The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix usage statement `_bash-it-search()`

SC2154

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/search: code cleanup

Improve `_bash-it-erase-term()`, `_bash-it-flash-term()`, `_bash-it-rewind()`, `_bash-it-search-result()`, and `_bash-it-search-component()`. Minor tweaks to `_bash-it-is-partial-match()`, and `_bash-it-search()`.

pathmunge tests

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
- Place `composure.sh` init all in one place

main: adopt `_bash-it-log-prefix-by-path()`

lib/reloader: adopt `_bash-it-log-prefix-by-path()`

lib/appearance: `shellcheck` && `shfmt`

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: don't redefine battery_char()

Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both.

Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: `shellcheck` SC2154

These variables are referenced by themes already linted.

lib/theme.githelpers: unbound varbl

lib/theme: don't use `date` for `$THEME_CLOCK_FORMAT`

main: simplify flow of lib loader loop

Eliminate the separate loop for `vendor/init.d` since it's just as easy to glob it in the `lib` loop.

lib: delete `appearance.bash`

This adds *three* lines to `bash_it.sh`, and two to `plugin/base`. Just not worth an extra file requiring special handling.

main: load custom theme

Allow for simpler directory strucutre when loading theme from `$CUSTOM_THEME_DIR`/`$BASH_IT_CUSTOM`

make aliases load very late

...and update all the tests...

preexec: add helper functions to loader

Define the helper functions for `bash-preexec.sh` immediately after importing it, rather than in `lib/theme`.
- `__check_precmd_conflict()` and `save_append_prompt_command()` are generally useful and not theme-specific.
- Add matching `__check_preexec_conflict()` like `__check_precmd_conflict()`, and alsö `safe_append_preexec()`.

preexec: work around upstream

Alsö, move `set +T` in here.

test/theme: make fewer assumptions

Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉

That said, we do want to verify that the function was actually loaded.

TODO: actually test the function.

install: use `.bashrc` and notify user

The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

plugins/thefuck: lint

plugins/todo: lint

plugin/base: use `_bash-it-component-item-is-enabled()`

completion/git: use `_completion_exists()`

plugins/alias: remove old `SC2154` flag

This is no logner needed because the `local` keyword was moved higher up in the function.

BATS: enable strict mode

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/theme: simplify default variables and avoid binary execution

Use `type -P` instead of `which` to get the path-on-disk (not alias or function) without having to invoke an external binary.

Alsö, simplify some parameter defaults.

theme/powerline: fix source path for theme base

completion/system: correctly load version when not linked

- Load the correct version of `bash-completion` even when not "linked".

preexec: work around upstream

Alsö, move `set +T` in here.

test/theme: make fewer assumptions

Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉

That said, we do want to verify that the function was actually loaded.

TODO: actually test the function.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

lib/search: simplify `read` usage

Avoid having to loop by abusing *both* `$IFS` _and_ `-d ''`: this makes `read` intake the entire file, and split in to an array by line.

plugins/fuck: aliases

Add themes/*.bash to lint

Lint everything (add dirs to `clean_files.txt`)

theme/barbuk: fix SC2154, and clean up

Handle all unbound parameters, even colors!

Alsö, fix some local variables and variable assignments.

The unicode/emoji symbols don’t show up for me so that makes me think they won’t work, but it *looks* like the history has these characters in them so…I dunno

theme/binaryanomaly: SC2154

Handle all unbound parameters, even colors!

Local some variables, &c

theme/brainy: work-in-progress

Handle all unbound parameters, even colors!

theme/modern: SC2154

Handle all unbound parameters, even colors!

theme/brainy

theme/binaryanomaly

lib/helpers: remove log message from `_command_exists()` et al

- and move them to `lib/utilities`

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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 18, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 18, 2022
- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
- Place `composure.sh` init all in one place
- remove 10-years-deprecated backwards compatibility: Deprecated in `b59ee658f78ec6ff8c6c2754216e0322b7fe18e2` dated 2011-10-29.

main: adopt `_bash-it-log-prefix-by-path()`

main: variable name cleanup

pathmunge tests

lib/appearance: `shellcheck` && `shfmt`

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: don't redefine battery_char()

Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both.

Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: `shellcheck` SC2154

These variables are referenced by themes already linted.

lib/theme.githelpers: unbound varbl

lib/theme: don't use `date` for `$THEME_CLOCK_FORMAT`

lib: delete `appearance.bash`

This adds *three* lines to `bash_it.sh`, and two to `plugin/base`. Just not worth an extra file requiring special handling.

make aliases load very late

...and update all the tests...

plugins/go: simplify _bash-it-gopath-pathmunge()

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

completion/grunt: shellcheck

plugins/xterm: not just Xterm

lib/battery: rename `plugin/battery`

This plugin *only* provides utility functions, so it has zero cost to just being enabled. This allows us to eliminate assumptions from `lib/theme` and several themes.

main: load custom theme

Allow for simpler directory strucutre when loading theme from `$CUSTOM_THEME_DIR`/`$BASH_IT_CUSTOM`

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/todo: lint

plugin/base: use `_bash-it-component-item-is-enabled()`

plugins/alias: remove old `SC2154` flag

This is no logner needed because the `local` keyword was moved higher up in the function.

install: use `.bashrc` and notify user

The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix usage statement `_bash-it-search()`

SC2154

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/search: code cleanup

Improve `_bash-it-erase-term()`, `_bash-it-flash-term()`, `_bash-it-rewind()`, `_bash-it-search-result()`, and `_bash-it-search-component()`. Minor tweaks to `_bash-it-is-partial-match()`, and `_bash-it-search()`.

pathmunge tests

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
- Place `composure.sh` init all in one place

main: adopt `_bash-it-log-prefix-by-path()`

lib/reloader: adopt `_bash-it-log-prefix-by-path()`

lib/appearance: `shellcheck` && `shfmt`

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: don't redefine battery_char()

Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both.

Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: `shellcheck` SC2154

These variables are referenced by themes already linted.

lib/theme.githelpers: unbound varbl

lib/theme: don't use `date` for `$THEME_CLOCK_FORMAT`

main: simplify flow of lib loader loop

Eliminate the separate loop for `vendor/init.d` since it's just as easy to glob it in the `lib` loop.

lib: delete `appearance.bash`

This adds *three* lines to `bash_it.sh`, and two to `plugin/base`. Just not worth an extra file requiring special handling.

main: load custom theme

Allow for simpler directory strucutre when loading theme from `$CUSTOM_THEME_DIR`/`$BASH_IT_CUSTOM`

make aliases load very late

...and update all the tests...

preexec: add helper functions to loader

Define the helper functions for `bash-preexec.sh` immediately after importing it, rather than in `lib/theme`.
- `__check_precmd_conflict()` and `save_append_prompt_command()` are generally useful and not theme-specific.
- Add matching `__check_preexec_conflict()` like `__check_precmd_conflict()`, and alsö `safe_append_preexec()`.

preexec: work around upstream

Alsö, move `set +T` in here.

test/theme: make fewer assumptions

Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉

That said, we do want to verify that the function was actually loaded.

TODO: actually test the function.

install: use `.bashrc` and notify user

The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

plugins/thefuck: lint

plugins/todo: lint

plugin/base: use `_bash-it-component-item-is-enabled()`

completion/git: use `_completion_exists()`

plugins/alias: remove old `SC2154` flag

This is no logner needed because the `local` keyword was moved higher up in the function.

BATS: enable strict mode

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/theme: simplify default variables and avoid binary execution

Use `type -P` instead of `which` to get the path-on-disk (not alias or function) without having to invoke an external binary.

Alsö, simplify some parameter defaults.

theme/powerline: fix source path for theme base

completion/system: correctly load version when not linked

- Load the correct version of `bash-completion` even when not "linked".

preexec: work around upstream

Alsö, move `set +T` in here.

test/theme: make fewer assumptions

Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉

That said, we do want to verify that the function was actually loaded.

TODO: actually test the function.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

lib/search: simplify `read` usage

Avoid having to loop by abusing *both* `$IFS` _and_ `-d ''`: this makes `read` intake the entire file, and split in to an array by line.

plugins/fuck: aliases

Add themes/*.bash to lint

Lint everything (add dirs to `clean_files.txt`)

theme/barbuk: fix SC2154, and clean up

Handle all unbound parameters, even colors!

Alsö, fix some local variables and variable assignments.

The unicode/emoji symbols don’t show up for me so that makes me think they won’t work, but it *looks* like the history has these characters in them so…I dunno

theme/binaryanomaly: SC2154

Handle all unbound parameters, even colors!

Local some variables, &c

theme/brainy: work-in-progress

Handle all unbound parameters, even colors!

theme/modern: SC2154

Handle all unbound parameters, even colors!

theme/brainy

theme/binaryanomaly

lib/helpers: remove log message from `_command_exists()` et al

- and move them to `lib/utilities`

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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 20, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 20, 2022
- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
- Place `composure.sh` init all in one place
- remove 10-years-deprecated backwards compatibility: Deprecated in `b59ee658f78ec6ff8c6c2754216e0322b7fe18e2` dated 2011-10-29.

main: adopt `_bash-it-log-prefix-by-path()`

main: variable name cleanup

pathmunge tests

lib/appearance: `shellcheck` && `shfmt`

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: don't redefine battery_char()

Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both.

Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: `shellcheck` SC2154

These variables are referenced by themes already linted.

lib/theme.githelpers: unbound varbl

lib/theme: don't use `date` for `$THEME_CLOCK_FORMAT`

lib: delete `appearance.bash`

This adds *three* lines to `bash_it.sh`, and two to `plugin/base`. Just not worth an extra file requiring special handling.

make aliases load very late

...and update all the tests...

plugins/go: simplify _bash-it-gopath-pathmunge()

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

completion/grunt: shellcheck

plugins/xterm: not just Xterm

lib/battery: rename `plugin/battery`

This plugin *only* provides utility functions, so it has zero cost to just being enabled. This allows us to eliminate assumptions from `lib/theme` and several themes.

main: load custom theme

Allow for simpler directory strucutre when loading theme from `$CUSTOM_THEME_DIR`/`$BASH_IT_CUSTOM`

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/todo: lint

plugin/base: use `_bash-it-component-item-is-enabled()`

plugins/alias: remove old `SC2154` flag

This is no logner needed because the `local` keyword was moved higher up in the function.

install: use `.bashrc` and notify user

The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix usage statement `_bash-it-search()`

SC2154

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/search: code cleanup

Improve `_bash-it-erase-term()`, `_bash-it-flash-term()`, `_bash-it-rewind()`, `_bash-it-search-result()`, and `_bash-it-search-component()`. Minor tweaks to `_bash-it-is-partial-match()`, and `_bash-it-search()`.

pathmunge tests

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
- Place `composure.sh` init all in one place

main: adopt `_bash-it-log-prefix-by-path()`

lib/reloader: adopt `_bash-it-log-prefix-by-path()`

lib/appearance: `shellcheck` && `shfmt`

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: don't redefine battery_char()

Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both.

Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: `shellcheck` SC2154

These variables are referenced by themes already linted.

lib/theme.githelpers: unbound varbl

lib/theme: don't use `date` for `$THEME_CLOCK_FORMAT`

main: simplify flow of lib loader loop

Eliminate the separate loop for `vendor/init.d` since it's just as easy to glob it in the `lib` loop.

lib: delete `appearance.bash`

This adds *three* lines to `bash_it.sh`, and two to `plugin/base`. Just not worth an extra file requiring special handling.

main: load custom theme

Allow for simpler directory strucutre when loading theme from `$CUSTOM_THEME_DIR`/`$BASH_IT_CUSTOM`

make aliases load very late

...and update all the tests...

preexec: add helper functions to loader

Define the helper functions for `bash-preexec.sh` immediately after importing it, rather than in `lib/theme`.
- `__check_precmd_conflict()` and `save_append_prompt_command()` are generally useful and not theme-specific.
- Add matching `__check_preexec_conflict()` like `__check_precmd_conflict()`, and alsö `safe_append_preexec()`.

preexec: work around upstream

Alsö, move `set +T` in here.

test/theme: make fewer assumptions

Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉

That said, we do want to verify that the function was actually loaded.

TODO: actually test the function.

install: use `.bashrc` and notify user

The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

plugins/thefuck: lint

plugins/todo: lint

plugin/base: use `_bash-it-component-item-is-enabled()`

completion/git: use `_completion_exists()`

plugins/alias: remove old `SC2154` flag

This is no logner needed because the `local` keyword was moved higher up in the function.

BATS: enable strict mode

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/theme: simplify default variables and avoid binary execution

Use `type -P` instead of `which` to get the path-on-disk (not alias or function) without having to invoke an external binary.

Alsö, simplify some parameter defaults.

theme/powerline: fix source path for theme base

completion/system: correctly load version when not linked

- Load the correct version of `bash-completion` even when not "linked".

preexec: work around upstream

Alsö, move `set +T` in here.

test/theme: make fewer assumptions

Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉

That said, we do want to verify that the function was actually loaded.

TODO: actually test the function.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

lib/search: simplify `read` usage

Avoid having to loop by abusing *both* `$IFS` _and_ `-d ''`: this makes `read` intake the entire file, and split in to an array by line.

plugins/fuck: aliases

Add themes/*.bash to lint

Lint everything (add dirs to `clean_files.txt`)

theme/barbuk: fix SC2154, and clean up

Handle all unbound parameters, even colors!

Alsö, fix some local variables and variable assignments.

The unicode/emoji symbols don’t show up for me so that makes me think they won’t work, but it *looks* like the history has these characters in them so…I dunno

theme/binaryanomaly: SC2154

Handle all unbound parameters, even colors!

Local some variables, &c

theme/brainy: work-in-progress

Handle all unbound parameters, even colors!

theme/modern: SC2154

Handle all unbound parameters, even colors!

theme/brainy

theme/binaryanomaly

lib/helpers: remove log message from `_command_exists()` et al

- and move them to `lib/utilities`

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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 20, 2022
- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
- Place `composure.sh` init all in one place
- remove 10-years-deprecated backwards compatibility: Deprecated in `b59ee658f78ec6ff8c6c2754216e0322b7fe18e2` dated 2011-10-29.

main: adopt `_bash-it-log-prefix-by-path()`

main: variable name cleanup

pathmunge tests

lib/appearance: `shellcheck` && `shfmt`

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: don't redefine battery_char()

Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both.

Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: `shellcheck` SC2154

These variables are referenced by themes already linted.

lib/theme.githelpers: unbound varbl

lib/theme: don't use `date` for `$THEME_CLOCK_FORMAT`

lib: delete `appearance.bash`

This adds *three* lines to `bash_it.sh`, and two to `plugin/base`. Just not worth an extra file requiring special handling.

make aliases load very late

...and update all the tests...

plugins/go: simplify _bash-it-gopath-pathmunge()

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

completion/grunt: shellcheck

plugins/xterm: not just Xterm

lib/battery: rename `plugin/battery`

This plugin *only* provides utility functions, so it has zero cost to just being enabled. This allows us to eliminate assumptions from `lib/theme` and several themes.

main: load custom theme

Allow for simpler directory strucutre when loading theme from `$CUSTOM_THEME_DIR`/`$BASH_IT_CUSTOM`

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/todo: lint

plugin/base: use `_bash-it-component-item-is-enabled()`

plugins/alias: remove old `SC2154` flag

This is no logner needed because the `local` keyword was moved higher up in the function.

install: use `.bashrc` and notify user

The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix usage statement `_bash-it-search()`

SC2154

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/search: code cleanup

Improve `_bash-it-erase-term()`, `_bash-it-flash-term()`, `_bash-it-rewind()`, `_bash-it-search-result()`, and `_bash-it-search-component()`. Minor tweaks to `_bash-it-is-partial-match()`, and `_bash-it-search()`.

pathmunge tests

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
- Place `composure.sh` init all in one place

main: adopt `_bash-it-log-prefix-by-path()`

lib/reloader: adopt `_bash-it-log-prefix-by-path()`

lib/appearance: `shellcheck` && `shfmt`

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: don't redefine battery_char()

Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both.

Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/theme: `shellcheck` SC2154

These variables are referenced by themes already linted.

lib/theme.githelpers: unbound varbl

lib/theme: don't use `date` for `$THEME_CLOCK_FORMAT`

main: simplify flow of lib loader loop

Eliminate the separate loop for `vendor/init.d` since it's just as easy to glob it in the `lib` loop.

lib: delete `appearance.bash`

This adds *three* lines to `bash_it.sh`, and two to `plugin/base`. Just not worth an extra file requiring special handling.

main: load custom theme

Allow for simpler directory strucutre when loading theme from `$CUSTOM_THEME_DIR`/`$BASH_IT_CUSTOM`

make aliases load very late

...and update all the tests...

preexec: add helper functions to loader

Define the helper functions for `bash-preexec.sh` immediately after importing it, rather than in `lib/theme`.
- `__check_precmd_conflict()` and `save_append_prompt_command()` are generally useful and not theme-specific.
- Add matching `__check_preexec_conflict()` like `__check_precmd_conflict()`, and alsö `safe_append_preexec()`.

preexec: work around upstream

Alsö, move `set +T` in here.

test/theme: make fewer assumptions

Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉

That said, we do want to verify that the function was actually loaded.

TODO: actually test the function.

install: use `.bashrc` and notify user

The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

plugins/thefuck: lint

plugins/todo: lint

plugin/base: use `_bash-it-component-item-is-enabled()`

completion/git: use `_completion_exists()`

plugins/alias: remove old `SC2154` flag

This is no logner needed because the `local` keyword was moved higher up in the function.

BATS: enable strict mode

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/theme: simplify default variables and avoid binary execution

Use `type -P` instead of `which` to get the path-on-disk (not alias or function) without having to invoke an external binary.

Alsö, simplify some parameter defaults.

theme/powerline: fix source path for theme base

completion/system: correctly load version when not linked

- Load the correct version of `bash-completion` even when not "linked".

preexec: work around upstream

Alsö, move `set +T` in here.

test/theme: make fewer assumptions

Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉

That said, we do want to verify that the function was actually loaded.

TODO: actually test the function.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

lib/search: simplify `read` usage

Avoid having to loop by abusing *both* `$IFS` _and_ `-d ''`: this makes `read` intake the entire file, and split in to an array by line.

plugins/fuck: aliases

Add themes/*.bash to lint

Lint everything (add dirs to `clean_files.txt`)

theme/barbuk: fix SC2154, and clean up

Handle all unbound parameters, even colors!

Alsö, fix some local variables and variable assignments.

The unicode/emoji symbols don’t show up for me so that makes me think they won’t work, but it *looks* like the history has these characters in them so…I dunno

theme/binaryanomaly: SC2154

Handle all unbound parameters, even colors!

Local some variables, &c

theme/brainy: work-in-progress

Handle all unbound parameters, even colors!

theme/modern: SC2154

Handle all unbound parameters, even colors!

theme/brainy

theme/binaryanomaly

lib/helpers: remove log message from `_command_exists()` et al

- and move them to `lib/utilities`

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?

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`!

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()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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
```

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.)
- remove `compgen` from `_bash-it-describe()`

lib/helpers: fix `_bash-it-describe()`

plugins/go: update tests

Update tests for `plugins/go` to account for non-existing directories being ignored by `pathmunge()`.

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

Test was failing only on Mac OS X for some reason, so refactor a little.

lib/search: code style cleanup

Couldn't even `shellcheck` until I did a first pass...too much noise! ♥

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

lib/search: fix `_bash-it-flash-term()`

1. `$text_black` isn't a parameter provided by _Bash It_. Typo?
2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`.
3. The color was never returned to normal after.

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

If we already looked up colors, and we already have them, then don't run `tput` again.

main: Glob for *.bash properly when path contains spaces

- `shfmt`, `shellcheck`
- Clean up legacy/compatibility code to simpler control flow
- Move theme stuff down to where themes are handled
- Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir.
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)

reloader: `shellcheck` && `shfmt`

Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace.

lib/preview: `shfmt` && `shellcheck`

Fix theme file path globbing when $BASH_IT contains any spaces.

My apologies to future `git blame` hunters ♥

lib/appearance: `shellcheck` && `shfmt`

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

Move `_set-prefix-based-on-path()`

Instead of defining `_set-prefix-based-on-path()` in `scripts/reloader`, define it in `lib/utilities` so it can be helpful elsewhere too

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.

plugins/dirs: use XDG_STATE_HOME

Locate the bookmarks file in $XDG_STATE_HOME, and migrate an existing file from the old location if it exists.

plugin/dirs: `shfmt` && `shellcheck`

lib/theme: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/colors: `shellcheck` && `shfmt`

Alsö, clean up `__color_rgb` to just use a regular if block.

lib/command_duration: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

`__check_precmd_conflict()`, `save_append_prompt_command()`, and `_save-and-reload-history()` are generally useful and not theme-specific.

lib/helpers: add preexec functions

Add matching `check_preexec_conflict()` with `check_precmd_conflict()` and alsö `safe_append_preexec()`

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string.

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

Fallback to `$SECONDS` for older versions of _Bash_.

Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.

plugin/cmd-returned-notify: Rewrite to match/use `lib/command_duration`

Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell.

Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done.

Change variable names to match lib/command-duration

Rename `preexec_return_notification()` to match lib/command-duration's `_command_duration_pre_exec()`, and guard against redefining it.

This should now use the same preexec hook and variables as the theme library `command_duration`.

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

Alsö, use `_log_notice`, quote variables, handle unbound parameters, &c.

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed.

plugins/java: quote path

plugins/jekyll: simplify command flow

Use bashisms, remove suplerfous variable, use parameter default value replacement

plugins/latex: 2009 was 12 years ago

Glob the currently installed edition, instead of transpoting us back to undergrad.

plugins/osx-timemachine: code style cleanups

Use bash functionality rather than external binaries, or even builtins. Alsö, if $SUDO_ASKPASS is set then pass -A to sudo.

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

Use shell functionality to avoid invoking external binaries, and quote some stuff.
Alsö, use $EDITOR and related variables in order to fall through if some aren't defined.

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

No need for gymnastics to determine if variable had been exported priort to modification. If it was, then it still is. See man bash(1).

plugins/osx: unbound PROMPT_COMMAND

I don't think this is possible given bash-preexec.sh dependency and early load.

completion/system: accomodate multiple versions

For Homebrew, switch between v1 and v2 of bash-completion based on whether the running Bash shell is new enough to use v2.

plugins/go: simplify _bash-it-gopath-pathmunge()

plugins/man: Add "R" to `$LESS`

plugin/history: no need to set a trap
Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function.

Also, set the defaults in a way that is happy with read-only parameters.

plugin/latex: just call `pathmunge()` as it will check if the directory exists itself

plugin/nginx: dont overwrite user-set variable, and quote path just in case

plugin/git-subrepo: use `$HOME` instead of `~`

If the outer variable is double-quoted, then the default expansion when undefined does not get tilde-expanded. Use `$HOME`.

aliases/general: minor fixes

- Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`.
- Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically?
- Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files).

themes/base: use `type -P` instead of `which`

Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it#1818.

NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically.

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

Don't overwrite variables that the user has already set.

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

plugin/base: use `_bash-it-component-item-is-enabled()`

lib/githelpers: `shfmt` && `shellcheck`

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.

lib/helpers: new functions `_bash_it_history_auto_*()`

Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively.

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

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.

main: lint false positive

style consistency improvements

Adjust location of quotation marks in paths for visual consistency.
Use double-bracket test evaluation, which has better feature support and avoids possible external tool invocation.

Reduce environmental pollution

Don’t `export` every single variable… Only variables that need to be seen by child processes need to be `export`ed.

lib: avoid duplicate inclusion

For lib/log and lib/utilities, add double-inclusion protection as we're so early in startup that these are loaded explicitly rather than through `reloader.sh` or even the early lib load loop.
This *slightly* improves performance, but alsö improves debugging by reducing surface area.

lint defaults and base

No need for `cat`

The input redirection can go at the beginning, it doens't need to go at the end.

main: add some debugging

alsö, clear a loop variable and set BASH_IT_LOG_PREFIX after reloader.

main: move Jekyll stuff to plugins/jekyll

If the user doesn't load the Jekyll plugin, then don't load any Jeykll stuff.

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

plugins/history: Add `autoshare` to `$HISTCONTROL`

lib/helpers: fix `_command_exists()`

The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.

lib/helpers: set return value of `pathmunge`

This allows use as a test condition, but for very simple plugins this sets the return value for the whole plugin

lib/log: automate log prefix

Automatically set log prefix when sourcing a file, and relinquish it when returning from that file.

TODO: move _bash_it_log_section to alias instead of _bash_it_log_prefix_push()

Reduce subshells and make reloader only loop

Move the global `reloader.sh` invocation inside the loop to simplify control flow: load global, then aliases, plugins, and completions in one structure.

Create lib finalize hook

Create an array `_bash_it_library_finalize_hook` and loop at the end of the main `bash_it.sh` to run each element in the array.

The purpose here is to run some command after everything else has been loaded. For example, the appearance lib checks for executables for SCM commands, but `$PATH` may be altered after appearance has loaded and therefore some available commands may never be discovered. Therefore, create `_bash_it_appearance_scm_init()` and add it to the hook. It will re-check at end of `bash_it.sh` just before prompt is first displayed.

Alsö, use this for the log cleanup function, and for the `set +T` for DEBUG inheritance.

lib: fix _bash_it_library_finalize_hook

It's an array, not a string.

Move bash-it reload alias to aliases/bash-it
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Feb 20, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
gaelicWizard added a commit to gaelicWizard/bash-it that referenced this issue Mar 4, 2022
and disable `shfmt` for now pending upstream mvdan/sh#721

Let function blocks begin on new lines so that the opennign and closing braces align.
@mvdan
Copy link
Owner Author

mvdan commented Mar 29, 2022

@gaelicWizard I'm not sure if it's on purpose, but note how you're filling some of the issues here with hundreds of commit references. Please tone it down if you can, as it makes the threads hard to read.

@ale5000-git
Copy link

ale5000-git commented Oct 18, 2022

Hi,
personally I do want curly brackets of functions on the next line but do and then on the same line.
do and then are neither functions nor curly brackets so I think they never belong here.

PS: I vote for the officially listed => curly_bracket_next_line

@mvdan
Copy link
Owner Author

mvdan commented Oct 20, 2022

It's fine if you want a specific way to format your programs. But shfmt can't support every option and formatting style possible, because that is essentially impossible to maintain and test. Or even use - just see https://linux.die.net/man/1/indent. Most people find this proposal to be a good idea per this thread, and I don't see the point in maintaining multiple options per the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants