Skip to content

Commit 8609f5c

Browse files
committed
plugins: clear and consistent log messages
1 parent 2575d64 commit 8609f5c

22 files changed

+207
-160
lines changed

clean_files.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,13 @@ plugins/available/autojump.plugin.bash
9191
plugins/available/base.plugin.bash
9292
plugins/available/basher.plugin.bash
9393
plugins/available/blesh.plugin.bash
94+
plugins/available/cht.sh.plugin.bash
9495
plugins/available/cmd-returned-notify.plugin.bash
9596
plugins/available/direnv.plugin.bash
9697
plugins/available/dirs.plugin.bash
9798
plugins/available/docker-machine.plugin.bash
99+
plugins/available/fasd.plugin.bash
100+
plugins/available/fzf.plugin.bash
98101
plugins/available/gif.plugin.bash
99102
plugins/available/git-subrepo.plugin.bash
100103
plugins/available/git.plugin.bash
@@ -107,24 +110,28 @@ plugins/available/history.plugin.bash
107110
plugins/available/hub.plugin.bash
108111
plugins/available/java.plugin.bash
109112
plugins/available/jekyll.plugin.bash
113+
plugins/available/jenv.plugin.bash
110114
plugins/available/jump.plugin.bash
111115
plugins/available/latex.plugin.bash
112116
plugins/available/less-pretty-cat.plugin.bash
113117
plugins/available/man.plugin.bash
114118
plugins/available/nginx.plugin.bash
115119
plugins/available/node.plugin.bash
116120
plugins/available/nodenv.plugin.bash
121+
plugins/available/nvm.plugin.bash
117122
plugins/available/osx-timemachine.plugin.bash
118123
plugins/available/osx.plugin.bash
119124
plugins/available/percol.plugin.bash
120125
plugins/available/plenv.plugin.bash
126+
plugins/available/powerline.plugin.bash
121127
plugins/available/projects.plugin.bash
122128
plugins/available/proxy.plugin.bash
123129
plugins/available/pyenv.plugin.bash
124130
plugins/available/python.plugin.bash
125131
plugins/available/rbenv.plugin.bash
126132
plugins/available/ruby.plugin.bash
127133
plugins/available/textmate.plugin.bash
134+
plugins/available/thefuck.plugin.bash
128135
plugins/available/todo.plugin.bash
129136
plugins/available/xterm.plugin.bash
130137
plugins/available/zoxide.plugin.bash

plugins/available/cht-sh.plugin.bash

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
cite about-plugin
1+
# shellcheck shell=bash
22
about-plugin 'Simplify `curl cht.sh/<query>` to `cht.sh <query>`'
33

44
# Play nicely if user already installed cht.sh cli tool
5-
if ! _command_exists cht.sh ; then
6-
function cht.sh () {
7-
about 'Executes a cht.sh curl query using the provided arguments'
8-
param ' [ ( topic [sub-topic] ) | ~keyword ] [ :list | :help | :learn ]'
9-
example '$ cht.sh :help'
10-
example '$ cht.sh :list'
11-
example '$ cht.sh tar'
12-
example '$ cht.sh js "parse json"'
13-
example '$ cht.sh python :learn'
14-
example '$ cht.sh rust :list'
15-
group 'cht-sh'
16-
17-
# Separate arguments with '/', preserving spaces within them
18-
local query=$(IFS=/ ; echo "$*")
19-
curl "cht.sh/${query}"
20-
}
5+
if _binary_exists cht.sh ; then
6+
_log_warning "You have already installed `cht.sh`, so it's safe to disable this plugin."
7+
return 1
218
fi
9+
10+
function cht.sh () {
11+
about 'Executes a cht.sh curl query using the provided arguments'
12+
param ' [ ( topic [sub-topic] ) | ~keyword ] [ :list | :help | :learn ]'
13+
example '$ cht.sh :help'
14+
example '$ cht.sh :list'
15+
example '$ cht.sh tar'
16+
example '$ cht.sh js "parse json"'
17+
example '$ cht.sh python :learn'
18+
example '$ cht.sh rust :list'
19+
group 'cht-sh'
20+
21+
# Separate arguments with '/', preserving spaces within them
22+
local query
23+
query=$(IFS=/ ; echo "$*")
24+
curl "cht.sh/${query}"
25+
}

plugins/available/direnv.plugin.bash

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'load direnv, if you are using it: https://direnv.net/'
43

5-
if _command_exists direnv; then
6-
eval "$(direnv hook bash)"
4+
if ! _binary_exists direnv; then
5+
_log_warning "Could not find 'direnv'."
6+
return 1
77
fi
8+
9+
# shellcheck disable=SC1090
10+
source < <(direnv hook bash)

plugins/available/fasd.plugin.bash

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
cite about-plugin
1+
# shellcheck shell=bash
22
about-plugin 'load fasd, if you are using it'
33

4-
_command_exists fasd || return
4+
if ! _binary_exists fasd; then
5+
_log_warning "Unable to locage 'fasd'."
6+
return 1
7+
fi
58

6-
eval "$(fasd --init auto)"
9+
# shellcheck disable=SC1090
10+
source < <(fasd --init auto)

plugins/available/fzf.plugin.bash

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
1-
# Load after the system completion to make sure that the fzf completions are working
2-
# BASH_IT_LOAD_PRIORITY: 375
3-
4-
cite about-plugin
1+
# shellcheck shell=bash
52
about-plugin 'load fzf, if you are using it'
63

7-
if [ -r ~/.fzf.bash ] ; then
8-
source ~/.fzf.bash
9-
elif [ -r "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ] ; then
10-
source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash
4+
# shellcheck source-path=$HOME source-path=$HOME/.config/fzf disable=SC1090 disable=SC1091
5+
if [[ -r ~/.fzf.bash ]]; then
6+
source ~/.fzf.bash
7+
elif [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf.bash" ]]; then
8+
source "${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf.bash"
119
fi
1210

1311
# No need to continue if the command is not present
14-
_command_exists fzf || return
12+
if ! _binary_exists fzf; then
13+
_log_warning "${BASH_SOURCE[0]##*/}: unable to initialize without '$_' installed."
14+
return 1
15+
fi
1516

16-
if [ -z ${FZF_DEFAULT_COMMAND+x} ] && _command_exists fd ; then
17-
export FZF_DEFAULT_COMMAND='fd --type f'
17+
if [[ -z ${FZF_DEFAULT_COMMAND+x} ]] && _command_exists fd; then
18+
export FZF_DEFAULT_COMMAND='fd --type f'
1819
fi
1920

20-
fe() {
21-
about "Open the selected file in the default editor"
22-
group "fzf"
23-
param "1: Search term"
24-
example "fe foo"
21+
function fe() {
22+
about "Open the selected file in the default editor"
23+
group "fzf"
24+
param "1: Search term"
25+
example "fe foo"
2526

26-
local IFS=$'\n'
27-
local files
28-
files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
29-
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
27+
local IFS=$'\n'
28+
local files
29+
IFS=$'\n' read -ra files < <(fzf-tmux --query="$1" --multi --select-1 --exit-0)
30+
[[ -n "${files[*]}" ]] && "${EDITOR:-${ALTERNATE_EDITOR:-nano}}" "${files[@]}"
3031
}
3132

32-
fcd() {
33-
about "cd to the selected directory"
34-
group "fzf"
35-
param "1: Directory to browse, or . if omitted"
36-
example "fcd aliases"
33+
function fcd() {
34+
about "cd to the selected directory"
35+
group "fzf"
36+
param "1: Directory to browse, or . if omitted"
37+
example "fcd aliases"
3738

38-
local dir
39-
dir=$(find ${1:-.} -path '*/\.*' -prune \
40-
-o -type d -print 2> /dev/null | fzf +m) &&
41-
cd "$dir"
39+
local dir
40+
dir=$(find "${1:-.}" -path '*/\.*' -prune \
41+
-o -type d -print 2> /dev/null | fzf +m) \
42+
&& cd "$dir" || return
4243
}

plugins/available/go.plugin.bash

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'go environment variables & path configuration'
43

54
# Load after basher and goenv
65
# BASH_IT_LOAD_PRIORITY: 270
76

87
# Test `go version` because goenv creates shim scripts that will be found in PATH
98
# but do not always resolve to a working install.
10-
{ _command_exists go && go version &> /dev/null; } || return 0
9+
if ! _binary_exists go || ! go version &> /dev/null; then
10+
_log_warning "Unable to locate a working 'go'."
11+
return 1
12+
fi
1113

1214
export GOROOT="${GOROOT:-$(go env GOROOT)}"
1315
export GOPATH="${GOPATH:-$(go env GOPATH)}"
@@ -16,7 +18,7 @@ export GOPATH="${GOPATH:-$(go env GOPATH)}"
1618
# might be managed differently, we add each path's /bin folder to PATH using pathmunge,
1719
# while preserving ordering.
1820
# e.g. GOPATH=foo:bar -> PATH=foo/bin:bar/bin
19-
_bash-it-gopath-pathmunge() {
21+
function _bash-it-gopath-pathmunge() {
2022
_about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended'
2123
_group 'go'
2224
if [[ -z $GOPATH ]]; then
@@ -29,7 +31,7 @@ _bash-it-gopath-pathmunge() {
2931
while [[ $i -gt 0 ]]; do
3032
i=$((i - 1))
3133
if [[ -n "${paths[i]}" ]]; then
32-
pathmunge "${paths[i]}/bin"
34+
pathmunge "${paths[i]}/bin" || true # ignore failures
3335
fi
3436
done
3537
}

plugins/available/goenv.plugin.bash

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'load goenv, if you are using it'
43

54
# https://github.com/syndbg/goenv
@@ -11,29 +10,31 @@ about-plugin 'load goenv, if you are using it'
1110
# - Check if in $PATH already
1211
# - Check if installed manually to $GOENV_ROOT
1312
# - Check if installed manually to $HOME
14-
_command_exists goenv \
15-
|| [[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] \
16-
|| [[ -x "$HOME/.goenv/bin/goenv" ]] \
17-
|| return 0
13+
if ! _binary_exists goenv || ! [[ -n "${GOENV_ROOT:-}" && -x "$GOENV_ROOT/bin/goenv" ]] || ! [[ -x "$HOME/.goenv/bin/goenv" ]]; then
14+
_log_warning "Unable to locate 'goenv'."
15+
return 1
16+
fi
1817

1918
# Set GOENV_ROOT, if not already set
20-
export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}"
19+
: "${GOENV_ROOT:=$HOME/.goenv}"
20+
export GOENV_ROOT
2121

2222
# Add GOENV_ROOT/bin to PATH, if that's where it's installed
2323
if ! _command_exists goenv && [[ -x "$GOENV_ROOT/bin/goenv" ]]; then
2424
pathmunge "$GOENV_ROOT/bin"
2525
fi
2626

27-
# Initialize goenv
28-
eval "$(goenv init - bash)"
27+
# shellcheck disable=SC1090 # Initialize goenv
28+
source < <(goenv init - bash)
2929

3030
# If moving to a directory with a goenv version set, reload the shell
3131
# to ensure the shell environment matches expectations.
32-
_bash-it-goenv-preexec() {
32+
function _bash-it-goenv-preexec() {
3333
GOENV_OLD_VERSION="$(goenv version-name)"
3434
}
35-
_bash-it-goenv-precmd() {
36-
if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then
35+
36+
function _bash-it-goenv-precmd() {
37+
if [[ -n "${GOENV_OLD_VERSION:-}" ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then
3738
exec env -u PATH -u GOROOT -u GOPATH -u GOENV_OLD_VERSION "${0/-/}" --login
3839
fi
3940
unset GOENV_OLD_VERSION

plugins/available/hub.plugin.bash

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'load hub, if you are using it'
43

5-
if _command_exists hub; then
6-
eval "$(hub alias -s)"
4+
if ! _binary_exists hub; then
5+
_log_warning "Unable to locate 'hub'."
6+
return 1
77
fi
8+
9+
source < <(hub alias -s)

plugins/available/jenv.plugin.bash

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
cite about-plugin
1+
# shellcheck shell=bash
22
about-plugin 'load jenv, if you are using it'
33

44
# Don't modify the environment if we can't find the tool:
55
# - Check if in $PATH already
66
# - Check if installed manually to $JENV_ROOT
77
# - Check if installed manually to $HOME
8-
_command_exists jenv ||
9-
[[ -n "$JENV_ROOT" && -x "$JENV_ROOT/bin/jenv" ]] ||
10-
[[ -x "$HOME/.jenv/bin/jenv" ]] ||
11-
return
8+
if ! _binary_exists jenv && ! [[ -n "${JENV_ROOT:-}" && -x "$JENV_ROOT/bin/jenv" ]] && ! [[ -x "$HOME/.jenv/bin/jenv" ]]; then
9+
_log_warning "Unable to locate 'jenv'."
10+
return 1
11+
fi
1212

1313
# Set JENV_ROOT, if not already set
14-
export JENV_ROOT="${JENV_ROOT:-$HOME/.jenv}"
14+
: "${JENV_ROOT:=$HOME/.jenv}"
15+
export JENV_ROOT
1516

1617
# Add JENV_ROOT/bin to PATH, if that's where it's installed
17-
! _command_exists jenv &&
18-
[[ -x "$JENV_ROOT/bin/jenv" ]] &&
19-
pathmunge "$JENV_ROOT/bin"
18+
if ! _command_exists jenv && [[ -x "$JENV_ROOT/bin/jenv" ]]; then
19+
pathmunge "$JENV_ROOT/bin"
20+
fi
2021

21-
# Initialize jenv
22-
eval "$(jenv init - bash)"
22+
# shellcheck disable=SC1090 # Initialize jenv
23+
source < <(jenv init - bash)

plugins/available/less-pretty-cat.plugin.bash

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'pygmentize instead of cat to terminal if possible'
43

5-
_command_exists pygmentize || return
4+
if ! _binary_exists pygmentize; then
5+
_log_warning "${BASH_SOURCE[0]##*/}: unable to initialize without '$_' installed."
6+
return 1
7+
fi
68

79
# pigmentize cat and less outputs - call them ccat and cless to avoid that
810
# especially cat'ed output in scripts gets mangled with pygemtized meta characters

plugins/available/node.plugin.bash

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'Node.js helper functions'
43

54
# Check that we have npm
6-
_command_exists npm || return
5+
if ! _binary_exists npm; then
6+
_log_warning "Unable to locage 'npm'."
7+
return 1
8+
fi
79

810
# Ensure local modules are preferred in PATH
911
pathmunge "./node_modules/.bin" "after"
1012

1113
# If not using nodenv, ensure global modules are in PATH
12-
if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then
14+
if [[ "$(type -p npm)" != *"nodenv/shims"* ]]; then
1315
pathmunge "$(npm config get prefix)/bin" "after"
1416
fi

plugins/available/nodenv.plugin.bash

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'load nodenv, if you are using it'
43

5-
export NODENV_ROOT="$HOME/.nodenv"
6-
pathmunge "$NODENV_ROOT/bin"
4+
if [[ -d "${NODENV_ROOT:=$HOME/.nodenv}/bin" ]]; then
5+
export NODENV_ROOT
6+
pathmunge "$NODENV_ROOT/bin"
7+
fi
78

8-
if _command_exists nodenv; then
9-
eval "$(nodenv init - bash)"
9+
if ! _binary_exists nodenv; then
10+
_log_warning "Unable to locage 'nodenv'."
11+
return 1
1012
fi
13+
14+
# shellcheck disable=SC1090
15+
source < <(nodenv init - bash)

0 commit comments

Comments
 (0)