tmux, bash, mgmt fiddling
This commit is contained in:
parent
6649cfc78d
commit
c653422734
11 changed files with 160 additions and 11 deletions
40
private_dot_config/private_mgmt/fns/current.bash
Normal file
40
private_dot_config/private_mgmt/fns/current.bash
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# shellcheck shell=bash
|
||||
#================================================================
|
||||
#% SYNOPSIS
|
||||
#+ current <cmd> [-f <flag>] [-r <regex>]
|
||||
#%
|
||||
#% OPTIONS
|
||||
#% -f set command-line args to pass to <cmd>; single string.
|
||||
#% Default: [--version]
|
||||
#% -r set regex used to extract version string from cmd output
|
||||
#% Default: [v?(\d+\.\d+\.\d+)]
|
||||
#================================================================
|
||||
current() {
|
||||
flag="--version"
|
||||
regex='v?(\d+\.\d+\.\d+)'
|
||||
declare -a args
|
||||
OPTIND=1
|
||||
while [ $OPTIND -le "$#" ]; do
|
||||
if getopts :f:r: opt; then
|
||||
case "$opt" in
|
||||
\?)
|
||||
diag "$(red "error: called 'current' badly")"
|
||||
;;
|
||||
f) flag="$OPTARG" ;;
|
||||
r) regex="$OPTARG" ;;
|
||||
esac
|
||||
else
|
||||
args+=("${!OPTIND}")
|
||||
(( OPTIND++ ))
|
||||
fi
|
||||
done
|
||||
set -- "${args[@]}"
|
||||
|
||||
cmd="$1"
|
||||
|
||||
if command -v "$cmd" >/dev/null; then
|
||||
bash -c "$cmd $flag" | perl -ne 'm/'"$regex"'/ && print "$1\n"' || true
|
||||
else
|
||||
true
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue