Improve fabric-completion.
* Search recursively up the filesystem for fabfile.py since fabric does this * Short circuit earlier if cache is not enabledpull/216/head
parent
8d7a9cc1bb
commit
bd7662f51f
|
|
@ -64,16 +64,26 @@ function __fab_chache_mtime() {
|
||||||
# Get time of last fabfile file/module modification as seconds since Epoch
|
# Get time of last fabfile file/module modification as seconds since Epoch
|
||||||
#
|
#
|
||||||
function __fab_fabfile_mtime() {
|
function __fab_fabfile_mtime() {
|
||||||
local f="fabfile"
|
if [[ -d "$1" ]]; then
|
||||||
if [[ -e "$f.py" ]]; then
|
|
||||||
${__FAB_COMPLETION_MTIME_COMMAND} "$f.py" | xargs -n 1 expr
|
|
||||||
else
|
|
||||||
# Suppose that it's a fabfile dir
|
|
||||||
find $f/*.py -exec ${__FAB_COMPLETION_MTIME_COMMAND} {} + \
|
find $f/*.py -exec ${__FAB_COMPLETION_MTIME_COMMAND} {} + \
|
||||||
| xargs -n 1 expr | sort -n -r | head -1
|
| xargs -n 1 expr | sort -n -r | head -1
|
||||||
|
else
|
||||||
|
${__FAB_COMPLETION_MTIME_COMMAND} "$1" | xargs -n 1 expr
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Recursively look for a file up the filesystem
|
||||||
|
#
|
||||||
|
function __fab_fabfile_search() {
|
||||||
|
slashes=${PWD//[^\/]/}
|
||||||
|
directory="$PWD"
|
||||||
|
for (( n=${#slashes}; n>0; --n ))
|
||||||
|
do
|
||||||
|
test -e "$directory/$1" && echo "$directory/$1" && return
|
||||||
|
directory="$directory/.."
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Completion for "fab" command
|
# Completion for "fab" command
|
||||||
|
|
@ -107,22 +117,29 @@ function __fab_completion() {
|
||||||
# ;;
|
# ;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
# If "fabfile.py" or "fabfile" dir with "__init__.py" file exists
|
# If use cache
|
||||||
local f="fabfile"
|
if $FAB_COMPLETION_CACHE_TASKS; then
|
||||||
if [[ -e "$f.py" || (-d "$f" && -e "$f/__init__.py") ]]; then
|
local f="fabfile"
|
||||||
# Build a list of the available tasks
|
local f_path=$(__fab_fabfile_search $f.py)
|
||||||
if $FAB_COMPLETION_CACHE_TASKS; then
|
local f_location=""
|
||||||
# If use cache
|
# If "fabfile.py" or "fabfile" dir with "__init__.py" file exists
|
||||||
|
if [[ -n "$f_path" ]]; then
|
||||||
|
f_location=$f_path
|
||||||
|
elif [[ -d "$f" && -e "$f/__init__.py" ]]; then
|
||||||
|
f_location=$f
|
||||||
|
fi
|
||||||
|
if [[ -n "$f_location" ]]; then
|
||||||
|
# Build a list of the available tasks
|
||||||
if [[ ! -s ${FAB_COMPLETION_CACHED_TASKS_FILENAME} ||
|
if [[ ! -s ${FAB_COMPLETION_CACHED_TASKS_FILENAME} ||
|
||||||
$(__fab_fabfile_mtime) -gt $(__fab_chache_mtime) ]]; then
|
$(__fab_fabfile_mtime $f_location) -gt $(__fab_chache_mtime) ]]; then
|
||||||
fab --shortlist > ${FAB_COMPLETION_CACHED_TASKS_FILENAME} \
|
fab --shortlist > ${FAB_COMPLETION_CACHED_TASKS_FILENAME} \
|
||||||
2> /dev/null
|
2> /dev/null
|
||||||
fi
|
fi
|
||||||
opts=$(cat ${FAB_COMPLETION_CACHED_TASKS_FILENAME})
|
opts=$(cat ${FAB_COMPLETION_CACHED_TASKS_FILENAME})
|
||||||
else
|
|
||||||
# Without cache
|
|
||||||
opts=$(fab --shortlist 2> /dev/null)
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
# Without cache
|
||||||
|
opts=$(fab --shortlist 2> /dev/null)
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue