-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
add profile subcommand #1865
add profile subcommand #1865
Conversation
At first blush, this seems compatible with the work I discussed here: I keep the script as a gist here: |
I see, nice work there 😄 I still like my solution, as it also checks for the profile integrity before loading, and provides a standardized way to specify profiles. |
I have to admit, I'm a little surprised by this. I hop laptops every few years and just take bash-it with me. Almost always something breaks and the system needs adjustment before things click into place. For this reason, I don't think I'll be a good reviewer. I guess my only $0.02 is to say that this feels like it also overlaps, or could, with the idea of installing bash-it system wide - if only because instead of having a profile command, we could make loaded plugins, aliases, and completions a set of permanent configs, which would likely be much easier to reason about in a centralized, system wide install. Once that's complete, "exporting" becomes just another config file copy. |
@NoahGorny Nicely done. With this feature we can also ship optimised profile templates so that end users can effectively load it on their end. |
@NoahGorny Can we re-use With my proposal for servers (#1825) I didn't want to make things look complicated |
I got to look at this with fresh eyes today and better understand what's going on. I like this idea. I could envision switching profiles for different language development, or to test out a friend's setup. Cool. |
6ab34b6
to
6f304d6
Compare
@cornfeedhobo @davidpfarrell @tbhaxor Added many tests, new install option and docs Take a look now 😄 |
cb9bb17
to
aba9281
Compare
@NoahGorny Any blockers? When are we planning to release this feature |
Because this is a fairly big change, I am waiting for a review from you guys. |
In order to ship Bash It via a package manager (#1819), the whole symlinks thing will need to be replaced as Oh My Zsh uses, for example, |
@davidpfarrell ping |
@cornfeedhobo ping as well :) |
@NoahGorny If you want to rebase this, I can test over the coming days and we can finally get this out. Thanks for your patience!! |
I like this feature as I've accidentally blown out my enabled directory more than once this week. 😃 |
aba9281
to
7b7892d
Compare
@cornfeedhobo I have rebased it on the latest master 😄 |
@NoahGorny Alright, looking good so far. Here are some thoughts from my first hands on test:
|
@NoahGorny I just found that this also leaves a dirty git state is the user's |
Alright @cornfeedhobo, great work! I am going on a vacation today so I will not be available for the following days. I will address your comments after I will return 😄 |
@NoahGorny sounds good. Have a great vacation! |
80298ff
to
cd38f32
Compare
Thanks for the great review @cornfeedhobo, you had great points! |
Alright, I think it is finally time! |
Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit...
Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit...
Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit...
Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit...
- 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: fix `_command_exists()` The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`! lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit... 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: 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.) lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh issue 558 lib/helpers: unbound positional parameters lib/helpers: fix profile subcommand tests plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: fix tests This subshell is...wut lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: simplify some functions - add some `local` variables, - don't subshell `_typeset_functions`, lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: delete `_bash-it-determine-component-status-from-path()` Duplicate function of existing `_bash-it-component-item-is-enabled()`. lib/helpers: quotes for consistency Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too. lib/helpers: simplify some quote escapes 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. 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: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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/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/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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. BATS: enable strict mode 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` 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/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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh#558 lib/helpers: unbound positional parameters lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: local 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. lib/log: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/command_duration: remove temporary files 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. lib/command_duration: consolidate functions 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 plugin/cmd-returned-notify: remove duplicate function Remove `_command_duration_pre_exec()` from plugin; just use the one from `lib/command_duration` lib/command_duration: move `theme/command_duration.theme` Rename the `theme/command_duration.theme` file as it's not really got anything to do with theming or SCM. lib/command_duration: adopt `_bash_it_library_finalize_hook` 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` 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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. 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` reloader: just loop once Move the "global" `reloader.sh` invocation inside the loop to simplify control flow: load global, then aliases, then plugins, and then completions in one structure. 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. 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. _bash_it_library_finalize_hook _bash_it_appearance_scm_init THEME_CHECK_SUDO theme/powerline: fix source path for theme base plugins/fuck: aliases Add themes/*.bash to lint Lint everything (add dirs to `clean_files.txt`) theme/atomic: lint/cleanup Use `[[` instead of `[`, set some local variables, still more to clean 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/bobby: SC2154 Handle all unbound parameters, even colors! theme/brainy: work-in-progress Handle all unbound parameters, even colors! theme/brunton: SC2154 Handle all unbound parameters, even colors! theme/candy: SC2154 Handle all unbound parameters, even colors! theme/easy: SC2154 Handle all unbound parameters, even colors! theme/modern: SC2154 Handle all unbound parameters, even colors! theme/essential: SC2154 Handle all unbound parameters, even colors! theme/atomic theme/brainy theme/binaryanomaly
- 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: fix `_command_exists()` The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`! lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit... 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: 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.) lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh issue 558 lib/helpers: unbound positional parameters lib/helpers: fix profile subcommand tests plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: fix tests This subshell is...wut lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: simplify some functions - add some `local` variables, - don't subshell `_typeset_functions`, lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: delete `_bash-it-determine-component-status-from-path()` Duplicate function of existing `_bash-it-component-item-is-enabled()`. lib/helpers: quotes for consistency Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too. lib/helpers: simplify some quote escapes 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. 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: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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/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/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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. BATS: enable strict mode 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` 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/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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh#558 lib/helpers: unbound positional parameters lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: local 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. lib/log: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/command_duration: remove temporary files 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. lib/command_duration: consolidate functions 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 plugin/cmd-returned-notify: remove duplicate function Remove `_command_duration_pre_exec()` from plugin; just use the one from `lib/command_duration` lib/command_duration: move `theme/command_duration.theme` Rename the `theme/command_duration.theme` file as it's not really got anything to do with theming or SCM. lib/command_duration: adopt `_bash_it_library_finalize_hook` 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` 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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. 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` reloader: just loop once Move the "global" `reloader.sh` invocation inside the loop to simplify control flow: load global, then aliases, then plugins, and then completions in one structure. 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. 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. _bash_it_library_finalize_hook _bash_it_appearance_scm_init THEME_CHECK_SUDO theme/powerline: fix source path for theme base plugins/fuck: aliases Add themes/*.bash to lint Lint everything (add dirs to `clean_files.txt`) theme/atomic: lint/cleanup Use `[[` instead of `[`, set some local variables, still more to clean 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/bobby: SC2154 Handle all unbound parameters, even colors! theme/brainy: work-in-progress Handle all unbound parameters, even colors! theme/brunton: SC2154 Handle all unbound parameters, even colors! theme/candy: SC2154 Handle all unbound parameters, even colors! theme/easy: SC2154 Handle all unbound parameters, even colors! theme/modern: SC2154 Handle all unbound parameters, even colors! theme/essential: SC2154 Handle all unbound parameters, even colors! theme/atomic theme/brainy theme/binaryanomaly
Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit...
- 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: fix `_command_exists()` The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`! lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit... 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: 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.) lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh issue 558 lib/helpers: unbound positional parameters lib/helpers: fix profile subcommand tests plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: fix tests This subshell is...wut lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: simplify some functions - add some `local` variables, - don't subshell `_typeset_functions`, lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: delete `_bash-it-determine-component-status-from-path()` Duplicate function of existing `_bash-it-component-item-is-enabled()`. lib/helpers: quotes for consistency Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too. lib/helpers: simplify some quote escapes 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. 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: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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/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/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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. BATS: enable strict mode 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` 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/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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh#558 lib/helpers: unbound positional parameters lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: local 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. lib/log: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/command_duration: remove temporary files 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. lib/command_duration: consolidate functions 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 plugin/cmd-returned-notify: remove duplicate function Remove `_command_duration_pre_exec()` from plugin; just use the one from `lib/command_duration` lib/command_duration: move `theme/command_duration.theme` Rename the `theme/command_duration.theme` file as it's not really got anything to do with theming or SCM. lib/command_duration: adopt `_bash_it_library_finalize_hook` 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` 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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. 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` reloader: just loop once Move the "global" `reloader.sh` invocation inside the loop to simplify control flow: load global, then aliases, then plugins, and then completions in one structure. 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. 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. _bash_it_library_finalize_hook _bash_it_appearance_scm_init THEME_CHECK_SUDO theme/powerline: fix source path for theme base plugins/fuck: aliases Add themes/*.bash to lint Lint everything (add dirs to `clean_files.txt`) theme/atomic: lint/cleanup Use `[[` instead of `[`, set some local variables, still more to clean 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/bobby: SC2154 Handle all unbound parameters, even colors! theme/brainy: work-in-progress Handle all unbound parameters, even colors! theme/brunton: SC2154 Handle all unbound parameters, even colors! theme/candy: SC2154 Handle all unbound parameters, even colors! theme/easy: SC2154 Handle all unbound parameters, even colors! theme/modern: SC2154 Handle all unbound parameters, even colors! theme/essential: SC2154 Handle all unbound parameters, even colors! theme/atomic theme/brainy theme/binaryanomaly
- 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: fix `_command_exists()` The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`! lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit... 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: 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.) lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh issue 558 lib/helpers: unbound positional parameters lib/helpers: fix profile subcommand tests plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: fix tests This subshell is...wut lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: simplify some functions - add some `local` variables, - don't subshell `_typeset_functions`, lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: delete `_bash-it-determine-component-status-from-path()` Duplicate function of existing `_bash-it-component-item-is-enabled()`. lib/helpers: quotes for consistency Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too. lib/helpers: simplify some quote escapes 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`.
- 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: fix `_command_exists()` The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`! lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit... 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: 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.) lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh issue 558 lib/helpers: unbound positional parameters lib/helpers: fix profile subcommand tests plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: fix tests This subshell is...wut lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: simplify some functions - add some `local` variables, - don't subshell `_typeset_functions`, lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: delete `_bash-it-determine-component-status-from-path()` Duplicate function of existing `_bash-it-component-item-is-enabled()`. lib/helpers: quotes for consistency Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too. lib/helpers: simplify some quote escapes 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. 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: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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/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/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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. BATS: enable strict mode 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` 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/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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh#558 lib/helpers: unbound positional parameters lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: local 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. lib/log: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/command_duration: remove temporary files 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. lib/command_duration: consolidate functions 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 plugin/cmd-returned-notify: remove duplicate function Remove `_command_duration_pre_exec()` from plugin; just use the one from `lib/command_duration` lib/command_duration: move `theme/command_duration.theme` Rename the `theme/command_duration.theme` file as it's not really got anything to do with theming or SCM. lib/command_duration: adopt `_bash_it_library_finalize_hook` 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` 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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. 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` reloader: just loop once Move the "global" `reloader.sh` invocation inside the loop to simplify control flow: load global, then aliases, then plugins, and then completions in one structure. 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. 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. _bash_it_library_finalize_hook _bash_it_appearance_scm_init THEME_CHECK_SUDO theme/powerline: fix source path for theme base plugins/fuck: aliases Add themes/*.bash to lint Lint everything (add dirs to `clean_files.txt`) theme/atomic: lint/cleanup Use `[[` instead of `[`, set some local variables, still more to clean 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/bobby: SC2154 Handle all unbound parameters, even colors! theme/brainy: work-in-progress Handle all unbound parameters, even colors! theme/brunton: SC2154 Handle all unbound parameters, even colors! theme/candy: SC2154 Handle all unbound parameters, even colors! theme/easy: SC2154 Handle all unbound parameters, even colors! theme/modern: SC2154 Handle all unbound parameters, even colors! theme/essential: SC2154 Handle all unbound parameters, even colors! theme/atomic theme/brainy theme/binaryanomaly
- 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: fix `_command_exists()` The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`! lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit... 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: 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.) lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh issue 558 lib/helpers: unbound positional parameters lib/helpers: fix profile subcommand tests plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: fix tests This subshell is...wut lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: simplify some functions - add some `local` variables, - don't subshell `_typeset_functions`, lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: delete `_bash-it-determine-component-status-from-path()` Duplicate function of existing `_bash-it-component-item-is-enabled()`. lib/helpers: quotes for consistency Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too. lib/helpers: simplify some quote escapes 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. 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: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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/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/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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. BATS: enable strict mode 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` 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/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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh#558 lib/helpers: unbound positional parameters lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: local 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. lib/log: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/command_duration: remove temporary files 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. lib/command_duration: consolidate functions 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 plugin/cmd-returned-notify: remove duplicate function Remove `_command_duration_pre_exec()` from plugin; just use the one from `lib/command_duration` lib/command_duration: move `theme/command_duration.theme` Rename the `theme/command_duration.theme` file as it's not really got anything to do with theming or SCM. lib/command_duration: adopt `_bash_it_library_finalize_hook` 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` 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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. 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` reloader: just loop once Move the "global" `reloader.sh` invocation inside the loop to simplify control flow: load global, then aliases, then plugins, and then completions in one structure. 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. 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. _bash_it_library_finalize_hook _bash_it_appearance_scm_init THEME_CHECK_SUDO theme/powerline: fix source path for theme base plugins/fuck: aliases Add themes/*.bash to lint Lint everything (add dirs to `clean_files.txt`) theme/atomic: lint/cleanup Use `[[` instead of `[`, set some local variables, still more to clean 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/bobby: SC2154 Handle all unbound parameters, even colors! theme/brainy: work-in-progress Handle all unbound parameters, even colors! theme/brunton: SC2154 Handle all unbound parameters, even colors! theme/candy: SC2154 Handle all unbound parameters, even colors! theme/easy: SC2154 Handle all unbound parameters, even colors! theme/modern: SC2154 Handle all unbound parameters, even colors! theme/essential: SC2154 Handle all unbound parameters, even colors! theme/atomic theme/brainy theme/binaryanomaly
- 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: fix `_command_exists()` The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`! lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit... 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: 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.) lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh issue 558 lib/helpers: unbound positional parameters lib/helpers: fix profile subcommand tests plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: fix tests This subshell is...wut lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: simplify some functions - add some `local` variables, - don't subshell `_typeset_functions`, lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: delete `_bash-it-determine-component-status-from-path()` Duplicate function of existing `_bash-it-component-item-is-enabled()`. lib/helpers: quotes for consistency Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too. lib/helpers: simplify some quote escapes 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. 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: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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/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/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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. BATS: enable strict mode 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` 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/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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh#558 lib/helpers: unbound positional parameters lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: local 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. lib/log: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/command_duration: remove temporary files 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. lib/command_duration: consolidate functions 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 plugin/cmd-returned-notify: remove duplicate function Remove `_command_duration_pre_exec()` from plugin; just use the one from `lib/command_duration` lib/command_duration: move `theme/command_duration.theme` Rename the `theme/command_duration.theme` file as it's not really got anything to do with theming or SCM. lib/command_duration: adopt `_bash_it_library_finalize_hook` 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` 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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. 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` reloader: just loop once Move the "global" `reloader.sh` invocation inside the loop to simplify control flow: load global, then aliases, then plugins, and then completions in one structure. 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. 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. _bash_it_library_finalize_hook _bash_it_appearance_scm_init THEME_CHECK_SUDO theme/powerline: fix source path for theme base plugins/fuck: aliases Add themes/*.bash to lint Lint everything (add dirs to `clean_files.txt`) theme/atomic: lint/cleanup Use `[[` instead of `[`, set some local variables, still more to clean 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/bobby: SC2154 Handle all unbound parameters, even colors! theme/brainy: work-in-progress Handle all unbound parameters, even colors! theme/brunton: SC2154 Handle all unbound parameters, even colors! theme/candy: SC2154 Handle all unbound parameters, even colors! theme/easy: SC2154 Handle all unbound parameters, even colors! theme/modern: SC2154 Handle all unbound parameters, even colors! theme/essential: SC2154 Handle all unbound parameters, even colors! theme/atomic theme/brainy theme/binaryanomaly
- 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: fix `_command_exists()` The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`! lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit... 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: 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.) lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh issue 558 lib/helpers: unbound positional parameters lib/helpers: fix profile subcommand tests plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: fix tests This subshell is...wut lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: simplify some functions - add some `local` variables, - don't subshell `_typeset_functions`, lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: delete `_bash-it-determine-component-status-from-path()` Duplicate function of existing `_bash-it-component-item-is-enabled()`. lib/helpers: quotes for consistency Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too. lib/helpers: simplify some quote escapes 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. 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: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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/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/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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. BATS: enable strict mode 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` 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/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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh#558 lib/helpers: unbound positional parameters lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: local 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`. lib/log: `shellcheck` && `shfmt` Alsö, fix tests to load `lib/colors` instead of `lib/appearance`...wut Alsö, `short-circuit _has_colors()`: If we already looked up colors, and we already have them, then don't run `tput` again. My apologies to future `git blame` hunters ♥ lib/log: rename `_log_general()` ...to `_bash-it-log-message()`. alsö, add common log levels with common names. lib/log: function `_bash-it-log-prefix-by-path()` ...to replace `_set-prefix-based-on-path()` in `scripts/reloader`. Deliberately does not use `_bash-it-get-component-name-from-path()`/`_bash-it-get-component-type-from-path()` as we need some of the intermediate state and would have to reimplement anyway. 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. test: quote things 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_helper already loads `composure.sh` ...and `cite()`s metadata test: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. 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. lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()` 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.) plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/utilities: fix tests This subshell is...wut lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/command_duration: remove temporary files 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. lib/command_duration: consolidate functions 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 plugin/cmd-returned-notify: remove duplicate function Remove `_command_duration_pre_exec()` from plugin; just use the one from `lib/command_duration` lib/command_duration: move `theme/command_duration.theme` Rename the `theme/command_duration.theme` file as it's not really got anything to do with theming or SCM. lib/command_duration: adopt `_bash_it_library_finalize_hook` 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` 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/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/base: use `_bash-it-component-item-is-enabled()` plugin/man: simplify Don't overwrite variables that the user has already set. completion/git: use `_completion_exists()` plugins/man: unbound `$LESS` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. 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` reloader: just loop once Move the "global" `reloader.sh` invocation inside the loop to simplify control flow: load global, then aliases, then plugins, and then completions in one structure. 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. 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. _bash_it_library_finalize_hook _bash_it_appearance_scm_init THEME_CHECK_SUDO theme/powerline: fix source path for theme base plugins/fuck: aliases Add themes/*.bash to lint Lint everything (add dirs to `clean_files.txt`) theme/atomic: lint/cleanup Use `[[` instead of `[`, set some local variables, still more to clean 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/bobby: SC2154 Handle all unbound parameters, even colors! theme/brainy: work-in-progress Handle all unbound parameters, even colors! theme/brunton: SC2154 Handle all unbound parameters, even colors! theme/candy: SC2154 Handle all unbound parameters, even colors! theme/easy: SC2154 Handle all unbound parameters, even colors! theme/modern: SC2154 Handle all unbound parameters, even colors! theme/essential: SC2154 Handle all unbound parameters, even colors! theme/atomic theme/brainy theme/binaryanomaly
Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit...
- 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: fix `_command_exists()` The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`, `_completion_exists()`, and `_is_function()`! lib/helpers: first `shellcheck` pass Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR Bash-it#1865 from NoahGorny...and clean it a bit... 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: 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.) lib/helpers: fix `_bash-it-describe()` Use `_bash-it-component-item-is-enabled()` Fix SC2295 lib/helpers: be extra careful with word splitting Use curly braces when `$1` is unseparated from words in a string. lib/helpers: use `awk` to count lines instead of piping to `wc -l` Co-authored-by: Kostas Giapis <[email protected]> lib/helpers: remove weird non-globs Replace weird non-globs with array and loop, as suggested by `shellcheck`. Alsö, simplify several constructs to eliminate external binaries. Alsö, see mvdan/sh issue 558 lib/helpers: unbound positional parameters lib/helpers: fix profile subcommand tests lib/helpers: juse use `awk`, insteado of `grep | awk` lib/helpers: simplify some functions - add some `local` variables, - don't subshell `_typeset_functions`, lib/utilities: autonomize `_bash-it-component-item-is-enabled()` lib/helpers: delete `_bash-it-determine-component-status-from-path()` Duplicate function of existing `_bash-it-component-item-is-enabled()`. lib/helpers: quotes for consistency Quote some parameter uses that don't strictly require it, but since Bash needs so many quotes everywhere else my brain worms feel better when these are quoted too. lib/helpers: simplify some quote escapes 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/utilities: fix `_bash-it-component-help()` for long component names Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity. This fixes Bash-it#1978. 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()`.
A new Bash-it subcommand- bash-it profile!
Please note this is still a POC, but I would like some feedback on this as this is a big change.
Lemme know what you think @nwinkler @cornfeedhobo @davidpfarrell @tbhaxor
TODO:
Description
This PR adds a new subcommand, "profile", which enables users to load/save their configuration from config files.
This has great value, and will help users port bash-it into a new setup, and ease the installation process.
Motivation and Context
Motivated by #1825 (#1825 (comment))
Closes #1350
How Has This Been Tested?
Only locally, I plan to add some tests in the future
Screenshots (if appropriate):
I may add some in the future 😄
Types of changes
Checklist: