Skip to content

Commit

Permalink
close #183: support dash, ksh
Browse files Browse the repository at this point in the history
- dorothy:
    - fix possible double-loading on posix shells when .profile is configured
    - use single-quotes when configuring dotfiles, and update find regex to support both
- add `setup-util-dash`
- add `setup-util-ksh`
  • Loading branch information
balupton committed Oct 24, 2023
1 parent a42aefc commit 52dc739
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 95 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/dorothy-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
setup-util-nu
setup-util-xonsh
setup-util-elvish
setup-util-dash
setup-util-ksh
setup-util-carapace
dorothy install
# nu -c 'echo $nu.loginshell-path'
Expand Down Expand Up @@ -75,6 +77,16 @@ jobs:
# continue as normal
command-exists dorothy
echo-style --success='ok'
- name: 'Dorothy Login Shell: dash'
shell: dash -l {0}
run: |
command-exists dorothy
echo-style --success='ok'
- name: 'Dorothy Login Shell: ksh'
shell: ksh -l {0}
run: |
command-exists dorothy
echo-style --success='ok'
- name: 'Trunk Format'
if: github.event_name == 'push'
shell: bash -leo pipefail {0}
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

Dorothy is a dotfile ecosystem featuring:

- seamless support for [Bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>), [Zsh](https://en.wikipedia.org/wiki/Z_shell), [Fish](<https://en.wikipedia.org/wiki/Fish_(Unix_shell)>), [Nu](https://www.nushell.sh), [Xonsh](https://xon.sh), [Elvish](https://elv.sh)
- seamless support for [Bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>), [Zsh](https://en.wikipedia.org/wiki/Z_shell), [Fish](<https://en.wikipedia.org/wiki/Fish_(Unix_shell)>), [Nu](https://www.nushell.sh), [Xonsh](https://xon.sh), [Elvish](https://elv.sh), [Dash](https://wiki.archlinux.org/title/Dash), [KSH](https://en.wikipedia.org/wiki/KornShell)
- seamless support for multiple operating systems and architectures
- seamless support for your favorite terminal and GUI editors
- automatic configuration of your environment variables for what you have installed on your system
Expand Down Expand Up @@ -167,7 +167,7 @@ If your shell doesn't recognize any of the Dorothy commands (you get a command n

- 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](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>), [Zsh](https://en.wikipedia.org/wiki/Z_shell), [Fish](<https://en.wikipedia.org/wiki/Fish_(Unix_shell)>), [Nu](https://www.nushell.sh), [Xonsh](https://xon.sh), [Elvish](https://elv.sh)). [Create an issue requesting support for your shell.](https://github.com/bevry/dorothy/issues)
- Your login shell is not one of the Dorothy supported shells. [Create an issue requesting support for your shell.](https://github.com/bevry/dorothy/issues)

## Overview

Expand All @@ -186,31 +186,31 @@ For each shell that you configured during the Dorothy installation (can be recon

1. The shell loads Dorothy's initialization script:

- [Elvish](https://elv.sh) loads our [`init.elv`](https://github.com/bevry/dorothy/blob/master/init.elv) script
- [Fish](<https://en.wikipedia.org/wiki/Fish_(Unix_shell)>) loads our [`init.fish`](https://github.com/bevry/dorothy/blob/master/init.fish) script
- [Nu](https://www.nushell.sh) loads our [`init.nu`](https://github.com/bevry/dorothy/blob/master/init.nu) script
- [Xonsh](https://xon.sh) loads our [`init.xsh`](https://github.com/bevry/dorothy/blob/master/init.xsh) script
- [Elvish](https://elv.sh) loads our [`init.elv`](https://github.com/bevry/dorothy/blob/master/init.elv) script
- POSIX shells ([Bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>), [Zsh](https://en.wikipedia.org/wiki/Z_shell), etc) load our [`init.sh`](https://github.com/bevry/dorothy/blob/master/init.sh) script
- POSIX shells ([Bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>), [Zsh](https://en.wikipedia.org/wiki/Z_shell), [Dash](https://wiki.archlinux.org/title/Dash), [KSH](https://en.wikipedia.org/wiki/KornShell), etc) load our [`init.sh`](https://github.com/bevry/dorothy/blob/master/init.sh) script

1. The initialization script will:

1. Ensure the `DOROTHY` environment variable is set to the location of the Dorothy installation.

1. If a login shell, it loads our login script `sources/login.(sh|fish|nu|xsh|elv)`, which will:
1. If a login shell, it loads our login script `sources/login.(bash|dash|elv|fish|ksh|nu|xsh|zsh)`, which will:

1. Apply any configuration changes necessary for that login shell
1. Load our environment script `sources/environment.(sh|fish|nu|xsh|elv)`, which will:
1. Load our environment script `sources/environment.(bash|dash|elv|fish|ksh|nu|xsh|zsh)`, which will:

1. Invoke `commands/setup-environment-commands` which determines and applies all necessary environment configuration changes to the shell. It loads your `user/config(.local)/environment.bash` configuration script for your own custom environment configuration that will be applied to all your login shells.

1. If a login and interactive shell, it loads our interactive script `sources/interactive.(sh|fish|nu|xsh|elv)`, which will:
1. If a login and interactive shell, it loads our interactive script `sources/interactive.(bash|dash|elv|fish|ksh|nu|xsh|zsh)`, which will:

1. Load your own `user/config(.local)/interactive.(sh|fish|nu|xsh|elv)` configuration script for your own interactive login shell configuration.
- [Fish](<https://en.wikipedia.org/wiki/Fish_(Unix_shell)>) shell will load `interactive.fish` if it exists, otherwise it will load `interactive.sh`.
1. Load your own `user/config(.local)/interactive.(bash|dash|elv|fish|ksh|nu|xsh|zsh)` configuration script for your own interactive login shell configuration.
- [Elvish](https://elv.sh) will only load `interactive.elv` if it exists.
- [Fish](<https://en.wikipedia.org/wiki/Fish_(Unix_shell)>) will load `interactive.fish` if it exists, otherwise it will load `interactive.sh`.
- [Nu](https://www.nushell.sh) will only load `interactive.nu` and it must exist.
- [Xonsh](https://xon.sh) will only load `interactive.xsh` if it exists.
- [Elvish](https://elv.sh) will only load `interactive.elv` if it exists.
- POSIX shells ([Bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>), [Zsh](https://en.wikipedia.org/wiki/Z_shell), etc) will load their `interactive.(bash|zsh|...etc)` file if it exists, otherwise they will load `interactive.sh` if exists.
- POSIX shells ([Bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>), [Zsh](https://en.wikipedia.org/wiki/Z_shell), [Dash](https://wiki.archlinux.org/title/Dash), [KSH](https://en.wikipedia.org/wiki/KornShell), etc) will load their `interactive.(bash|zsh|...etc)` file if it exists, otherwise they will load `interactive.sh` if exists.
1. Load any common alias and function utilities.
1. Load our theme configuration.
1. Load our ssh configuration.
Expand Down
136 changes: 80 additions & 56 deletions commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -1094,16 +1094,20 @@ function dorothy() (
local item option_clean='no' option_uninstall='no' default_shells=() use_shells=() fodder=''
local supported_shells=(
bash
dash
elvish
fish
ksh
nu
xonsh
zsh
)
local supported_shells_with_labels=(
bash Bash
dash Dash
elvish Elvish
fish Fish
ksh KSH
nu Nu
xonsh Xonsh
zsh Zsh
Expand Down Expand Up @@ -1143,63 +1147,65 @@ function dorothy() (
fi
use_shells+=('bash v3 compat workaround')

# cleanup
if test "$option_clean" = 'yes'; then
rm_deprecated "$HOME/.profile" "$HOME/.bash_profile" "$HOME/.bashrc" "$HOME/.config/fish/config.fish" "$ZDOTDIR/.zshrc" "$ZDOTDIR/.zprofile"
fi

# bash
if is-needle bash "${use_shells[@]}"; then
echo-segment --h3='Configuring Bash'
setup-util-bash

# cleanup
if test "$option_clean" = 'yes'; then
rm_deprecated "$HOME/.profile" "$HOME/.bash_profile" "$HOME/.bashrc"
fi

# mac and raspi ubuntu
config-helper --file="$HOME/.bash_profile" -- \
--find='source ".+?" # Dorothy' --replace="source \"$DOROTHY/init.sh\" # Dorothy"
--find='.+? # Dorothy' --replace="source \"$DOROTHY/init.sh\" # Dorothy"

# vm ubuntu
config-helper --file="$HOME/.bashrc" -- \
--find='source ".+?" # Dorothy' --replace="source \"$DOROTHY/init.sh\" # Dorothy"
--find='.+? # Dorothy' --replace="source \"$DOROTHY/init.sh\" # Dorothy"

echo-segment --g3='Configuring Bash'
else
config-helper --file="$HOME/.bash_profile" -- \
--find='source ".+?" # Dorothy' --replace=''
--find='.+? # Dorothy' --replace=''
config-helper --file="$HOME/.bashrc" -- \
--find='source ".+?" # Dorothy' --replace=''
--find='.+? # Dorothy' --replace=''
fi

# zsh
# https://zsh.sourceforge.io/Intro/intro_3.html
if is-needle zsh "${use_shells[@]}"; then
echo-segment --h3='Configuring Zsh'
setup-util-zsh
mkdir -p "$ZDOTDIR"

# cleanup
if test "$option_clean" = 'yes'; then
rm_deprecated "$ZDOTDIR/.zshrc" "$ZDOTDIR/.zprofile"
fi
# dash
if is-needle dash "${use_shells[@]}"; then
echo-segment --h3='Configuring Dash'
setup-util-dash

# configure
config-helper --file="$ZDOTDIR/.zshrc" -- \
--find='source ".+?" # Dorothy' --replace="source \"$DOROTHY/init.sh\" # Dorothy"
config-helper --file="$HOME/.profile" -- \
--find='.+? # Dorothy' --replace=". \"$DOROTHY/init.sh\" # Dorothy"

config-helper --file="$ZDOTDIR/.zprofile" -- \
--find='source ".+?" # Dorothy' --replace="source \"$DOROTHY/init.sh\" # Dorothy"
echo-segment --g3='Configuring Dash'
elif ! is-needle bash "${use_shells[@]}" && ! is-needle ksh "${use_shells[@]}"; then
config-helper --file="$HOME/.profile" -- \
--find='.+? # Dorothy' --replace=''
fi

config-helper --file="$HOME/.zshenv" -- \
--find='ZDOTDIR=.+' --replace="ZDOTDIR=\"$ZDOTDIR\""
# elvish
if is-needle elvish "${use_shells[@]}"; then
# https://elv.sh/ref/command.html#rc-file
# https://elv.sh/ref/runtime.html
# https://github.com/elves/elvish/issues/1726
echo-segment --h3='Configuring Elvish'
setup-util-elvish
mkdir -p "$HOME/.config/elvish"

echo-segment --g3='Configuring Zsh'
# configure
config-helper --file="$HOME/.config/elvish/rc.elv" -- \
--find='.+? # Dorothy' --replace="eval (cat '$DOROTHY/init.elv' | slurp) # Dorothy"

echo-segment --h3='Configuring Elvish'
else
mkdir -p "$ZDOTDIR"
config-helper --file="$ZDOTDIR/.zshrc" -- \
--find='source ".+?" # Dorothy' --replace=''
config-helper --file="$ZDOTDIR/.zprofile" -- \
--find='source ".+?" # Dorothy' --replace=''
config-helper --file="$HOME/.zshenv" -- \
--find='ZDOTDIR=.+' --replace="ZDOTDIR=\"$ZDOTDIR\""
mkdir -p "$HOME/.config/elvish"
config-helper --file="$HOME/.config/elvish/rc.elv" -- \
--find='.+? # Dorothy' --replace=''
fi

# fish
Expand All @@ -1208,20 +1214,30 @@ function dorothy() (
setup-util-fish
mkdir -p "$HOME/.config/fish"

# cleanup
if test "$option_clean" = 'yes'; then
rm_deprecated "$HOME/.config/fish/config.fish"
fi

# configure
config-helper --file="$HOME/.config/fish/config.fish" -- \
--find='source ".+?" # Dorothy' --replace="source \"$DOROTHY/init.fish\" # Dorothy"
--find='.+? # Dorothy' --replace="source '$DOROTHY/init.fish' # Dorothy"

echo-segment --g3='Configuring Zsh'
else
mkdir -p "$HOME/.config/fish"
config-helper --file="$HOME/.config/fish/config.fish" -- \
--find='source ".+?" # Dorothy' --replace=''
--find='.+? # Dorothy' --replace=''
fi

# ksh
if is-needle ksh "${use_shells[@]}"; then
echo-segment --h3='Configuring KSH'
setup-util-ksh

# configure
config-helper --file="$HOME/.profile" -- \
--find='.+? # Dorothy' --replace=". '$DOROTHY/init.sh' # Dorothy"

echo-segment --g3='Configuring KSH'
elif ! is-needle bash "${use_shells[@]}" && ! is-needle dash "${use_shells[@]}"; then
config-helper --file="$HOME/.profile" -- \
--find='.+? # Dorothy' --replace=''
fi

# nu
Expand All @@ -1231,13 +1247,13 @@ function dorothy() (

# trunk-ignore(shellcheck/SC2016)
config-helper --file="$(nu -c 'echo $nu.loginshell-path')" -- \
--find='source ".+?" # Dorothy' --replace="source \"$DOROTHY/init.nu\" # Dorothy"
--find='.+? # Dorothy' --replace="source '$DOROTHY/init.nu' # Dorothy"

echo-segment --g3='Configuring Nu'
elif command-exists nu; then
# trunk-ignore(shellcheck/SC2016)
config-helper --file="$(nu -c 'echo $nu.loginshell-path')" -- \
--find='source ".+?" # Dorothy' --replace=''
--find='.+? # Dorothy' --replace=''
fi

# xonsh
Expand All @@ -1258,24 +1274,32 @@ function dorothy() (
--find='.+? # Dorothy' --replace=''
fi

# elvish
if is-needle elvish "${use_shells[@]}"; then
# https://elv.sh/ref/command.html#rc-file
# https://elv.sh/ref/runtime.html
# https://github.com/elves/elvish/issues/1726
echo-segment --h3='Configuring Elvish'
setup-util-elvish
mkdir -p "$HOME/.config/elvish"
# zsh
# https://zsh.sourceforge.io/Intro/intro_3.html
if is-needle zsh "${use_shells[@]}"; then
echo-segment --h3='Configuring Zsh'
setup-util-zsh
mkdir -p "$ZDOTDIR"

# configure
config-helper --file="$HOME/.config/elvish/rc.elv" -- \
--find='.+? # Dorothy' --replace="eval (cat '$DOROTHY/init.elv' | slurp) # Dorothy"
config-helper --file="$ZDOTDIR/.zshrc" -- \
--find='.+? # Dorothy' --replace="source '$DOROTHY/init.sh' # Dorothy"

echo-segment --h3='Configuring Elvish'
config-helper --file="$ZDOTDIR/.zprofile" -- \
--find='.+? # Dorothy' --replace="source '$DOROTHY/init.sh' # Dorothy"

config-helper --file="$HOME/.zshenv" -- \
--find='ZDOTDIR=.+' --replace="ZDOTDIR='$ZDOTDIR'"

echo-segment --g3='Configuring Zsh'
else
mkdir -p "$HOME/.config/elvish"
config-helper --file="$HOME/.config/elvish/rc.elv" -- \
mkdir -p "$ZDOTDIR"
config-helper --file="$ZDOTDIR/.zshrc" -- \
--find='.+? # Dorothy' --replace=''
config-helper --file="$ZDOTDIR/.zprofile" -- \
--find='.+? # Dorothy' --replace=''
config-helper --file="$HOME/.zshenv" -- \
--find='ZDOTDIR=.+' --replace="ZDOTDIR='$ZDOTDIR'"
fi

echo-segment --g2='Dorothy Shell Configuration'
Expand Down
29 changes: 29 additions & 0 deletions commands/setup-util-dash
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# https://repology.org/project/dash-shell/versions

function setup_util_dash() (
source "$DOROTHY/sources/bash.bash"

# improve performance
if is-needle --quiet "$@" && ! is-needle --upgrade "$@" && ! is-needle --uninstall "$@" && command-exists dash; then
return 0
fi

# setup
local options=(
--cli='dash'
"$@"
APT='dash' # UBUNTU, not on repology but it exists
APK='dash' # ALPINE
AUR='dash' # ARCH
BREW='dash'
NIX='dash'
)
setup-util "${options[@]}"
)

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
setup_util_dash "$@"
fi
31 changes: 31 additions & 0 deletions commands/setup-util-ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# https://repology.org/project/ksh/versions

function setup_util_ksh() (
source "$DOROTHY/sources/bash.bash"

# improve performance
if is-needle --quiet "$@" && ! is-needle --upgrade "$@" && ! is-needle --uninstall "$@" && command-exists ksh; then
return 0
fi

# setup
local options=(
--cli='ksh'
"$@"
APT='ksh' # UBUNTU
AUR='ksh' # ARCH
BREW='ksh'
EMERGE='app-shells/ksh' # GENTOO
NIX='ksh'
RPM='ksh' # FEDORA
ZYPPER='ksh' # SUSE
)
setup-util "${options[@]}"
)

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
setup_util_ksh "$@"
fi
26 changes: 15 additions & 11 deletions config/shells.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

# Used by `setup-shell`

# Our shells in order of preference
# Shells that Dorothy supports, reorder them with most preferred first
USER_SHELLS=(
fish # fish shell
zsh # Z shell
bash # bourne again shell
nu # nushell
xonsh # python-powered shell
sh # bourne shell
ash # almquist shell
dash # debian almquist shell
ksh # korn shell
hush # hush, an independent implementation of a Bourne shell for BusyBox
# officially supported shells
bash # bourne again shell
dash # debian almquist shell
fish # fish shell
nu # nushell
zsh # Z shell
# officially supported shells (alpha/beta quality integrations)
elvish # elvish shell
ksh # korn shell
xonsh # python-powered shell
# unofficially supported shells
ash # almquist shell
hush # hush, an independent implementation of a Bourne shell for BusyBox
sh # the operating-system symlinks this to any POSIX compliant shell
)
Loading

0 comments on commit 52dc739

Please sign in to comment.