-
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
Plugins: bail early with descriptive messages #2062
Draft
gaelicWizard
wants to merge
6
commits into
Bash-it:master
Choose a base branch
from
gaelicWizard:plugins-bail
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d813d2
plugins: clear and consistent log messages
gaelicWizard 37c79b8
plugin/fzf: `shellcheck`
gaelicWizard 3573275
plugin/gitstatus: `shellcheck`
gaelicWizard 2e143cf
plugins/go: simplify _bash-it-gopath-pathmunge()
gaelicWizard 5dc6658
plugin/nvm: fix homebrew path
gaelicWizard e517201
Merge branch 'master' into plugins-bail
seefood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
cite about-plugin | ||
# shellcheck shell=bash | ||
about-plugin 'Simplify `curl cht.sh/<query>` to `cht.sh <query>`' | ||
|
||
# Play nicely if user already installed cht.sh cli tool | ||
if ! _command_exists cht.sh ; then | ||
function cht.sh () { | ||
about 'Executes a cht.sh curl query using the provided arguments' | ||
param ' [ ( topic [sub-topic] ) | ~keyword ] [ :list | :help | :learn ]' | ||
example '$ cht.sh :help' | ||
example '$ cht.sh :list' | ||
example '$ cht.sh tar' | ||
example '$ cht.sh js "parse json"' | ||
example '$ cht.sh python :learn' | ||
example '$ cht.sh rust :list' | ||
group 'cht-sh' | ||
|
||
# Separate arguments with '/', preserving spaces within them | ||
local query=$(IFS=/ ; echo "$*") | ||
curl "cht.sh/${query}" | ||
} | ||
if _binary_exists cht.sh ; then | ||
_log_warning "You have already installed 'cht.sh', so it's safe to disable this plugin." | ||
return 1 | ||
fi | ||
|
||
function cht.sh () { | ||
about 'Executes a cht.sh curl query using the provided arguments' | ||
param ' [ ( topic [sub-topic] ) | ~keyword ] [ :list | :help | :learn ]' | ||
example '$ cht.sh :help' | ||
example '$ cht.sh :list' | ||
example '$ cht.sh tar' | ||
example '$ cht.sh js "parse json"' | ||
example '$ cht.sh python :learn' | ||
example '$ cht.sh rust :list' | ||
group 'cht-sh' | ||
|
||
# Separate arguments with '/', preserving spaces within them | ||
local query | ||
query=$(IFS=/ ; echo "$*") | ||
curl "cht.sh/${query}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# shellcheck shell=bash | ||
cite about-plugin | ||
about-plugin 'load direnv, if you are using it: https://direnv.net/' | ||
|
||
if _command_exists direnv; then | ||
eval "$(direnv hook bash)" | ||
if ! _binary_exists direnv; then | ||
_log_warning "Could not find 'direnv'." | ||
return 1 | ||
fi | ||
|
||
# shellcheck disable=SC1090 | ||
source < <(direnv hook bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
cite about-plugin | ||
# shellcheck shell=bash | ||
about-plugin 'load fasd, if you are using it' | ||
|
||
_command_exists fasd || return | ||
if ! _binary_exists fasd; then | ||
_log_warning "Unable to locage 'fasd'." | ||
return 1 | ||
fi | ||
|
||
eval "$(fasd --init auto)" | ||
# shellcheck disable=SC1090 | ||
source < <(fasd --init auto) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
# Load after the system completion to make sure that the fzf completions are working | ||
# BASH_IT_LOAD_PRIORITY: 375 | ||
|
||
cite about-plugin | ||
# shellcheck shell=bash | ||
about-plugin 'load fzf, if you are using it' | ||
|
||
if [ -r ~/.fzf.bash ] ; then | ||
source ~/.fzf.bash | ||
elif [ -r "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ] ; then | ||
source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash | ||
# shellcheck source-path=$HOME source-path=$HOME/.config/fzf disable=SC1090 disable=SC1091 | ||
if [[ -r ~/.fzf.bash ]]; then | ||
source ~/.fzf.bash | ||
elif [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf.bash" ]]; then | ||
source "${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf.bash" | ||
fi | ||
|
||
# No need to continue if the command is not present | ||
_command_exists fzf || return | ||
if ! _binary_exists fzf; then | ||
_log_warning "unable to initialize without '$_' installed." | ||
return 1 | ||
fi | ||
|
||
if [ -z ${FZF_DEFAULT_COMMAND+x} ] && _command_exists fd ; then | ||
export FZF_DEFAULT_COMMAND='fd --type f' | ||
if [[ -z ${FZF_DEFAULT_COMMAND+x} ]] && _command_exists fd; then | ||
export FZF_DEFAULT_COMMAND='fd --type f' | ||
fi | ||
|
||
fe() { | ||
about "Open the selected file in the default editor" | ||
group "fzf" | ||
param "1: Search term" | ||
example "fe foo" | ||
function fe() { | ||
about "Open the selected file in the default editor" | ||
group "fzf" | ||
param "1: Search term" | ||
example "fe foo" | ||
|
||
local IFS=$'\n' | ||
local files | ||
files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0)) | ||
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}" | ||
local IFS=$'\n' | ||
local files | ||
read -ra files < <(fzf-tmux --query="$1" --multi --select-1 --exit-0) | ||
[[ -n "${files[*]}" ]] && "${EDITOR:-${ALTERNATE_EDITOR:-nano}}" "${files[@]}" | ||
} | ||
|
||
fcd() { | ||
about "cd to the selected directory" | ||
group "fzf" | ||
param "1: Directory to browse, or . if omitted" | ||
example "fcd aliases" | ||
function fcd() { | ||
about "cd to the selected directory" | ||
group "fzf" | ||
param "1: Directory to browse, or . if omitted" | ||
example "fcd aliases" | ||
|
||
local dir | ||
dir=$(find ${1:-.} -path '*/\.*' -prune \ | ||
-o -type d -print 2> /dev/null | fzf +m) && | ||
cd "$dir" | ||
local dir | ||
dir=$(find "${1:-.}" -path '*/\.*' -prune \ | ||
-o -type d -print 2> /dev/null | fzf +m) \ | ||
&& cd "$dir" || return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,36 @@ | ||
cite about-plugin | ||
# shellcheck shell=bash | ||
about-plugin 'speeds up your life by using gitstatus for git status calculations. install from https://github.com/romkatv/gitstatus' | ||
|
||
: "${SCM_GIT_GITSTATUS_DIR:="$HOME/gitstatus"}" | ||
if [[ ! -d "${SCM_GIT_GITSTATUS_DIR}" ]] && _bash_it_homebrew_check; then | ||
SCM_GIT_GITSTATUS_DIR="${BASH_IT_HOMEBREW_PREFIX?}/opt/gitstatus" | ||
fi | ||
|
||
function gitstatus_on_disable() { | ||
about 'Destructor of gitstatus plugin' | ||
group 'gitstatus' | ||
about 'Destructor of gitstatus plugin' | ||
group 'gitstatus' | ||
|
||
unset SCM_GIT_USE_GITSTATUS | ||
_command_exists gitstatus_stop && gitstatus_stop | ||
unset SCM_GIT_USE_GITSTATUS | ||
_command_exists gitstatus_stop && gitstatus_stop | ||
} | ||
|
||
# No scm-check | ||
[[ $SCM_CHECK == "true" ]] || return | ||
function _bash-it-component-plugin-callback-on-init-gitstatus() { | ||
# No scm-check | ||
[[ ${SCM_CHECK?} == "true" ]] || return | ||
|
||
# non-interactive shell | ||
[[ $- == *i* ]] || return | ||
# non-interactive shell | ||
[[ $- == *i* ]] || return | ||
|
||
: "${SCM_GIT_GITSTATUS_DIR:="$HOME/gitstatus"}" | ||
if [[ -d ${SCM_GIT_GITSTATUS_DIR} ]]; then | ||
source "${SCM_GIT_GITSTATUS_DIR}/gitstatus.plugin.sh" | ||
# Start the actual gitstatus binary | ||
gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 | ||
export SCM_GIT_USE_GITSTATUS=true | ||
else | ||
_log_warning "Could not find gitstatus directory in ${SCM_GIT_GITSTATUS_DIR}. Please specify directory location using SCM_GIT_GITSTATUS_DIR." | ||
fi | ||
if [[ -d "${SCM_GIT_GITSTATUS_DIR?}" ]]; then | ||
# shellcheck source-path=$HOME/gitstatus disable=SC1091 | ||
source "${SCM_GIT_GITSTATUS_DIR}/gitstatus.plugin.sh" | ||
# Start the actual gitstatus binary | ||
gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 | ||
export SCM_GIT_USE_GITSTATUS=true | ||
else | ||
_log_warning "Could not find gitstatus directory in ${SCM_GIT_GITSTATUS_DIR}. Please specify directory location using SCM_GIT_GITSTATUS_DIR." | ||
return 1 | ||
fi | ||
} | ||
|
||
_bash-it-component-plugin-callback-on-init-gitstatus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
# shellcheck shell=bash | ||
cite about-plugin | ||
about-plugin 'go environment variables & path configuration' | ||
|
||
# Load after basher and goenv | ||
# BASH_IT_LOAD_PRIORITY: 270 | ||
|
||
# Test `go version` because goenv creates shim scripts that will be found in PATH | ||
# but do not always resolve to a working install. | ||
{ _command_exists go && go version &> /dev/null; } || return 0 | ||
if ! _binary_exists go || ! go version &> /dev/null; then | ||
_log_warning "Unable to locate a working 'go'." | ||
return 1 | ||
fi | ||
|
||
export GOROOT="${GOROOT:-$(go env GOROOT)}" | ||
export GOPATH="${GOPATH:-$(go env GOPATH)}" | ||
: "${GOROOT:=$(go env GOROOT)}" | ||
: "${GOPATH:=$(go env GOPATH)}" | ||
export GOROOT GOPATH | ||
|
||
# $GOPATH/bin is the default location for binaries. Because GOPATH accepts a list of paths and each | ||
# might be managed differently, we add each path's /bin folder to PATH using pathmunge, | ||
# while preserving ordering. | ||
# e.g. GOPATH=foo:bar -> PATH=foo/bin:bar/bin | ||
_bash-it-gopath-pathmunge() { | ||
function _bash-it-component-plugin-callback-on-init-go() { | ||
_about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended' | ||
_group 'go' | ||
if [[ -z $GOPATH ]]; then | ||
echo 'GOPATH empty' >&2 | ||
if [[ -z "${GOPATH:-}" ]]; then | ||
_log_warning 'GOPATH empty' | ||
return 1 | ||
fi | ||
local paths i | ||
local paths apath | ||
IFS=: read -r -a paths <<< "$GOPATH" | ||
i=${#paths[@]} | ||
while [[ $i -gt 0 ]]; do | ||
i=$((i - 1)) | ||
if [[ -n "${paths[i]}" ]]; then | ||
pathmunge "${paths[i]}/bin" | ||
fi | ||
for apath in "${paths[@]}"; do | ||
pathmunge "${apath}/bin" || true | ||
done | ||
} | ||
_bash-it-gopath-pathmunge | ||
_bash-it-component-plugin-callback-on-init-go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
# shellcheck shell=bash | ||
cite about-plugin | ||
about-plugin 'load hub, if you are using it' | ||
|
||
if _command_exists hub; then | ||
eval "$(hub alias -s)" | ||
if ! _binary_exists hub; then | ||
_log_warning "Unable to locate 'hub'." | ||
return 1 | ||
fi | ||
|
||
source < <(hub alias -s) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont you want to keep it?