Skip to content

Commit 5809d92

Browse files
committed
Adding preexec as a vendored library
Added a vendored lib loading routine in bash-it.sh Added documentation on how to vendor libs in bash-it Added and fixed plugins using preexec Added tests for two plugins Removed the old preexec lib
1 parent 8fe585c commit 5809d92

File tree

12 files changed

+249
-260
lines changed

12 files changed

+249
-260
lines changed

bash_it.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ do
4949
fi
5050
done
5151

52+
# Load vendors
53+
BASH_IT_LOG_PREFIX="vendor: "
54+
for _bash_it_vendor_init in "${BASH_IT}"/vendor/init.d/*.bash
55+
do
56+
_log_debug "Loading \"$(basename "${_bash_it_vendor_init}" .bash)\"..."
57+
# shellcheck disable=SC1090
58+
source "${_bash_it_vendor_init}"
59+
done
60+
unset _bash_it_vendor_init
61+
62+
BASH_IT_LOG_PREFIX="core: main: "
5263
# Load the global "enabled" directory
5364
# "family" param is empty so that files get sources in glob order
5465
# shellcheck source=./scripts/reloader.bash
@@ -62,7 +73,7 @@ do
6273
done
6374

6475
# Load theme, if a theme was set
65-
if [[ ! -z "${BASH_IT_THEME}" ]]; then
76+
if [[ -n "${BASH_IT_THEME}" ]]; then
6677
_log_debug "Loading \"${BASH_IT_THEME}\" theme..."
6778
# Load colors and helpers first so they can be used in base theme
6879
BASH_IT_LOG_PREFIX="themes: colors: "

clean_files.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ themes/barbuk
3939
themes/atomic
4040
themes/axin
4141
themes/base.theme.bash
42+
themes/command_duration.theme.bash
4243

4344
# plugins
4445
#
4546
plugins/available/basher.plugin.bash
47+
plugins/available/cmd-returned-notify.plugin.bash
48+
plugins/available/xterm.plugin.bash
4649

4750
# completions
4851
#

docs/development.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The main ``bash_it.sh`` script loads the frameworks individual components in the
3838

3939

4040
* ``lib/composure.bash``
41+
* ``vendor/init.d/*.bash``
4142
* Files in ``lib`` with the exception of ``appearance.bash`` - this means that ``composure.bash`` is loaded again here (possible improvement?)
4243
* Enabled ``aliases``
4344
* Enabled ``plugins``
@@ -78,6 +79,62 @@ Having the order based on a numeric priority in a common directory allows for mo
7879

7980
These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well.
8081

82+
Working with vendored libs
83+
--------------------------
84+
85+
Vendored libs are external libraries, meaning source code not maintained by Bash-it
86+
developers.
87+
They are ``git subtrees`` curated in the ``vendor/`` folder. To ease the work with git
88+
vendored libs as subtrees we use the `git-vendor <https://github.com/Tyrben/git-vendor>`_ tool.
89+
90+
For more information on ``git vendor`` there are a short `usage description <https://github.com/Tyrben/git-vendor#usage>`_
91+
in the repositories ``README`` file and a website with the `manual page <https://brettlangdon.github.io/git-vendor/>`_.
92+
93+
To support a flexible loading of external libraries, a file unique to the vendored
94+
library must be placed in ``vendor/init.d/`` with the ``.bash`` extension.
95+
96+
Rebasing a feature branch with an added/updated vendored library
97+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98+
99+
If your feature branch with a newly added/updated vendored lib has fallen behind master
100+
you might need to rebase it before creating a PR. However rebasing with dangling
101+
subtree commits can cause problems.
102+
The following rebase strategy will pause the rebase at the point where you added a
103+
subtree and let you add it again before continuing the rebasing.
104+
105+
::
106+
107+
[feature/branch] $ git rebase --rebase-merges --strategy subtree master
108+
fatal: refusing to merge unrelated histories
109+
Could not apply 0d6a56b... Add-preexec-from-https-github.colasdn.workers.dev-rcaloras-bash-preexec-0-4-1- # Add "preexec" from "https://github.com/rcaloras/[email protected]"
110+
[feature/branch] $ git vendor add preexec https://github.com/rcaloras/bash-preexec 0.4.1
111+
...
112+
[feature/branch] $ git rebase --continue
113+
114+
If rebasing makes you a little uneasy (as it probably should). You can always test in
115+
another branch.
116+
117+
::
118+
119+
[feater/branch] $ git checkout -b feature/branch-test-rebase
120+
[feater/branch-test-rebase] $ git rebase --rebase-merges --strategy subtree master
121+
...
122+
123+
Afterwards you can make sure the rebase was successful by running ``git vendor list``
124+
to see if your library is still recognized as a vendored lib
125+
126+
::
127+
128+
[feature/branch] $ git vendor list
129+
130+
name: preexec
131+
dir: vendor/github.com/rcaloras/bash-preexec
132+
repo: https://github.com/rcaloras/bash-preexec
133+
ref: 0.4.1
134+
commit: 8fe585c5cf377a3830b895fe26e694b020d8db1a
135+
[feature/branch] $
136+
137+
81138
Plugin Disable Callbacks
82139
------------------------
83140

lib/preexec.bash

Lines changed: 0 additions & 199 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# shellcheck shell=bash
2+
cite about-plugin
3+
about-plugin 'Alert (BEL) when process ends after a threshold of seconds'
4+
5+
precmd_return_notification() {
6+
export LAST_COMMAND_DURATION=$(($(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)}))
7+
[[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a"
8+
export LAST_COMMAND_TIME=
9+
}
10+
11+
preexec_return_notification() {
12+
[ -z "${LAST_COMMAND_TIME}" ] && export LAST_COMMAND_TIME=$(date +%s)
13+
}
14+
15+
precmd_functions+=(precmd_return_notification)
16+
preexec_functions+=(preexec_return_notification)
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1+
# shellcheck shell=bash
12
cite about-plugin
23
about-plugin 'automatically set your xterm title with host and location info'
34

4-
5-
_short-dirname () {
6-
local dir_name=`dirs +0`
7-
[ "$SHORT_TERM_LINE" = true ] && [ ${#dir_name} -gt 8 ] && echo ${dir_name##*/} || echo $dir_name
5+
_short-dirname() {
6+
local dir_name=$(dirs +0)
7+
[ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}"
88
}
99

10-
_short-command () {
11-
local input_command="$@"
12-
[ "$SHORT_TERM_LINE" = true ] && [ ${#input_command} -gt 8 ] && echo ${input_command%% *} || echo $input_command
10+
_short-command() {
11+
local input_command="$*"
12+
[ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}"
1313
}
1414

15-
set_xterm_title () {
16-
local title="$1"
17-
echo -ne "\033]0;$title\007"
15+
set_xterm_title() {
16+
local title="$1"
17+
echo -ne "\033]0;$title\007"
1818
}
1919

20-
precmd () {
21-
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} `_short-dirname` $PROMPTCHAR"
20+
precmd_xterm_title() {
21+
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPT_CHAR"
2222
}
2323

24-
preexec () {
25-
set_xterm_title "`_short-command $1` {`_short-dirname`} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
24+
preexec_xterm_title() {
25+
set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
2626
}
2727

2828
case "$TERM" in
29-
xterm*|rxvt*) preexec_install;;
29+
xterm* | rxvt*)
30+
precmd_functions+=(precmd_xterm_title)
31+
preexec_functions+=(preexec_xterm_title)
32+
;;
3033
esac

test/fixtures/plugin/xterm/files/arg0

Whitespace-only changes.

test/fixtures/plugin/xterm/files/arg1

Whitespace-only changes.

0 commit comments

Comments
 (0)