1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-08-02 21:53:38 +02:00

Fetch list of all projects lazily

Currently osc <TAB><TAB> takes a long time to complete, which is incredibly
annoying. Only run "osc ls" if it is necessary for proper completion.
This commit is contained in:
Fabian Vogt
2020-03-13 15:32:03 +01:00
parent 3914b8c5e8
commit e11b49e2f1

11
dist/osc.complete vendored
View File

@@ -132,7 +132,9 @@ if test -n "$alias" ; then
command="$command -A $alias"
fi
if test -s "${projects}" ; then
update_projects_list ()
{
if test -s "${projects}" ; then
typeset -i ctime=$(command date -d "$(command stat -c '%z' ${projects})" +'%s')
typeset -i now=$(command date -d now +'%s')
if ((now - ctime > 86400)) ; then
@@ -141,9 +143,10 @@ if test -s "${projects}" ; then
mv -uf $tmp ${projects}
fi
fi
else
else
command ${command} ls / >| "${projects}"
fi
fi
}
projects ()
{
@@ -159,6 +162,7 @@ projects ()
argv[argc++]=$arg
done
shift $argc
update_projects_list
cur="$1"
if test -n "${cur}" ; then
list=($(command grep -E "^${cur}" ${projects}))
@@ -273,6 +277,7 @@ targets ()
users ()
{
update_projects_list
if test -s ${projects} ; then
command sed -rn "/^home:$1/{ s/^home:([^:]*):.*/\1/p}" ${projects}|command sort -u
elif test -s ~/.oscrc; then