85 lines
2.5 KiB
Bash
85 lines
2.5 KiB
Bash
#! /usr/bin/env bash
|
|
|
|
SHOW_ALIASES=0
|
|
SHOW_FUNCTIONS=0
|
|
SHOW_MEMBASED=0
|
|
SHOW_SCRIPTS=0
|
|
|
|
NAME="${0##*/}"
|
|
eval set -- $(getopt --name "$NAME" --options 'afmsh' --longoptions aliases,functions,membased,scripts,all,help -- "${@}")
|
|
|
|
ARG_COUNT=0
|
|
SHOW_USAGE=0
|
|
while [[ $# -gt 0 ]]
|
|
do
|
|
opt="$1";
|
|
#expose next argument
|
|
shift;
|
|
case "$opt" in
|
|
'--' ) break 2;;
|
|
'-h'|'-?' )
|
|
opt='--help' ;;
|
|
'-a' )
|
|
opt='--aliases' ;;
|
|
'-f' )
|
|
opt='--functions' ;;
|
|
'-m' )
|
|
opt='--membased' ;;
|
|
'-s' )
|
|
opt='--scripts' ;;
|
|
esac
|
|
((ARG_COUNT++))
|
|
case "$opt" in
|
|
'--help' ) SHOW_USAGE=1; break 2;;
|
|
'--aliases' )
|
|
SHOW_ALIASES=1 ;;
|
|
'--functions' )
|
|
SHOW_FUNCTIONS=1 ;;
|
|
'--membased' )
|
|
SHOW_MEMBASED=1 ;;
|
|
'--scripts' )
|
|
SHOW_SCRIPTS=1 ;;
|
|
*) echo >&2 "Invalid option: $@"; exit 1;;
|
|
esac
|
|
done
|
|
|
|
# If no args, show_usage
|
|
[[ $ARG_COUNT -eq 0 ]] && SHOW_SCRIPTS=0
|
|
|
|
if [[ "$SHOW_USAGE" == "1" ]]; then
|
|
printf "%s\n" \
|
|
"${0##*/}: ${0##*/} [-afhms] [--aliases] [--functions] [--help] [--membased] [--script]" \
|
|
" List POLARISqb productivity and helpdesk commands supplied by ITOps" \
|
|
"" \
|
|
" Options:" \
|
|
" -a | --aliases List aliases defined in Pqb startup scripts" \
|
|
" -f | --functions List functions defined in Pqb startup scripts" \
|
|
" -h | --help Display this usage message" \
|
|
" -m | --membased List all memory based commands (aka, aliases " \
|
|
" and functions)." \
|
|
" -s | --scripts List Pqb supplied utility scripts" \
|
|
" This is the default when no arguments are passed" \
|
|
""
|
|
|
|
return 2>/dev/null || exit
|
|
fi
|
|
FILTER=""
|
|
if [[ "$SHOW_ALIASES" == "1" || "$SHOW_MEMBASED" == "1" ]]; then
|
|
FILTER+="^\W*alias\|"
|
|
fi
|
|
if [[ "$SHOW_FUNCTIONS" == "1" || "$SHOW_MEMBASED" == "1" ]]; then
|
|
FILTER+="^\W*functions\|"
|
|
fi
|
|
if [[ -n "$FILTER" ]]; then
|
|
FILTER=${FILTER%\\|*}
|
|
find ~/.pqb.shrc.d -type f \
|
|
| xargs grep "${FILTER}" \
|
|
| sed 's/^.*\.d\///; s/:.*function /:(f) /; s/() {.*$//; s/:.*alias /:(a) /; s/=.*$//;'
|
|
fi
|
|
|
|
[[ "$SHOW_ALIASES" == "0" && "$SHOW_MEMBASED" == "0" && "$SHOW_MEMBASED" == "0" ]] && SHOW_SCRIPTS=1
|
|
|
|
if [[ "$SHOW_SCRIPTS" == "1" ]]; then
|
|
find ~/.local/bin -executable -type f -name "pqb*" -printf "%f\n"
|
|
fi
|