From e11b49e2f1473285ed1a5b2d775c7cdad8b5c6d0 Mon Sep 17 00:00:00 2001 From: Fabian Vogt Date: Fri, 13 Mar 2020 15:32:03 +0100 Subject: [PATCH 1/2] Fetch list of all projects lazily Currently osc takes a long time to complete, which is incredibly annoying. Only run "osc ls" if it is necessary for proper completion. --- dist/osc.complete | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/dist/osc.complete b/dist/osc.complete index 8ca3afd5..18245d21 100755 --- a/dist/osc.complete +++ b/dist/osc.complete @@ -132,18 +132,21 @@ if test -n "$alias" ; then command="$command -A $alias" fi -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 - if tmp=$(mktemp ${projects}.XXXXXX) ; then - command ${command} ls / >| $tmp - mv -uf $tmp ${projects} - fi +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 + if tmp=$(mktemp ${projects}.XXXXXX) ; then + command ${command} ls / >| $tmp + mv -uf $tmp ${projects} + fi + fi + else + command ${command} ls / >| "${projects}" fi -else - command ${command} ls / >| "${projects}" -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 From ee44164bf1a8dc2de31066db253d82d4d57a4acd Mon Sep 17 00:00:00 2001 From: Fabian Vogt Date: Fri, 13 Mar 2020 15:36:08 +0100 Subject: [PATCH 2/2] Discard stderr of the completion script Otherwise it pollutes the terminal with warnings and errors such as "interrupted!", which makes the terminal line unusable. --- dist/osc.complete | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dist/osc.complete b/dist/osc.complete index 18245d21..3f1de663 100755 --- a/dist/osc.complete +++ b/dist/osc.complete @@ -26,6 +26,9 @@ typeset -i remove typeset -i colon typeset -r OIFS="$IFS" +# Do not pollute the terminal session with warnings or errors +exec 2>/dev/null + if test "/proc/$PPID/exe" -ef /bin/tcsh ; then export COMP_TYPE=63 export COMP_KEY=9