Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Fish shell #326

Draft
wants to merge 5 commits into
base: rolling
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ros2cli/colcon.pkg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"hooks": [
"share/ros2cli/environment/ros2-argcomplete.bash",
"share/ros2cli/environment/ros2-argcomplete.fish",
"share/ros2cli/environment/ros2-argcomplete.zsh"
]
}
19 changes: 19 additions & 0 deletions ros2cli/completion/ros2-argcomplete.fish
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using eval and source looks weird - are both really necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The . command is deprecated as the source command is preferred: fish-shell/fish-shell#310
But I suppose the eval might not be needed. I was just mimicking the style in bash file.
Why was eval used there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is the recommended approach described in the argcomplete docs: https://argcomplete.readthedocs.io/en/latest/#synopsis

else if type register-python-argcomplete > /dev/null 2>&1
eval "register-python-argcomplete3 --shell fish ros2 | source"
end
31 changes: 31 additions & 0 deletions ros2cli/resource/local_setup.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# reduced from ament_package/template/package_level/local_setup.fish.in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't exist atm?


# 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
2 changes: 2 additions & 0 deletions ros2cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]),
],
Expand Down