-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"hooks": [ | ||
"share/colcon_cd/function/colcon_cd.sh" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
dirk-thomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if [ "$_colcon_cd_root" != "" ]; then | ||
# try to find the given package from the saved path | ||
_colcon_cd_pwd="$(pwd)" | ||
cd "$_colcon_cd_root" | ||
dirk-thomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
_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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.