Skip to content

Automatically starting genie on every shell session

b05902132 edited this page Jul 2, 2022 · 4 revisions

I use this code at the top of my .zprofile, which prompts me every time I enter wsl (without specifying a particular command; i.e., just wsl alone) to enter the bottle, or not:

# Are we in the bottle?
if [[ ! -v INSIDE_GENIE ]]; then
  read "yn? * Not inside the genie bottle; enter it?"

  if [[ ${yn[1]} == "y" ]]; then
    echo "Starting genie:"
    exec /usr/bin/genie -s
  fi
fi

If you want to enter the bottle every time, you can replace everything inside the outer if with exec /usr/bin/genie -s. Alternatively, the following:

# Are we in the bottle?
if [[ ! -v INSIDE_GENIE ]]; then
  read -t 3 -q "yn? * Preparing to enter genie bottle (in 3s); abort? "
  echo

  if [[ $yn != "y" ]]; then
    echo "Starting genie:"
    exec /usr/bin/genie -s
  fi
fi

will automatically enter the bottle unless you enter y to abort within three seconds; entering n or waiting for the timeout runs genie.


.bash_profile version

Users having default shell as bash may use this code at the end of .bash_profile, which prompts every time entering wsl (without specifying a particular command; i.e., just wsl alone) to enter the bottle, or not:

# Are we in the bottle?
if [[ -z ${INSIDE_GENIE} ]]; then
  read -p "yn? * Not inside the genie bottle; enter it? " yn
  echo

  if [[ $yn == "y" ]]; then
    echo "Starting genie:"
    exec /usr/bin/genie -s
  fi
fi

If you want to enter the bottle every time, you can replace everything inside the outer if with exec /usr/bin/genie -s. Alternatively, the following:

# Are we in the bottle?
if [[ -z ${INSIDE_GENIE} ]]; then
  read -t 3 -p "yn? * Preparing to enter genie bottle (in 3s); abort? "
  echo

  if [[ $yn != "y" ]]; then
    echo "Starting genie:"
    exec /usr/bin/genie -s
  fi
fi

will automatically enter the bottle unless you enter y to abort within three seconds; entering n or waiting for the timeout runs genie.