Skip to content

Commit

Permalink
lib/helpers: first shellcheck pass
Browse files Browse the repository at this point in the history
Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c.

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

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

Use `[[` for conditional evaluation.

lib/helpers: fix `_command_exists()`

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

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

lib/helpers: second `shellcheck` pass

lib/helpers: lint `_bash-it-migrate()`

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

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

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

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

lib/helpers: some SC2034 fixes

And SC2154 in `_make_reload_alias()`

lib/helpers: lint `all_groups()`

lib/helpers: `shfmt`

My apologies to future `git blame` hunters ♥

lib/helpers: fix `all_groups()`

- Don't write to disk, just pipe.
- Don't loop, just do all functions.

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

Performance of new implementation on my system:
```
real    0m0.052s
user    0m0.069s
sys     0m0.025s
```

lib/helpers: cleanup

- Improve `pushd`/`popd` somewhat
- local some parameters
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
- remove `compgen` from `_bash-it-describe()`

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

plugins/go: update tests

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

plugins/ruby: update tests

Account for non-existing directory not added to path.

plugins/ruby: tests on Mac OS X

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

lib/search: code style cleanup

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

lib/search: `shellcheck`

SC2076
SC2091
SC2004
SC2086
SC2207

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

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

lib/search: fix SC2154

lib/search: adjust spacing on test assertions

lib/search: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: shellcheck

lib/log: use builtin [[ for test evaluation

lib/log: `shfmt`

My apologies to future `git blame` hunters ♥

lib/log: short-circuit _has_colors()

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

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

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

reloader: `shellcheck` && `shfmt`

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

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

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

My apologies to future `git blame` hunters ♥

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

uninstall: `shellcheck` && `shfmt`

lint: add lib to clean_files.txt

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

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

lib/utilities: XDG_CACHE_HOME

Use $XDG_CACHE_HOME environment constant instead of placing a tmp/cache folder inside the bash-it data repo. If not defined, fall back to current behavior.

plugins/dirs: use XDG_STATE_HOME

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

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

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

My apologies to future `git blame` hunters ♥

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

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

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

My apologies to future `git blame` hunters ♥

lib/p4helpers: `shfmt`

My apologies to future `git blame` hunters ♥

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

My apologies to future `git blame` hunters ♥

Add themes/*.bash to lint

lib: move generic helper functions to helpers.bash

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

lib/helpers: add preexec functions

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

lib/command_duration

Remove use of temporary files.

lib/command_duration: first pass at logging

lib/command_duration: dynamic clock hand

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

Expressly handle COMMAND_DURATION_COLOR as blank when undefined.

lib/command_duration: Refactor using `$EPOCHREALTIME`

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

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

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

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

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

Change variable names to match lib/command-duration

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

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

tests: handle nanoseconds

lib/command_duration: `shfmt`

My apologies to future `git blame` hungers ♥

plugins/proxy: use `_command_exists`

Addresses Bash-it#1632

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

completions/sqlmap: use `_command_exists`

Addresses Bash-it#1632

completion/fabric: no need for `_command_exists`

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

plugins/java: quote path

plugins/jekyll: simplify command flow

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

plugins/latex: 2009 was 12 years ago

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

plugins/osx-timemachine: code style cleanups

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

plugins/osx: code style improvements #TODO #TODO

Avoid external binaries

plugins/python: code style improvements

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

plugins/osx: unbound PROMPT_COMMAND

Expressly handle undefined PROMPT_COMMAND as empty

plugins/osx: dead code removal

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

plugins/osx: unbound PROMPT_COMMAND

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

completion/system: accomodate multiple versions

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

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

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

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

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

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

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

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

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

aliases/general: minor fixes

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

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

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

plugins/git: use `type -p`

completion/grunt: shellcheck

completion/subversion: load system completion

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

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

plugins/battery: lint

plugins/xterm: not just Xterm

completion/system: load earlier than other completions

plugin/projects: cleanup

plugins/thefuck: lint

plugins/todo: lint

plugin/man: simplify

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

completion/git: use `_completion_exists()`

plugin/base: SC2144

globs literally don't work. At all.

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

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

My apologies to future `git blame` hunters ♥

lint: add lib and scripts to clean_files.txt

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

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

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

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

See Bash-it#1595 for discussion.

lib/helpers: new function `_find_uncle()`

New function to do a search looking for a sibling to a parent of the current directory, for example to find `../../.git` to indicate that `$PWD` is inside a git repository.

main: lint false positive

style consistency improvements

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

Reduce environmental pollution

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

lib: avoid duplicate inclusion

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

lint defaults and base

No need for `cat`

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

main: add some debugging

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

main: move Jekyll stuff to plugins/jekyll

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

lib/utilities: s/defined/loaded

lib/helpers: define `pathmunge()` unconditionally

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

lib/helpers: fix `_command_exists()`

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

Ditto `_binary_exists()`.
  • Loading branch information
gaelicWizard committed Feb 9, 2022
1 parent af2c680 commit f263c34
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ binary_next_line = true # like -bn
switch_case_indent = true # like -ci
space_redirects = true # like -sr
keep_padding = false # like -kp
function_next_line = true # like -fn
#function_next_line = true # like -fn
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
7 changes: 7 additions & 0 deletions lib/utilities.bash
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ function _bash-it-get-component-type-from-path() {
echo "${filename}"
}

function _set-prefix-based-on-path() {
filename=$(_bash-it-get-component-name-from-path "$1")
extension=$(_bash-it-get-component-type-from-path "$1")
# shellcheck disable=SC2034 # expected
BASH_IT_LOG_PREFIX="$extension: $filename"
}

# This function searches an array for an exact match against the term passed
# as the first argument to the function. This function exits as soon as
# a match is found.
Expand Down
Empty file modified themes/githelpers.theme.bash
100644 → 100755
Empty file.

0 comments on commit f263c34

Please sign in to comment.