Convenience Tools¶
Tools can make work easier and efficient.
Bash Navigation Tool¶
This tool allows you to quickly get to your ZP source tree. It has filename completion:
export zpdefault=Ceph
if [ -z $zpbase ]; then
if [ -d /z ]; then
zpbase="/z"
elif [ -d /mnt/src/zenpacks ]; then
zpbase="/mnt/src/zenpacks"
elif [ -d /home/zenoss/src/europa/src/zenpacks ]; then
zpbase="/home/zenoss/src/europa/src/zenpacks"
elif [ -d /zenpacks ]; then
zpbase="/zenpacks"
elif [ -d /data/zp ]; then
zpbase="/data/zp"
else
zpbase="/tmp"
fi
export zpbase
fi
zp()
{
# --------------------------------------------------------------------------
# Setup up variables..
# --------------------------------------------------------------------------
if [[ -z "$zpdefault" ]]; then
export zpdefault=PythonCollector
fi
if [[ -z "$zplast" && -z "$zpcurrent" ]]; then
export zplast
export zpcurrent
fi
# --------------------------------------------------------------------------
# Find and go to right folders
# --------------------------------------------------------------------------
if [ -n "$1" ]; then
if [ -d "$zpbase"/"$1" ]; then
echo "zenpack exists";
cd "$zpbase"/"$1";
return;
fi;
if [[ "$1" == "-" ]]; then
if [[ -n "$zplast" && -n "$zpcurrent" ]]; then
echo "returning to prior zenpack";
zptemp=$zplast
zplast=$zpcurrent
zpcurrent=$zptemp
cd "$zpcurrent"
fi
return;
fi;
second="ZenPacks.zenoss.$1";
third=${second//./\/};
final="$zpbase"/"$second"/"$third"/;
if [ -d $final ]; then
echo "zenpack exists";
zplast="$PWD";
zpcurrent="$final";
cd "$final";
else
echo "no such Zenpack $final";
return;
fi;
else
echo "Using default zp";
zp $zpdefault;
fi
}
function _zp()
{
local cmd="${1##*/}"
local word=${COMP_WORDS[COMP_CWORD]}
# Pointer to current completion word.
# By convention, it's named "cur" but this isn't strictly necessary.
words=""
case "$word" in
*)
for i in $zpbase/ZenPacks.zenoss.${word}*; do
if [[ -d $i ]]; then
words+="${i##*.}"
words+=" "
fi
done
esac
COMPREPLY=() # Array variable storing the possible completions.
COMPREPLY=( $( compgen -W "$words" -- $cur ) )
}
complete -o filenames -F _zp zp
To use it, put the contents into a zp.sh file and source it from your .bashrc and then use it as follows:
zp Py<tab>
It should complete the name to PythonCollector, assuming you have the PythonCollector ZenPack installed, and take you to the folder:
$zpbase/ZenPacks.zenoss.PythonCollector/ZenPacks/zenoss/PythonCollector/
Make sure your ZenPacks are stored in one of the following directories:
- /z
- /mnt/src/zenpacks
- /home/zenoss/src/europa/src/zenpacks
- /zenpacks
- /data/zp
- /tmp