Skip to content

Commit

Permalink
Configure atmos auto-completion, verify host filesystem detection (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored Jan 24, 2022
1 parent ac1d453 commit 8f987c7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
20 changes: 16 additions & 4 deletions rootfs/etc/profile.d/_workdir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ function _file_device() {
# Intended to support files on user-defined bind mounts in addition to `/localhost`.
# This function is run by the command line prompt setup, so it should be very fast.
# Therefore we cache some info in the environment.
if df -a | grep -q /localhost; then
if [[ $GEODESIC_LOCALHOST_DEVICE == "disabled" ]]; then
red "# Host filesystem device detection disabled."
elif df -a | grep -q /localhost; then
export GEODESIC_LOCALHOST_DEVICE=$(_file_device /localhost)
if [[ $GEODESIC_LOCALHOST_DEVICE == $(_file_device /) ]]; then
red "# Host filesystem device detection failed. Falling back to \"path starts with /localhost\"."
GEODESIC_LOCALHOST_DEVICE="same-as-root"
fi
else
export GEODESIC_LOCALHOST_MISSING=true
export GEODESIC_LOCALHOST_DEVICE="missing"
fi

function file_on_host() {
[[ $GEODESIC_LOCALHOST_MISSING != "true" ]] && [[ $(_file_device "$1") == ${GEODESIC_LOCALHOST_DEVICE} ]]
if [[ $GEODESIC_LOCALHOST_DEVICE =~ ^(disabled|missing)$ ]]; then
return 1
elif [[ $GEODESIC_LOCALHOST_DEVICE == "same-as-root" ]]; then
[[ $(readlink -e "$1") =~ ^/localhost(/.*)?$ ]]
else
[[ $(_file_device "$1") == ${GEODESIC_LOCALHOST_DEVICE} ]]
fi
}

function _default_initial_wd() {
Expand All @@ -40,7 +52,7 @@ if [[ -d $GEODESIC_WORKDIR ]]; then
[[ $SHLVL == 1 ]] && green "# Initial working directory configured as ${GEODESIC_WORKDIR}"
else
if [[ -d $GEODESIC_HOST_CWD ]]; then
if [[ -n $LOCAL_HOME ]] && $(file_on_host "$GEODESIC_HOST_CWD"); then
if [[ -n $LOCAL_HOME ]] && { [[ $GEODESIC_LOCALHOST_DEVICE == "disabled" ]] || $(file_on_host "$GEODESIC_HOST_CWD"); }; then
export GEODESIC_WORKDIR=$(readlink -e "${GEODESIC_HOST_CWD}")
green "# Initial working directory set from host CWD to ${GEODESIC_WORKDIR}"
else
Expand Down
13 changes: 8 additions & 5 deletions rootfs/etc/profile.d/atmos.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

function _configure_atmos_base_path() {
function atmos_configure_base_path() {
# Leave $ATMOS_BASE_PATH alone if it is already set
if [[ -n $ATMOS_BASE_PATH ]]; then
if [[ $SHLVL == 1 ]]; then
Expand Down Expand Up @@ -31,8 +31,11 @@ function _configure_atmos_base_path() {
yellow "# No candidate for ATMOS_BASE_PATH found, leaving it unset"
}

# Only configure ATMOS_BASE_PATH if we find an `atmos` executable,
# but otherwise leave the function available for the user to call explicitly.
# Only configure ATMOS_BASE_PATH if we find an `atmos` executable.
# Leave the function available for the user to call explicitly.
# NOTE: If we start shipping `atmos` with Geodesic by default, change this to
# [[ -f /usr/local/etc/atmos/atmos.yaml ]] && _configure_atmos_base_path
command -v atmos >/dev/null && _configure_atmos_base_path && unset -f _configure_atmos_base_path
# if [[ -f /usr/local/etc/atmos/atmos.yaml ]]; then
if command -v atmos >/dev/null; then
atmos_configure_base_path
source <(atmos completion bash) || echo error setting up atmos auto-completion
fi
2 changes: 1 addition & 1 deletion rootfs/etc/profile.d/banner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BANNER_FONT="${BANNER_FONT:-Nancyj.flf}" # " IDE parser fix

if [ "${SHLVL}" == "1" ]; then
function _check_support() {
[[ $(arch) != "x86_64" ]] || grep -qs GenuineIntel /proc/cpuinfo && return
[[ $(arch) != "x86_64" ]] || grep -qsE 'GenuineIntel|AuthenticAMD' /proc/cpuinfo && return
echo
echo
red '**********************************************************************'
Expand Down

0 comments on commit 8f987c7

Please sign in to comment.