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
This commit is contained in:
16
plugins/available/cmd-returned-notify.plugin.bash
Normal file
16
plugins/available/cmd-returned-notify.plugin.bash
Normal file
@@ -0,0 +1,16 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'Alert (BEL) when process ends after a threshold of seconds'
|
||||
|
||||
precmd_return_notification() {
|
||||
export LAST_COMMAND_DURATION=$(($(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)}))
|
||||
[[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a"
|
||||
export LAST_COMMAND_TIME=
|
||||
}
|
||||
|
||||
preexec_return_notification() {
|
||||
[ -z "${LAST_COMMAND_TIME}" ] && export LAST_COMMAND_TIME=$(date +%s)
|
||||
}
|
||||
|
||||
precmd_functions+=(precmd_return_notification)
|
||||
preexec_functions+=(preexec_return_notification)
|
||||
@@ -1,30 +1,33 @@
|
||||
# shellcheck shell=bash
|
||||
cite about-plugin
|
||||
about-plugin 'automatically set your xterm title with host and location info'
|
||||
|
||||
|
||||
_short-dirname () {
|
||||
local dir_name=`dirs +0`
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ ${#dir_name} -gt 8 ] && echo ${dir_name##*/} || echo $dir_name
|
||||
_short-dirname() {
|
||||
local dir_name=$(dirs +0)
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}"
|
||||
}
|
||||
|
||||
_short-command () {
|
||||
local input_command="$@"
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ ${#input_command} -gt 8 ] && echo ${input_command%% *} || echo $input_command
|
||||
_short-command() {
|
||||
local input_command="$*"
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}"
|
||||
}
|
||||
|
||||
set_xterm_title () {
|
||||
local title="$1"
|
||||
echo -ne "\033]0;$title\007"
|
||||
set_xterm_title() {
|
||||
local title="$1"
|
||||
echo -ne "\033]0;$title\007"
|
||||
}
|
||||
|
||||
precmd () {
|
||||
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} `_short-dirname` $PROMPTCHAR"
|
||||
precmd_xterm_title() {
|
||||
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPT_CHAR"
|
||||
}
|
||||
|
||||
preexec () {
|
||||
set_xterm_title "`_short-command $1` {`_short-dirname`} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
|
||||
preexec_xterm_title() {
|
||||
set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
|
||||
}
|
||||
|
||||
case "$TERM" in
|
||||
xterm*|rxvt*) preexec_install;;
|
||||
xterm* | rxvt*)
|
||||
precmd_functions+=(precmd_xterm_title)
|
||||
preexec_functions+=(preexec_xterm_title)
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user