Skip to content

add colcon_cd function #1

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

Merged
merged 3 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ dist: trusty
sudo: true
install:
- pip install -U setuptools
# install_requires
- pip install -U git+https://github.com/colcon/colcon-core
- pip install -U git+https://github.com/colcon/colcon-package-information
# tests_require
- pip install -U flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-quotes pep8-naming pylint pytest pytest-cov scspell3k
script:
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ environment:
- PYTHON: "C:\\Python36-x64"
install:
- "%PYTHON%\\python.exe -m pip install -U setuptools"
# install_requires
- "%PYTHON%\\python.exe -m pip install -U git+https://github.com/colcon/colcon-core"
- "%PYTHON%\\python.exe -m pip install -U git+https://github.com/colcon/colcon-package-information"
# tests_require
- "%PYTHON%\\python.exe -m pip install -U flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-quotes pep8-naming pylint pytest pytest-cov scspell3k"
build: off
Expand Down
5 changes: 5 additions & 0 deletions colcon.pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": [
"share/colcon_cd/function/colcon_cd.sh"
]
}
79 changes: 79 additions & 0 deletions function/colcon_cd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# copied from colcon_cd/function/colcon_cd.sh

colcon_cd() {
if [ $# = 0 ]; then
# change the working directory to the previously saved path
if [ "$_colcon_cd_root" = "" ]; then
echo "No previous path saved. Either call 'colcon_cd <pkgname>' from a" \
"directory where <pkgname> can be found or 'colcon_cd --set' to" \
"directly save the current working directory." 1>&2
return 1
fi
if [ "$_colcon_cd_root" != "$(pwd)" ]; then
cd "$_colcon_cd_root"
fi

elif [ $# = 1 ]; then
if [ "$1" = "--set" ]; then
# store the current working directory for future invocations
_colcon_cd_root="$(pwd)"
echo "Saved the current working directory for future invocations of" \
"'colcon_cd <pkgname>' as well as to return to using 'colcon_cd'." \
"Call 'colcon_cd --reset' to unset the saved path."
return 0
elif [ "$1" = "--reset" ]; then
# unset the save path
unset _colcon_cd_root
return 0
fi

_colcon_cd_cmd="colcon list --packages-select $1 --paths-only"

if [ "$_colcon_cd_root" != "" ]; then
# try to find the given package from the saved path
_colcon_cd_pwd="$(pwd)"
cd "$_colcon_cd_root"

_colcon_cd_pkg_path="$(COLCON_LOG_PATH=/dev/null $_colcon_cd_cmd 2> /dev/null)"
if [ $? -eq 0 ] && [ "$_colcon_cd_pkg_path" != "" ]; then
cd "$_colcon_cd_pkg_path"
unset _colcon_cd_pkg_path
unset _colcon_cd_pwd
return 0
fi
unset _colcon_cd_pkg_path

cd "$_colcon_cd_pwd"
unset _colcon_cd_pwd
fi

# try to find the given package from the current working directory
_colcon_cd_pkg_path="$(COLCON_LOG_PATH=/dev/null $_colcon_cd_cmd 2> /dev/null)"
if [ $? -eq 0 ] && [ "$_colcon_cd_pkg_path" != "" ]; then
if [ "$_colcon_cd_root" = "" ]; then
# store the current working directory for future invocations
_colcon_cd_root="$(pwd)"
echo "Saved the directory '$_colcon_cd_root' for future invocations" \
"of 'colcon_cd <pkgname>' as well as to return to using " \
"'colcon_cd'. Call 'colcon_cd --reset' to unset the saved path."
fi
cd "$_colcon_cd_pkg_path"
unset _colcon_cd_pkg_path
return 0
fi
unset _colcon_cd_pkg_path

if [ "$_colcon_cd_root" != "" ]; then
echo "Could neither find package '$1' from '$_colcon_cd_root' nor from" \
"the current working directory" 1>&2
else
echo "Could not find package '$1' from the current working" \
"directory" 1>&2
fi
return 1

else
echo "'colcon_cd' only supports zero or one arguments" 1>&2
return 1
fi
}
8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ long_description = file: README.rst
keywords = colcon

[options]
install_requires =
colcon-core
colcon-package-information
packages = find:
tests_require =
flake8
Expand All @@ -42,6 +45,11 @@ tests_require =
scspell3k>=2.2
zip_safe = true

[options.data_files]
# distutils replaces dashes in keys with underscores
share/colcon_cd/function =
function/colcon_cd.sh

[tool:pytest]
filterwarnings =
error
Expand Down