diff --git a/ros2cli/colcon.pkg b/ros2cli/colcon.pkg index a762fd0cc..b361b7948 100644 --- a/ros2cli/colcon.pkg +++ b/ros2cli/colcon.pkg @@ -1,6 +1,7 @@ { "hooks": [ "share/ros2cli/environment/ros2-argcomplete.bash", + "share/ros2cli/environment/ros2-argcomplete.fish", "share/ros2cli/environment/ros2-argcomplete.zsh" ] } diff --git a/ros2cli/completion/ros2-argcomplete.fish b/ros2cli/completion/ros2-argcomplete.fish new file mode 100644 index 000000000..e72102089 --- /dev/null +++ b/ros2cli/completion/ros2-argcomplete.fish @@ -0,0 +1,19 @@ +# Copyright 2017-2019 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if type register-python-argcomplete3 > /dev/null 2>&1 + eval "register-python-argcomplete3 --shell fish ros2 | source" +else if type register-python-argcomplete > /dev/null 2>&1 + eval "register-python-argcomplete3 --shell fish ros2 | source" +end diff --git a/ros2cli/resource/local_setup.fish b/ros2cli/resource/local_setup.fish new file mode 100644 index 000000000..60333d15a --- /dev/null +++ b/ros2cli/resource/local_setup.fish @@ -0,0 +1,31 @@ +# reduced from ament_package/template/package_level/local_setup.fish.in + +# provide AMENT_CURRENT_PREFIX to shell script +set -l AMENT_CURRENT_PREFIX (cd (dirname (status -f))/../.. && pwd) +# store AMENT_CURRENT_PREFIX to restore it before each environment hook +set -l _package_local_setup_AMENT_CURRENT_PREFIX $AMENT_CURRENT_PREFIX + +# unset AMENT_ENVIRONMENT_HOOKS +# if not appending to them for return +if [ -z "$AMENT_RETURN_ENVIRONMENT_HOOKS"] + set -e AMENT_ENVIRONMENT_HOOKS +end + +# restore AMENT_CURRENT_PREFIX before evaluating the environment hooks +set -l AMENT_CURRENT_PREFIX $_package_local_setup_AMENT_CURRENT_PREFIX +# list all environment hooks of this package +ament_append_value AMENT_ENVIRONMENT_HOOKS "$AMENT_CURRENT_PREFIX/share/ros2cli/environment/ros2-argcomplete.fish" +# source all shell-specific environment hooks of this package +# if not returning them +if [ -z "$AMENT_RETURN_ENVIRONMENT_HOOKS"] + set -l _package_local_setup_IFS $IFS + set -l IFS ":" + for _hook in $AMENT_ENVIRONMENT_HOOKS + # restore AMENT_CURRENT_PREFIX for each environment hook + set AMENT_CURRENT_PREFIX $_package_local_setup_AMENT_CURRENT_PREFIX + # restore IFS before sourcing other files + set IFS $_package_local_setup_IFS + source "$_hook" + end + set IFS $_package_local_setup_IFS +end diff --git a/ros2cli/setup.py b/ros2cli/setup.py index c3f503231..000f962c0 100644 --- a/ros2cli/setup.py +++ b/ros2cli/setup.py @@ -14,10 +14,12 @@ ]), ('share/ros2cli', [ 'resource/local_setup.bash', + 'resource/local_setup.fish', 'resource/local_setup.zsh', ]), ('share/ros2cli/environment', [ 'completion/ros2-argcomplete.bash', + 'completion/ros2-argcomplete.fish', 'completion/ros2-argcomplete.zsh' ]), ],