Skip to content

Commit

Permalink
dorothy: prompt for repl shell, and install/configure the repl shell
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Sep 8, 2023
1 parent f1e3d58 commit 441817a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ bash -ic "$(curl -fsSL https://dorothy.bevry.me/run)" -- echo-verbose a b c
To run multiple commands in/from a Dorothy-configured REPL, enter the following line by line:

```bash
# to invoke a configured bash shell, use:
bash -ic "$(curl -fsSL https://dorothy.bevry.me/shell)"
# to invoke a configured fish shell, use:
bash -ic "$(curl -fsSL https://dorothy.bevry.me/shell?shell=fish)"
# to invoke a configured nu shell, use:
bash -ic "$(curl -fsSL https://dorothy.bevry.me/shell?shell=nu)"
# if your shell doesn't recognize any of the above syntax, run `bash -i` then try again

# now you can whatever and how many commands as you'd like, such as:
Expand Down Expand Up @@ -169,9 +164,10 @@ To select your login shell, run `select-shell`.
If packages are failing to install, [go back to the "Prerequisites" section](https://github.com/bevry/dorothy#prerequisites).

If your shell doesn't recognise any of the Dorothy commands (you get a command not found error, or an undefined/unbound variable error), then it could be that:
- Your shell is not running as a login shell. [Verify that your Terminal is running the shell as a login shell.](https://github.com/bevry/dorothy/blob/master/docs/dorothy/dorothy-not-loading.md).
- Dorothy did not configure itself for the shell you use. Re-run the Dorothy installation process, and be sure to configure Dorothy for your shell.
- Your login shell is not one of the Dorothy supported shells (Bash, Zsh, Fish, Nu). [Create an issue requesting support for your shell.](https://github.com/bevry/dorothy/issues)

- Your shell is not running as a login shell. [Verify that your Terminal is running the shell as a login shell.](https://github.com/bevry/dorothy/blob/master/docs/dorothy/dorothy-not-loading.md).
- Dorothy did not configure itself for the shell you use. Re-run the Dorothy installation process, and be sure to configure Dorothy for your shell.
- Your login shell is not one of the Dorothy supported shells (Bash, Zsh, Fish, Nu). [Create an issue requesting support for your shell.](https://github.com/bevry/dorothy/issues)

## Overview

Expand Down
25 changes: 16 additions & 9 deletions commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ function dorothy() (
# default to [shell=bash] instead of [sh] as [sh] is [dash] on ubuntu, and [dash] doesn't support the [--...] args
function act_shell {
# process arguments
local item shell='bash' theme=''
local item shell='' theme=''
while test "$#" -ne 0; do
item="$1"
shift
Expand All @@ -1242,13 +1242,18 @@ function dorothy() (
assert_dorothy_configured
ensure_minimal_dependencies

# compatibility
if command_missing "$shell"; then
echo-error 'Cannot use --shell=' --invert="$shell" ' as that shell is not available on this system.'
return 3 # ESRCH 3 No such process
# ask
if test -z "$shell"; then
shell="$(
choose-option --required \
--question='Which shell to use?' \
-- bash fish nu
)"
fi

# act, installing the shell if it is missing
if test "$shell" = 'bash'; then
setup-util-bash --quiet
# [bash --rcfile] works but not within a [--rcfile]
# [--login] ignores [--rcfile]
# this is not a true login shell, as [$0] is not [-bash], as such loading [init.sh] is incompatible
Expand All @@ -1260,29 +1265,31 @@ function dorothy() (
DOROTHY_LOADED=no
DOROTHY_THEME_OVERRIDE='$theme'
. '$DOROTHY/init.sh'
echo-style 'Your are now using the ' --code='$ACTIVE_POSIX_SHELL' ' shell with Dorothy loaded from ' --code='$DOROTHY' \$'\n' 'Use the ' --code='exit' ' command to return to your parent shell.' \$'\n' 'Use ' --code='ls $DOROTHY/commands' ' to see available commands.'
echo-style 'Your are now using the ' --invert='$ACTIVE_POSIX_SHELL' ' shell with Dorothy loaded from ' --code='$DOROTHY' \$'\n' 'Use the ' --code='exit' ' command to return to your parent shell.' \$'\n' 'Use ' --code='ls $DOROTHY/commands' ' to see available commands.'
EOF
)
elif test "$shell" = 'nu'; then
setup-util-nu --quiet # this is necessary for nushell, even if installed, as it requires all config files to exist prior
"$shell" --interactive --login --no-config-file --execute "$(
cat <<-EOF
#!/usr/bin/env nu
\$env.DOROTHY_THEME_OVERRIDE = '$theme'
source '$DOROTHY/init.nu'
echo-style 'Your are now using the ' --code=nu ' shell with Dorothy loaded from ' --code='$DOROTHY' "\n" 'Use the ' --code='exit' ' command to return to your parent shell.' "\n" 'Use ' --code='ls $DOROTHY/commands' ' to see available commands.'
echo-style 'Your are now using the ' --invert='nu' ' shell with Dorothy loaded from ' --code='$DOROTHY' "\n" 'Use the ' --code='exit' ' command to return to your parent shell.' "\n" 'Use ' --code='ls $DOROTHY/commands' ' to see available commands.'
EOF
)"
elif test "$shell" = 'fish'; then
setup-util-fish --quiet
"$shell" --interactive --login --no-config --init-command="$(
cat <<-EOF
#!/usr/bin/env fish
set DOROTHY_THEME_OVERRIDE '$theme'
source '$DOROTHY/init.fish'
echo-style 'Your are now using the ' --code=fish ' shell with Dorothy loaded from ' --code='$DOROTHY' \n 'Use the ' --code='exit' ' command to return to your parent shell.' \n 'Use ' --code='ls $DOROTHY/commands' ' to see available commands.'
echo-style 'Your are now using the ' --invert='fish' ' shell with Dorothy loaded from ' --code='$DOROTHY' \n 'Use the ' --code='exit' ' command to return to your parent shell.' \n 'Use ' --code='ls $DOROTHY/commands' ' to see available commands.'
EOF
)"
else
echo-error 'Cannot use --shell=' --invert="$shell" ' as that shell does not support REPLs with custom configuration.'
echo-error 'Cannot use ' --invert="$shell" ' as that shell does not support REPLs with custom configuration.'
return 93 # EPROTONOSUPPORT 93 Protocol not supported
fi
}
Expand Down

0 comments on commit 441817a

Please sign in to comment.