Skip to content

Commit

Permalink
fix dorothy theme for nushell
Browse files Browse the repository at this point in the history
- config-helper: include test for $
- echo-escape-regex-replacement: escape $
- setup-util-nushell: fix bad hashbang
- dorothy: theme editing for nushell
- config.bash: support `nu` extension
  • Loading branch information
balupton committed Aug 18, 2023
1 parent c6c4767 commit 18e6851
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
9 changes: 9 additions & 0 deletions commands/config-helper
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ function config_helper_test() (
eval_tester --name='tcv2' --stdout=$'a=\'double "quote" inside\'\n\tb=(\n\t\t\'double "quote" inside\'\t"single \'quote\' inside"\n\t\t\'3\'\t\'4\'\n\t)\naa="single \'quote\' inside"\nbb=(\n\t\'more double "quote" inside\'\t"more single \'quote\' inside"\n\t\'33\'\t\'44\'\n)' \
-- cat "$file"

# test values with dollar signs and backslashes
printf '%s\n' '$env.VALUE="hello\world"' >"$file"
# trunk-ignore-all(shellcheck/SC2016)
eval_tester --name='tcv1' \
-- config-helper --file="$file" -- \
--string-find='$env.VALUE' --string-replace='$env.VALUE="HELLO\WORLD"'
eval_tester --name='tcv2' --stdout='$env.VALUE="HELLO\WORLD"' \
-- cat "$file"

# done
echo-segment --g1="TEST: $0"
)
Expand Down
7 changes: 6 additions & 1 deletion commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,12 @@ function dorothy() (
source "$DOROTHY/sources/config.bash"
update_dorothy_user_config 'interactive.sh' -- \
--find='export DOROTHY_THEME=(.*)' --replace="export DOROTHY_THEME=$(echo-quote "$theme")"
# config-edit --file="$DOROTHY/user/config/interactive.nu" --needle="\$env.DOROTHY_THEME" --line="\$env.DOROTHY_THEME = $(echo-quote "$theme")" --add
if test -f "$DOROTHY/user/config/interactive.nu"; then
# update_dorothy_user_config 'interactive.nu' -- --string-find="\$env.DOROTHY_THEME" --string-replace="\$env.DOROTHY_THEME = $(echo-quote "$theme")"
# ^ don't use that, as theming will always be in the config not config.local
# ^ at some point, update_dorothy_user_config should use [config-edit]
config-edit --file="$DOROTHY/user/config/interactive.nu" --needle="\$env.DOROTHY_THEME" --line="\$env.DOROTHY_THEME = $(echo-quote "$theme")" --add
fi

# log
echo-style --success='Configuration change applied, ' --notice='restart your terminal for the change to take effect.'
Expand Down
5 changes: 3 additions & 2 deletions commands/echo-escape-regex-replacement
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ function echo_escape_backslash() (
echo-escape-regex-replacement 'Special: \040b'
Special: \\\\040b
Hello \$\$world. Special: \\\\040b
# exit status: 0
echo-escape-regex-replacement 'Special: \040b' | echo-escape-regex-replacement
Special: \\\\040b
Hello \$\$world. Special: \\\\040b
# exit status: 0
EOF
Expand All @@ -31,6 +31,7 @@ function echo_escape_backslash() (
function on_input {
local value="$1"
value="${value//\\/\\\\}"
value="${value//$/\$$}" # https://github.com/chmln/sd/issues/129
printf '%s\n' "$value"
}

Expand Down
4 changes: 2 additions & 2 deletions commands/setup-util-nushell
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ function setup_util_nushell() (
# ensure [sources/interactive.nu] works
if test ! -f "$DOROTHY/user/config.local/interactive.nu"; then
cat <<-EOF >"$DOROTHY/user/config.local/interactive.nu"
#!/usr/bin/env env
#!/usr/bin/env nu
# load the dorothy defaults
source ~/.local/share/dorothy/config/interactive.nu
EOF
fi
if test ! -f "$DOROTHY/user/config/interactive.nu"; then
cat <<-EOF >"$DOROTHY/user/config/interactive.nu"
#!/usr/bin/env env
#!/usr/bin/env nu
# load my public configuration
source ../config/interactive.nu
Expand Down
29 changes: 19 additions & 10 deletions sources/config.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
source "$DOROTHY/sources/config.sh"

# @todo this should be moved into [commands/dorothy] or at last be its own command
# as [config-edit], [config-helper], are all doubling up on this

# todo
# if test \"\$(get-hostname)\" = '$(get-hostname)'; then

Expand Down Expand Up @@ -112,7 +115,7 @@ function update_dorothy_user_config {
# check extension
local dorothy_config_extension # this is used later too
dorothy_config_extension="$(fs-extension -- "$dorothy_config_filename")"
if ! [[ $dorothy_config_extension =~ bash|zsh|sh|fish ]]; then
if ! [[ $dorothy_config_extension =~ bash|zsh|sh|fish|nu ]]; then
help "The file extension of [$dorothy_config_filename] is not yet supported."
fi

Expand All @@ -139,30 +142,36 @@ function update_dorothy_user_config {
local dorothy_config_default="$DOROTHY/config/$dorothy_config_filename"
if test -f "$dorothy_config_default"; then
if test "$dorothy_config_template" = 'default'; then
# copy the entire template
# copy the entire template
cp "$dorothy_config_default" "$dorothy_config_filepath"
else
# copy only the header
echo-before-blank --append=$'\n' "$dorothy_config_default" >"$dorothy_config_filepath"
fi
else
# default missing, make it with the typical header
# even the dorothy default is missing
cat <<-EOF >"$dorothy_config_filepath"
#!/usr/bin/env $dorothy_config_extension
# do not use \`export\` keyword in this file:
# shellcheck disable=SC2034
EOF
fi

# add the source of the default file
if test "$dorothy_config_source" = 'default'; then
# use `.` over `source` as must be posix, in case we are saving a .sh file
cat <<-EOF >>"$dorothy_config_filepath"
# Load the default configuration file
. "\$DOROTHY/config/${dorothy_config_filename}"
if test "$dorothy_config_extension" = 'nu'; then
cat <<-EOF >>"$dorothy_config_filepath"
# load the dorothy defaults
source ~/.local/share/dorothy/config/${dorothy_config_filename}
EOF
EOF
else
# use `.` over `source` as must be posix, in case we are saving a .sh file
cat <<-EOF >>"$dorothy_config_filepath"
# load the dorothy defaults
. "\$DOROTHY/config/${dorothy_config_filename}"
EOF
fi
fi

# add the new file to the paths
Expand Down

0 comments on commit 18e6851

Please sign in to comment.