Fix #64, prevent tab completion crash when server name all is used

This commit is contained in:
Marcus Whybrow 2012-08-02 10:31:15 +01:00
parent dd30caaa1d
commit 92c9395423

View File

@ -121,14 +121,17 @@ _msm() {
;; ;;
*) *)
# Server options # Server options
local server_path="$SETTINGS_SERVER_STORAGE_PATH/${COMP_WORDS[1]}"
if [[ "${COMP_WORDS[1]}" == "all" ]] || [ -e "$server_path" ]; then
# If the server exists
if [[ "${COMP_WORDS[1]}" == "all" ]]; then
local sid="-1"
else
server_get_id "${COMP_WORDS[1]}" server_get_id "${COMP_WORDS[1]}"
local sid="$RETURN" local sid="$RETURN"
fi
local server_path="$SETTINGS_SERVER_STORAGE_PATH/${COMP_WORDS[1]}"
if [[ "${COMP_WORDS[1]}" == "all" ]] || [ -e "$server_path" ]; then
if [[ $COMP_CWORD == 2 ]]; then if [[ $COMP_CWORD == 2 ]]; then
options="start stop restart status connected worlds logroll backup jar whitelist blacklist operator gamemode kick say time toggledownfall give xp save cmd cmdlog console config" options="start stop restart status connected worlds logroll backup jar whitelist blacklist operator gamemode kick say time toggledownfall give xp save cmd cmdlog console config"
else else
@ -142,33 +145,34 @@ _msm() {
if [[ $COMP_CWORD == 3 ]]; then if [[ $COMP_CWORD == 3 ]]; then
options="list load ram todisk backup on off" options="list load ram todisk backup on off"
else else
if [[ "${COMP_WORDS[1]}" != "all" ]]; then
case "${COMP_WORDS[3]}" in case "${COMP_WORDS[3]}" in
ram) ram)
if [[ $COMP_CWORD == 4 ]]; then if [[ $COMP_CWORD == 4 ]]; then
server_property "$sid" WORLD_STORAGE_PATH server_property "$sid" WORLD_STORAGE_PATH
if [ -d "${SERVER_WORLD_STORAGE_PATH[$sid]}" ]; then if [ -d "${SERVER_WORLD_STORAGE_PATH[$sid]}" ]; then
options="$(ls -1 "${SERVER_WORLD_STORAGE_PATH[$sid]}")" options="$(ls -1 "${SERVER_WORLD_STORAGE_PATH[$sid]}")"
fi
fi fi
fi ;;
;; on)
on) if [[ $COMP_CWORD == 4 ]]; then
if [[ $COMP_CWORD == 4 ]]; then server_property "$sid" WORLD_STORAGE_INACTIVE_PATH
server_property "$sid" WORLD_STORAGE_INACTIVE_PATH if [ -d "${SERVER_WORLD_STORAGE_INACTIVE_PATH[$sid]}" ]; then
if [ -d "${SERVER_WORLD_STORAGE_INACTIVE_PATH[$sid]}" ]; then options="$(ls -1 "${SERVER_WORLD_STORAGE_INACTIVE_PATH[$sid]}")"
options="$(ls -1 "${SERVER_WORLD_STORAGE_INACTIVE_PATH[$sid]}")" fi
fi fi
fi ;;
;; off)
off) if [[ $COMP_CWORD == 4 ]]; then
if [[ $COMP_CWORD == 4 ]]; then server_property "$sid" WORLD_STORAGE_PATH
server_property "$sid" WORLD_STORAGE_PATH if [ -d "${SERVER_WORLD_STORAGE_PATH[$sid]}" ]; then
if [ -d "${SERVER_WORLD_STORAGE_PATH[$sid]}" ]; then options="$(ls -1 "${SERVER_WORLD_STORAGE_PATH[$sid]}")"
options="$(ls -1 "${SERVER_WORLD_STORAGE_PATH[$sid]}")" fi
fi fi
fi ;;
;; esac
esac fi
fi fi
;; ;;
jar) jar)
@ -185,16 +189,18 @@ _msm() {
if [[ $COMP_CWORD == 3 ]]; then if [[ $COMP_CWORD == 3 ]]; then
options="on off add remove list" options="on off add remove list"
else else
case "${COMP_WORDS[3]}" in if [[ "${COMP_WORDS[1]}" != "all" ]]; then
remove) case "${COMP_WORDS[3]}" in
if [[ $COMP_CWORD -ge 4 ]]; then remove)
server_property "$sid" WHITELIST_PATH if [[ $COMP_CWORD -ge 4 ]]; then
if [ -f "${SERVER_WHITELIST_PATH[$sid]}" ]; then server_property "$sid" WHITELIST_PATH
options="$(cat "${SERVER_WHITELIST_PATH[$sid]}")" if [ -f "${SERVER_WHITELIST_PATH[$sid]}" ]; then
options="$(cat "${SERVER_WHITELIST_PATH[$sid]}")"
fi
fi fi
fi ;;
;; esac
esac fi
fi fi
;; ;;
blacklist|bl) blacklist|bl)
@ -206,32 +212,36 @@ _msm() {
if [[ $COMP_CWORD == 4 ]]; then if [[ $COMP_CWORD == 4 ]]; then
options="add remove" options="add remove"
else else
case "${COMP_WORDS[4]}" in if [[ "${COMP_WORDS[1]}" != "all" ]]; then
remove) case "${COMP_WORDS[4]}" in
if [[ $COMP_CWORD -ge 5 ]]; then remove)
server_property "$sid" BANNED_PLAYERS_PATH if [[ $COMP_CWORD -ge 5 ]]; then
if [ -f "${SERVER_BANNED_PLAYERS_PATH[$sid]}" ]; then server_property "$sid" BANNED_PLAYERS_PATH
options="$(cat "${SERVER_BANNED_PLAYERS_PATH[$sid]}")" if [ -f "${SERVER_BANNED_PLAYERS_PATH[$sid]}" ]; then
options="$(cat "${SERVER_BANNED_PLAYERS_PATH[$sid]}")"
fi
fi fi
fi ;;
;; esac
esac fi
fi fi
;; ;;
ip) ip)
if [[ $COMP_CWORD == 4 ]]; then if [[ $COMP_CWORD == 4 ]]; then
options="add remove" options="add remove"
else else
case "${COMP_WORDS[4]}" in if [[ "${COMP_WORDS[1]}" != "all" ]]; then
remove) case "${COMP_WORDS[4]}" in
if [[ $COMP_CWORD -ge 5 ]]; then remove)
server_property "$sid" BANNED_PLAYERS_PATH if [[ $COMP_CWORD -ge 5 ]]; then
if [ -f "${SERVER_BANNED_IPS_PATH[$sid]}" ]; then server_property "$sid" BANNED_PLAYERS_PATH
options="$(cat "${SERVER_BANNED_IPS_PATH[$sid]}")" if [ -f "${SERVER_BANNED_IPS_PATH[$sid]}" ]; then
options="$(cat "${SERVER_BANNED_IPS_PATH[$sid]}")"
fi
fi fi
fi ;;
;; esac
esac fi
fi fi
;; ;;
esac esac
@ -241,16 +251,18 @@ _msm() {
if [[ $COMP_CWORD == 3 ]]; then if [[ $COMP_CWORD == 3 ]]; then
options="add remove list" options="add remove list"
else else
case "${COMP_WORDS[3]}" in if [[ "${COMP_WORDS[1]}" != "all" ]]; then
remove) case "${COMP_WORDS[3]}" in
if [[ $COMP_CWORD -ge 4 ]]; then remove)
server_property "$sid" OPS_PATH if [[ $COMP_CWORD -ge 4 ]]; then
if [ -f "${SERVER_OPS_PATH[$sid]}" ]; then server_property "$sid" OPS_PATH
options="$(cat "${SERVER_OPS_PATH[$sid]}")" if [ -f "${SERVER_OPS_PATH[$sid]}" ]; then
options="$(cat "${SERVER_OPS_PATH[$sid]}")"
fi
fi fi
fi ;;
;; esac
esac fi
fi fi
;; ;;
gamemode|gm) gamemode|gm)
@ -270,8 +282,10 @@ _msm() {
;; ;;
config) config)
if [[ $COMP_CWORD == 3 ]]; then if [[ $COMP_CWORD == 3 ]]; then
server_property "$sid" SERVER_CONF if [[ "${COMP_WORDS[1]}" != "all" ]]; then
options="$(more "${SERVER_CONF[$sid]}" | sed 's/=.*$//' | grep -v '#')"; server_property "$sid" SERVER_CONF
options="$(more "${SERVER_CONF[$sid]}" | sed 's/=.*$//' | grep -v '#')";
fi
fi fi
;; ;;
esac esac