Skip to content

Commit fd4dd9a

Browse files
baluptonmolleweide
andcommitted
WIP: continue work on new setup-shell experience (part 2)
/continues f53c564 echo-unique: - new command that supports arguments, and stdin content without sorting choose: - fix ctrl+c not returning to default screen buffer dorothy, fs-relocate: - fix bad refactor of last commit echo-file: - don't output separator between files, as we don't want that in all use cases git-helper: - add `--no-confirm-solo` to protocol prompt - add repository details to all sensible prompts setup-shell: - fix the broken implementation of before - add installed and configured shell detection and use it when merging with preferences - add version detection - don't crash on unconfigurable shells - improved formatting - fix crash on deconfigure setup-util: - lint remaining todos: - [ ] config-helper sudo escalation - [ ] find out why xonsh is not getting installed - [ ] find out why all the shells aren't be configured correctly - [ ] save configuration updates Co-authored-by: hjalmar jakobsson <[email protected]>
1 parent e8fd8e4 commit fd4dd9a

17 files changed

+327
-149
lines changed

Diff for: commands.beta/itunes-owners

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function itunes_owners() (
8989

9090
# extract
9191
local owners owner_count owned_count
92-
owners="$(cut -f1 -s -- "$owner_list" | sort | uniq)"
92+
owners="$(cut -f1 -s -- "$owner_list" | echo-unique --stdin)"
9393
owner_count="$(__print_lines "$owners" | wc -l | xargs)"
9494
owned_count="$(wc -l <"$owner_list" | xargs)"
9595

Diff for: commands/brew-installed

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function brew_installed() (
115115
if [[ $option_quiet == 'yes' ]]; then
116116
"${brew_list_cmd[@]}" &>/dev/null
117117
else
118-
"${brew_list_cmd[@]}" | cut -d' ' -f1 | sort | uniq
118+
"${brew_list_cmd[@]}" | cut -d' ' -f1 | echo-unique --stdin
119119
fi
120120
}
121121

Diff for: commands/choose

+8-9
Original file line numberDiff line numberDiff line change
@@ -1261,22 +1261,22 @@ function choose_() (
12611261
mapfile -t items_renders < <(get-array "$items_count")
12621262
mapfile -t items_rows < <(get-array "$items_count")
12631263
# paging support is eternal, so no need for future updates if disabled
1264-
function show_cursor {
1264+
function reset_terminal_modifications_now {
12651265
:
12661266
}
1267-
function show_cursor_on_exit {
1267+
function reset_terminal_modifications_on_exit {
12681268
:
12691269
}
12701270
function refresh_terminal_size {
12711271
:
12721272
}
12731273
else
1274-
function show_cursor {
1275-
__print_string "$style__show_cursor" >"$terminal_device_file"
1274+
function reset_terminal_modifications_now {
1275+
__print_string "$style__show_cursor$style__default_screen_buffer" >"$terminal_device_file"
12761276
trap - EXIT
12771277
}
1278-
function show_cursor_on_exit {
1279-
trap show_cursor EXIT
1278+
function reset_terminal_modifications_on_exit {
1279+
trap reset_terminal_modifications_now EXIT
12801280
}
12811281
# paging support is eternal, so we need to refresh if enabled
12821282
function refresh_terminal_size {
@@ -2191,7 +2191,7 @@ function choose_() (
21912191
function handle_menu {
21922192
local input read_status keys skips
21932193
# action
2194-
show_cursor_on_exit
2194+
reset_terminal_modifications_on_exit
21952195
__print_string "$style__alternative_screen_buffer" >"$terminal_device_file"
21962196
while :; do
21972197
# (re-)render the menu?
@@ -2365,8 +2365,7 @@ function choose_() (
23652365
break
23662366
fi
23672367
done
2368-
show_cursor
2369-
__print_string "$style__default_screen_buffer" >"$terminal_device_file"
2368+
reset_terminal_modifications_now
23702369
}
23712370

23722371
# select the defaults

Diff for: commands/dorothy-config

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ function dorothy_config() (
444444
# update configuration if necessary
445445
if [[ $reconfigure == 'yes' ]]; then
446446
dorothy-config "$option_filename" --prefer="$option_prefer" --reason="$reason" -- \
447-
--field="$option_packages_var" --array="$(__print_lines "${revised_items[@]}" | sort --ignore-case | uniq)" \
448-
--field='SETUP_UTILS' --array="$(__print_lines "${SETUP_UTILS[@]}" | sort --ignore-case | uniq)"
447+
--field="$option_packages_var" --array="$(echo-unique --ignore-case -- "${revised_items[@]}")" \
448+
--field='SETUP_UTILS' --array="$(echo-unique --ignore-case -- "${SETUP_UTILS[@]}")"
449449
fi
450450

451451
# output the revised items, so that the caller has them

Diff for: commands/echo-file

+1-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function echo_file() (
8585
fi
8686

8787
if [[ $option_trim == 'yes' && $option_raw != 'yes' ]]; then
88-
help "The --trim option requires --raw."
88+
help 'The --trim option requires --raw.'
8989
fi
9090

9191
# =====================================
@@ -147,7 +147,6 @@ function echo_file() (
147147
fi
148148
}
149149

150-
151150
if [[ $option_raw == 'yes' ]]; then
152151
function echo_file {
153152
local file="$1"
@@ -209,9 +208,6 @@ function echo_file() (
209208
file="$1"
210209
shift
211210
echo_file "$file"
212-
if [[ $# -ne 0 ]]; then
213-
__print_lines '' ''
214-
fi
215211
done
216212
}
217213

Diff for: commands/echo-regexp

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function echo_regexp() (
146146
-n | --newline | --newlines
147147
Separate matches with newlines.
148148
-q | --quiet
149-
Do not output anything, returning failure exit status if no matches.
149+
Do not output anything, returning failure exit status if no matches. Implied --fail.
150150
-v | --verbose
151151
When counting, output matches.
152152
-f | --fail

Diff for: commands/echo-unique

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
3+
function echo_unique() (
4+
source "$DOROTHY/sources/stdinargs.bash"
5+
6+
# =====================================
7+
# Arguments
8+
9+
function help {
10+
cat <<-EOF >/dev/stderr
11+
ABOUT:
12+
Output each input that is unique, in their original order, without the need to sort beforehand.
13+
14+
USAGE:
15+
echo-unique [...options] [--] ...<input>
16+
echo-lines ...<input> | echo-unique [...options]
17+
18+
OPTIONS:
19+
--ignore-case
20+
If provided, ignore case when comparing lines.
21+
22+
EXAMPLES:
23+
24+
echo-unique -- a c e a b a b
25+
26+
a
27+
c
28+
e
29+
b
30+
# exit status: 0
31+
32+
echo-lines -- a c e a b a b | echo-unique
33+
34+
a
35+
c
36+
e
37+
b
38+
# exit status: 0
39+
40+
EOF
41+
if [[ $# -ne 0 ]]; then
42+
echo-error "$@"
43+
fi
44+
return 22 # EINVAL 22 Invalid argument
45+
}
46+
47+
# process
48+
local item option_ignore_case='no' option_args=()
49+
while [[ $# -ne 0 ]]; do
50+
item="$1"
51+
shift
52+
case "$item" in
53+
'--help' | '-h') help ;;
54+
'--stdin') : ;; # already the case
55+
'--ignore-case') option_ignore_case='yes' ;;
56+
'--')
57+
option_args+=("$@")
58+
shift $#
59+
break
60+
;;
61+
'--'*) help "An unrecognised flag was provided: $item" ;;
62+
*) option_args+=("$item") ;;
63+
esac
64+
done
65+
66+
# =====================================
67+
# Action
68+
69+
local bin_gawk_or_awk
70+
bin_gawk_or_awk="$(echo-gnu-command --install -- gawk)"
71+
72+
function do_uniq {
73+
if [[ $option_ignore_case == 'yes' ]]; then
74+
"$bin_gawk_or_awk" '!seen[tolower($0)]++'
75+
else
76+
"$bin_gawk_or_awk" '!seen[$0]++'
77+
fi
78+
}
79+
80+
if [[ ${#option_args[@]} -ne 0 ]]; then
81+
__print_lines "${option_args[@]}" | do_uniq
82+
else
83+
do_uniq
84+
fi
85+
)
86+
87+
# fire if invoked standalone
88+
if [[ $0 == "${BASH_SOURCE[0]}" ]]; then
89+
echo_unique "$@"
90+
fi

Diff for: commands/git-helper

+10-10
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ function git_helper() (
203203
__print_lines "$protocol"
204204
else
205205
load_protocols
206-
choose --required \
207-
--question='Which git protocol to use?' \
206+
choose --required --no-confirm-solo \
207+
--question'Which git protocol to use on the repository?' --question="$option_path" \
208208
--default="$protocol" -- "${protocols[@]}"
209209
fi
210210
}
@@ -232,14 +232,14 @@ function git_helper() (
232232
fi
233233
}
234234
function get_remote_name {
235-
local remote="${1-}" question="${2:-"Which remote to use?"}" remotes
235+
local remote="${1-}" question="${2:-"Which remote to use on the repository?"}" remotes
236236
if [[ -n $remote ]]; then
237237
__print_lines "$remote"
238238
else
239239
# assume verified
240240
mapfile -t remotes < <(get_remotes)
241241
choose --required --no-confirm-solo \
242-
--question="$question" \
242+
--question="$question" --question="$option_path" \
243243
-- "${remotes[@]}"
244244
fi
245245
}
@@ -331,7 +331,7 @@ function git_helper() (
331331
if [[ -z $file ]]; then
332332
help 'has-remote-file: requires <file>'
333333
fi
334-
remote="$(get_remote_name "$remote" "Which remote to check for $file?")"
334+
remote="$(get_remote_name "$remote" "Which remote on the repository to check for $file?")"
335335
git cat-file -e "$remote:$file" 2>/dev/null
336336
return
337337
}
@@ -350,7 +350,7 @@ function git_helper() (
350350
if [[ -z $file ]]; then
351351
help 'get-remote-file: requires <file>'
352352
fi
353-
remote="$(get_remote_name "$remote" "Which remote to get $file?")"
353+
remote="$(get_remote_name "$remote" "Which remote on the repository to get $file?")"
354354
git cat-file -p "$remote:$file" 2>/dev/null
355355
return
356356
}
@@ -443,8 +443,8 @@ function git_helper() (
443443
mapfile -t emails < <(git shortlog --summary --email | echo-regexp -ong --regexp='<(.+?)>' --replace='$1')
444444

445445
old_email="$(
446-
choose --linger --required \
447-
--question='Which email to update?' \
446+
choose --linger --required --no-confirm-solo \
447+
--question='Which email to update from the repository?' --question="$option_path" \
448448
--default="$old_email" \
449449
-- "${emails[@]}"
450450
)"
@@ -545,7 +545,7 @@ function git_helper() (
545545

546546
function update_protocol {
547547
local remote="${1-}" protocol="${2-}"
548-
remote="$(get_remote_name "$remote" 'Which remote to configure?')"
548+
remote="$(get_remote_name "$remote" 'Which remote to configure on the repository?')"
549549
protocol="$(get_protocol "$protocol")"
550550

551551
# process
@@ -680,7 +680,7 @@ function git_helper() (
680680
done
681681

682682
# ensure remote in case it was empty
683-
option_remote_name="$(get_remote_name "$option_remote_name" 'Which remote to pull?')"
683+
option_remote_name="$(get_remote_name "$option_remote_name" 'Which remote to pull on the repository?')"
684684

685685
# helper
686686
local PULL_OUTPUT_FILE

Diff for: commands/setup-environment-commands

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ add_prefix_dir /usr/local
215215
export ZDOTDIR
216216
if [[ -z ${ZDOTDIR-} ]]; then
217217
if [[ $PREFER_XDG == 'yes' ]]; then
218-
ZDOTDIR="$XDG_CONFIG_HOME/zsh"
218+
ZDOTDIR="$XDG_CONFIG_HOME/zsh"
219219
elif [[ $PREFER_XDG == 'no' ]]; then
220-
ZDOTDIR="$HOME"
220+
ZDOTDIR="$HOME"
221221
fi
222222
fi
223223

Diff for: commands/setup-linux

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ function setup_linux() (
7676
APT_INSTALL+=("${APT_ADD[@]}")
7777
dorothy-config 'setup.bash' -- \
7878
--field='APT_ADD' --replace= \
79-
--field='APT_INSTALL' --array="$(__print_lines "${APT_INSTALL[@]}" | sort --ignore-case | uniq)"
79+
--field='APT_INSTALL' --array="$(echo-unique --ignore-case -- "${APT_INSTALL[@]}")"
8080
fi
8181
if [[ ${#APT_REMOVE[@]} -ne 0 ]]; then
8282
APT_UNINSTALL+=("${APT_REMOVE[@]}")
8383
dorothy-config 'setup.bash' -- \
8484
--field='APT_REMOVE' --replace= \
85-
--field='APT_UNINSTALL' --array="$(__print_lines "${APT_UNINSTALL[@]}" | sort --ignore-case | uniq)"
85+
--field='APT_UNINSTALL' --array="$(echo-unique --ignore-case -- "${APT_UNINSTALL[@]}")"
8686
fi
8787

8888
# adjustments

Diff for: commands/setup-mac-brew

+5-5
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ function setup_mac_brew() (
564564

565565
if [[ $option_configure != 'yes' ]]; then
566566
if [[ ${#HOMEBREW_FORMULAS[@]} -eq 0 ]]; then
567-
if confirm --positive --ppid=$$ -- "You currently have no formula listed in your user configuration, do you want to update the configuration to reflect what you have installed?"; then
567+
if confirm --positive --ppid=$$ -- 'You currently have no formula listed in your user configuration, do you want to update the configuration to reflect what you have installed?'; then
568568
option_configure='yes'
569569
fi
570570
fi
@@ -621,11 +621,11 @@ function setup_mac_brew() (
621621

622622
# save
623623
dorothy-config 'setup.bash' -- \
624-
--field='SETUP_UTILS' --array="$(__print_lines "${SETUP_UTILS[@]}" | sort --ignore-case | uniq)" \
624+
--field='SETUP_UTILS' --array="$(echo-unique --ignore-case -- "${SETUP_UTILS[@]}")" \
625625
--field='HOMEBREW_ENCODING_INSTALL' --value="$HOMEBREW_ENCODING_INSTALL" \
626-
--field='HOMEBREW_FORMULAS' --array="$(__print_lines "${HOMEBREW_FORMULAS[@]}" | sort --ignore-case)" \
627-
--field='HOMEBREW_CASKS' --array="$(__print_lines "${HOMEBREW_CASKS[@]}" | sort --ignore-case)" \
628-
--field='HOMEBREW_FONTS' --array="$(__print_lines "${HOMEBREW_FONTS[@]}" | sort --ignore-case)"
626+
--field='HOMEBREW_FORMULAS' --array="$(__print_lines "${HOMEBREW_FORMULAS[@]}")" \
627+
--field='HOMEBREW_CASKS' --array="$(__print_lines "${HOMEBREW_CASKS[@]}")" \
628+
--field='HOMEBREW_FONTS' --array="$(__print_lines "${HOMEBREW_FONTS[@]}")"
629629
fi
630630

631631
# -------------------------------------

Diff for: commands/setup-node

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function setup_node() (
2828
NPM_INSTALL+=("${NODE_INSTALL[@]}")
2929
dorothy-config 'setup.bash' -- \
3030
--field='NODE_INSTALL' --replace= \
31-
--field='NPM_INSTALL' --array="$(__print_lines "${NPM_INSTALL[@]}" | sort --ignore-case | uniq)"
31+
--field='NPM_INSTALL' --array="$(echo-unique --ignore-case -- "${NPM_INSTALL[@]}")"
3232
fi
3333

3434
# adjustments

Diff for: commands/setup-ruby

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function setup_ruby() (
2525
GEM_INSTALL+=("${RUBY_INSTALL[@]}")
2626
dorothy-config 'setup.bash' -- \
2727
--field='RUBY_INSTALL' --replace= \
28-
--field='GEM_INSTALL' --array="$(__print_lines "${GEM_INSTALL[@]}" | sort --ignore-case | uniq)"
28+
--field='GEM_INSTALL' --array="$(echo-unique --ignore-case -- "${GEM_INSTALL[@]}")"
2929
fi
3030

3131
# adjustments

Diff for: commands/setup-rust

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function setup_rust() (
1818
CARGO_INSTALL+=("${RUST_INSTALL[@]}")
1919
dorothy-config 'setup.bash' -- \
2020
--field='RUST_INSTALL' --replace= \
21-
--field='CARGO_INSTALL' --array="$(__print_lines "${CARGO_INSTALL[@]}" | sort --ignore-case | uniq)"
21+
--field='CARGO_INSTALL' --array="$(echo-unique --ignore-case -- "${CARGO_INSTALL[@]}")"
2222
fi
2323

2424
# adjustments

0 commit comments

Comments
 (0)