mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-02-12 15:19:12 +01:00
batwatch: Split hook_help into a lib script
This commit is contained in:
parent
69d9c38326
commit
38f56c1bc7
32
lib/opt_hook_help.sh
Normal file
32
lib/opt_hook_help.sh
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# bat-extras | Copyright (C) 2019-2020 eth-p | MIT License
|
||||
#
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Option parser hook: --help support.
|
||||
# This will accept -h or --help, which prints the usage information and exits.
|
||||
hook_help() {
|
||||
SHIFTOPT_HOOKS+=("__shiftopt_hook__help")
|
||||
if [[ "$1" == "--no-short" ]]; then
|
||||
__shiftopt_hook__help() {
|
||||
if [[ "$OPT" = "--help" ]]; then
|
||||
show_help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
else
|
||||
__shiftopt_hook__help() {
|
||||
if [[ "$OPT" = "--help" ]] || [[ "$OPT" = "-h" ]]; then
|
||||
show_help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# bat-extras | Copyright (C) 2019 eth-p | MIT License
|
||||
# bat-extras | Copyright (C) 2019-2020 eth-p | MIT License
|
||||
#
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
@ -10,6 +10,7 @@ LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd "$(dirname "$(readlink "${BASH_
|
||||
source "${LIB}/constants.sh"
|
||||
source "${LIB}/opt.sh"
|
||||
source "${LIB}/opt_hook_color.sh"
|
||||
source "${LIB}/opt_hook_help.sh"
|
||||
source "${LIB}/opt_hook_pager.sh"
|
||||
source "${LIB}/opt_hook_version.sh"
|
||||
source "${LIB}/opt_hook_width.sh"
|
||||
@ -18,26 +19,18 @@ source "${LIB}/pager.sh"
|
||||
# -----------------------------------------------------------------------------
|
||||
# Init:
|
||||
# -----------------------------------------------------------------------------
|
||||
# Option parser hook: --help support.
|
||||
# This will accept -h or --help, which prints the usage information and exits.
|
||||
hook_help() {
|
||||
SHIFTOPT_HOOKS+=("__shiftopt_hook__help")
|
||||
__shiftopt_hook__help() {
|
||||
if [[ "$OPT" = "--help" ]] || [[ "$OPT" = "-h" ]]; then
|
||||
echo 'Usage: batwatch [--watcher entr|poll][--[no-]clear] <file> [<file> ...]'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
hook_color
|
||||
hook_pager
|
||||
hook_version
|
||||
hook_width
|
||||
hook_help
|
||||
# -----------------------------------------------------------------------------
|
||||
# Help:
|
||||
# -----------------------------------------------------------------------------
|
||||
show_help() {
|
||||
echo 'Usage: batwatch [--watcher entr|poll][--[no-]clear] <file> [<file> ...]'
|
||||
}
|
||||
# -----------------------------------------------------------------------------
|
||||
# Watchers:
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
@ -48,7 +41,7 @@ WATCHERS=("entr" "poll")
|
||||
watcher_entr_watch() {
|
||||
ENTR_ARGS=()
|
||||
|
||||
if [[ "$OPT_CLEAR" = "true" ]]; then
|
||||
if [[ "$OPT_CLEAR" == "true" ]]; then
|
||||
ENTR_ARGS+=('-c')
|
||||
fi
|
||||
|
||||
@ -115,7 +108,7 @@ watcher_poll_watch() {
|
||||
if "$modified"; then
|
||||
modified=false
|
||||
|
||||
if [[ "$OPT_CLEAR" = "true" ]]; then
|
||||
if [[ "$OPT_CLEAR" == "true" ]]; then
|
||||
clear
|
||||
fi
|
||||
|
||||
@ -192,7 +185,10 @@ while shiftopt; do
|
||||
case "$OPT" in
|
||||
|
||||
# Script options
|
||||
--watcher) shiftval; OPT_WATCHER="$OPT_VAL" ;;
|
||||
--watcher)
|
||||
shiftval
|
||||
OPT_WATCHER="$OPT_VAL"
|
||||
;;
|
||||
--clear) OPT_CLEAR=true ;;
|
||||
--no-clear) OPT_CLEAR=false ;;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user