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

Persist bash history in devcontainer #4389

Closed
Closed
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
6 changes: 6 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"source": "overlay-${devcontainerId}",
"target": "/opt/overlay_ws",
"type": "volume"
},
{
"source": "nav2-bashhistory",
"target": "/commandhistory",
Copy link
Member

Choose a reason for hiding this comment

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

When I overhaul the user account setup for the devcontainer, we can track such dot files easier than using root level paths.

"type": "volume"
}
],
"features": {
Expand All @@ -50,6 +55,7 @@
"settings": {},
"extensions": [
"althack.ament-task-provider",
"mhutchie.git-graph",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"GitHub.copilot",
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ RUN apt-get update && \
# source underlay for shell
RUN echo 'source "$UNDERLAY_WS/install/setup.bash"' >> /etc/bash.bashrc

COPY tools/nav2_bashrc /root/nav2_bashrc
RUN echo "source /root/nav2_bashrc" >> /root/.bashrc

# multi-stage for caddy
FROM caddy:builder AS caddyer

Expand Down
13 changes: 13 additions & 0 deletions tools/nav2_bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
OVERLAY_DIR=/opt/overlay_ws

OVERLAY=$OVERLAY_DIR/install/setup.bash
UNDERLAY=/opt/ros/${ROS_DISTRO}/setup.bash
if [ -f "$OVERLAY" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

Don't think we should add this kind of logic to a one off script. Let's add an alias to the .bashrc instead, as we still may need to open a shell without automatically sourcing a workspace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as we still may need to open a shell without automatically sourcing a workspace

I'm curious to know which use cases would be affected by the auto-sourcing of the workspace?

Adding an alias to the bashrc doesn't add much more value to manually doing it (once it's done once and in the bash history, it's easy to pull up).

source $OVERLAY
else
source $UNDERLAY
fi

# https://code.visualstudio.com/remote/advancedcontainers/persist-bash-history
Copy link
Member

Choose a reason for hiding this comment

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

I see the vscode docs recommends to bake this into the Dockerfile, but I think that's just adds unnecessary opportunities to bust the docker layer cache when it doesn't have to. Please add such user session config to the postCreateCommand where we already manage things like .bashrc.

# Enable autocomplete for user
cp /etc/skel/.bashrc ~/

export PROMPT_COMMAND='history -a'
export HISTFILE=/commandhistory/.nav2_bash_history
Loading