From fda1dcebfeeccc19be0010bdac76a0605d23a54c Mon Sep 17 00:00:00 2001 From: Marcus Whybrow Date: Thu, 31 May 2012 09:20:48 +0100 Subject: [PATCH] Limited file checking auto completion options to one level of completion. It could carry on completing from the same options indefinitely. --- bash_completion/msm | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/bash_completion/msm b/bash_completion/msm index a318093..fe5ddbc 100644 --- a/bash_completion/msm +++ b/bash_completion/msm @@ -66,16 +66,18 @@ _msm() { else case "${COMP_WORDS[3]}" in ram) - world_dir="${server_path}/$DEFAULT_WORLD_STORAGE_PATH" + if [[ $COMP_CWORD == 4 ]]; then + local world_dir="${server_path}/$DEFAULT_WORLD_STORAGE_PATH" - # Override with server specific value if present - server_conf="${server_path}/$DEFAULT_SERVER_CONF" - if [ -e "$server_conf" ]; then - world_dir=$(grep "^WORLD_STORAGE_PATH=\".*\"" $server_conf | awk -F '"' '{print $2}') - fi + # Override with server specific value if present + local server_conf="${server_path}/$DEFAULT_SERVER_CONF" + if [ -f "$server_conf" ]; then + world_dir=$(grep "^WORLD_STORAGE_PATH=\".*\"" $server_conf | awk -F '"' '{print $2}') + fi - if [ -d "$world_dir" ]; then - options="$(ls -1 "$world_dir")" + if [ -d "$world_dir" ]; then + options="$(ls -1 "$world_dir")" + fi fi ;; esac @@ -96,16 +98,18 @@ _msm() { else case "${COMP_WORDS[3]}" in remove) - whitelist_path="${server_path}/$DEFAULT_WHITELIST" + if [[ $COMP_CWORD == 4 ]]; then + local whitelist_path="${server_path}/$DEFAULT_WHITELIST" - # Override with server specific value if present - server_conf="${server_path}/$DEFAULT_SERVER_CONF" - if [ -e "$server_conf" ]; then - whitelist_path=$(grep "^WHITELIST=\".*\"" $server_conf | awk -F '"' '{print $2}') - fi + # Override with server specific value if present + local server_conf="${server_path}/$DEFAULT_SERVER_CONF" + if [ -f "$server_conf" ]; then + whitelist_path=$(grep "^WHITELIST=\".*\"" $server_conf | awk -F '"' '{print $2}') + fi - if [ -f "$whitelist_path" ]; then - options=$(cat "$whitelist_path") + if [ -f "$whitelist_path" ]; then + options="$(cat "$whitelist_path")" + fi fi ;; esac