NGEET / fates-tutorial

Repository for FATES tutorial and related documentation
0 stars 2 forks source link

cd command issue - possible solution #56

Closed jamedina09 closed 1 month ago

jamedina09 commented 1 month ago

Minor minor bug:

I've just came across the 'cd' behaviour inside docker (Greg mentioned this before). This is minor as users can type type 'cd /' to go to the root directory. But it would be nice (I think) to have the default behaviour of 'cd' to go to the root directory.

Showing the issue with the 'cd' command in the Docker container

Start the Docker Compose services in detached mode

docker compose up -d

Access the running Docker container with an interactive bash shell

docker exec -it elm-fates /bin/bash

Navigate to a directory within the container

cd tools/

Possible solution to make the 'cd' command return to the root directory when no arguments are given

Open a new terminal and access the Docker container again

docker exec -it elm-fates /bin/bash

Edit the user's .bashrc file with vim

vim ~/.bashrc

Enter Insert Mode in vim

i

Add a custom cd function to .bashrc

cd() {
    if [ -z "$1" ]; then
        builtin cd /
    else
        builtin cd "$1"
    fi
}

Exit Insert Mode

Esc

Save and exit vim

:wq

Apply the changes made to .bashrc

source ~/.bashrc

Navigate to a directory within the container again

cd tools/

Change to the home directory (this should now take you to the root directory)

cd

Success:

glemieux commented 1 month ago

This looks like a great workaround for the time being. Thanks @jamedina09. I'm going to build it into the image and have the attendees repull the fates container on Monday. I've made a commit to the tutorial-containers repo to add this: https://github.com/NGEET/tutorial-containers/commit/724809582d0e97e0e4a7fd9afa2b62ea8df4223c. I'll give you a heads up once I rebuild and push it to dockerhub

glemieux commented 1 month ago

New build is up on dockerhub and should be working. I'm testing it with the bci run script now.

glemieux commented 1 month ago

Build looks good. The new cd function appears to work as expected!

jamedina09 commented 1 month ago

I just tested it too. It works smoothly. Thanks.