From b84983331aa89bfb525cc4cdd65a90b280b8b9b2 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 26 Jan 2022 11:14:59 -0800 Subject: [PATCH] lib/search: code style cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Couldn't even `shellcheck` until I did a first pass...too much noise! ♥ lib/search: `shellcheck` SC2076 SC2091 SC2004 SC2086 SC2207 lib/search: fix `_bash-it-flash-term()` 1. `$text_black` isn't a parameter provided by _Bash It_. Typo? 2. `$bold_yellow` is meant for prompt strings and putputs `\[`; ditto `$bold_red`. 3. The color was never returned to normal after. lib/search: fix usage statement `_bash-it-search()` SC2154 lib/search: `shfmt` My apologies to future `git blame` hunters ♥ lib/search: code cleanup Improve `_bash-it-erase-term()`, `_bash-it-flash-term()`, `_bash-it-rewind()`, `_bash-it-search-result()`, and `_bash-it-search-component()`. Minor tweaks to `_bash-it-is-partial-match()`, and `_bash-it-search()`. pathmunge tests main: Glob for *.bash properly when path contains spaces - `shfmt`, `shellcheck` - Clean up legacy/compatibility code to simpler control flow - Move theme stuff down to where themes are handled - Don't use `**` as _Bash It_ has never before set `globstar`; this eliminates varying behavior by environment; this alsö fixes users having any not-enabled themes under their custom dir. - Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.) - Place `composure.sh` init all in one place main: adopt `_bash-it-log-prefix-by-path()` lib/reloader: adopt `_bash-it-log-prefix-by-path()` lib/appearance: `shellcheck` && `shfmt` reloader: `shellcheck` && `shfmt` Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace. lib/preview: `shfmt` && `shellcheck` Fix theme file path globbing when $BASH_IT contains any spaces. My apologies to future `git blame` hunters ♥ uninstall: `shellcheck` && `shfmt` lint: add lib to clean_files.txt lib/theme: `shfmt` && `shellcheck` My apologies to future `git blame` hunters ♥ lib/colors: `shellcheck` && `shfmt` Alsö, clean up `__color_rgb` to just use a regular if block. lib/p4helpers: `shfmt` My apologies to future `git blame` hunters ♥ lib/githelpers: `shfmt` && `shellcheck` My apologies to future `git blame` hunters ♥ lib/theme: don't redefine battery_char() Combine the two definitions for `battery_char()` so the second one doesn't just overwrite the first one. Do one or the other, not both. Don't evaluate if `battery_percentage()` is available at load time, evaluate it at run time. lib/command_duration: `shfmt` && `shellcheck` My apologies to future `git blame` hunters ♥ lib/theme: `shellcheck` SC2154 These variables are referenced by themes already linted. lib/theme.githelpers: unbound varbl lib/theme: don't use `date` for `$THEME_CLOCK_FORMAT` main: simplify flow of lib loader loop Eliminate the separate loop for `vendor/init.d` since it's just as easy to glob it in the `lib` loop. lib: delete `appearance.bash` This adds *three* lines to `bash_it.sh`, and two to `plugin/base`. Just not worth an extra file requiring special handling. main: load custom theme Allow for simpler directory strucutre when loading theme from `$CUSTOM_THEME_DIR`/`$BASH_IT_CUSTOM` make aliases load very late ...and update all the tests... preexec: add helper functions to loader Define the helper functions for `bash-preexec.sh` immediately after importing it, rather than in `lib/theme`. - `__check_precmd_conflict()` and `save_append_prompt_command()` are generally useful and not theme-specific. - Add matching `__check_preexec_conflict()` like `__check_precmd_conflict()`, and alsö `safe_append_preexec()`. preexec: work around upstream Alsö, move `set +T` in here. test/theme: make fewer assumptions Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉 That said, we do want to verify that the function was actually loaded. TODO: actually test the function. install: use `.bashrc` and notify user The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`. completions/sqlmap: use `_command_exists` Addresses bash-it/bash-it#1632 completion/fabric: no need for `_command_exists` If we're already inside the completion handler for `fab`...then it's a bit silly to check if `fab` is installed. plugins/go: simplify _bash-it-gopath-pathmunge() plugin/history: no need to set a trap Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function. Also, set the defaults in a way that is happy with read-only parameters. aliases/general: minor fixes - Don't define some aliases if the target isn't installed, use _command_exists to check instead of `type` and `which`. - Use `$EDITOR` for the editor for aliases about editing, excep the `sudo` ones because maybe you want those specifically? - Fix `ls` aliases to match their common definitions (-A instead of -a: don't show '.' and '..' when displaying hidden files). themes/base: use `type -P` instead of `which` Avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot. completion/grunt: shellcheck completion/subversion: load system completion Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it/bash-it#1818. NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically. plugins/battery: lint plugins/xterm: not just Xterm plugins/thefuck: lint plugins/todo: lint plugin/base: use `_bash-it-component-item-is-enabled()` completion/git: use `_completion_exists()` plugins/alias: remove old `SC2154` flag This is no logner needed because the `local` keyword was moved higher up in the function. --- clean_files.txt | 1 + completion/available/git.completion.bash | 2 +- plugins/available/thefuck.plugin.bash | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 4cb8bfc1db..0d4d2323b8 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -125,6 +125,7 @@ plugins/available/python.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/ruby.plugin.bash plugins/available/textmate.plugin.bash +plugins/available/thefuck.plugin.bash plugins/available/todo.plugin.bash plugins/available/xterm.plugin.bash plugins/available/zoxide.plugin.bash diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash index 31b77fa3de..37b3668adf 100644 --- a/completion/available/git.completion.bash +++ b/completion/available/git.completion.bash @@ -6,7 +6,7 @@ _command_exists git || return # Don't handle completion if it's already managed -if complete -p git &> /dev/null; then +if _completion_exists git; then _log_warning "completion already loaded - this usually means it is safe to stop using this completion" return 0 fi diff --git a/plugins/available/thefuck.plugin.bash b/plugins/available/thefuck.plugin.bash index 242a77df22..3c3f096ecc 100644 --- a/plugins/available/thefuck.plugin.bash +++ b/plugins/available/thefuck.plugin.bash @@ -1,9 +1,10 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Initialization for fuck' # https://github.com/nvbn/thefuck if _command_exists thefuck; then - # shellcheck disable=SC2046 - eval $(thefuck --alias) + # shellcheck disable=SC2046 + eval "$(thefuck --alias)" fi