Skip to content

Commit 7f50912

Browse files
fix(bash,zsh): use >| to avoid noclobber errors in tab completion (#524)
The warning look like this: ``` |<TAB> bash-5.3$ hk bash: /var/folders/c4/dnywd0f132q_3328dwgy8sfr0000gn/T//usage__usage_spec_hk.spec: cannot overwrite existing file builtins cfg completion f i install r test util version c check config fix init migrate run uninstall validate ``` Co-authored-by: Nikolaos Kakouros <nkakouros@nordsnipe.com>
1 parent 45c2924 commit 7f50912

10 files changed

+14
-14
lines changed

cli/assets/completions/_usage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _usage() {
2424
fi
2525

2626
local spec_file="${TMPDIR:-/tmp}/usage__usage_spec_usage.spec"
27-
usage --usage-spec > "$spec_file"
27+
usage --usage-spec >| "$spec_file"
2828
_arguments "*: :(($(command usage complete-word --shell zsh -f "$spec_file" -- "${words[@]}" )))"
2929
return 0
3030
}

cli/assets/completions/usage.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ _usage() {
1010
local cur prev words cword was_split comp_args
1111
_comp_initialize -n : -- "$@" || return
1212
local spec_file="${TMPDIR:-/tmp}/usage__usage_spec_usage.spec"
13-
usage --usage-spec > "$spec_file"
13+
usage --usage-spec >| "$spec_file"
1414
# shellcheck disable=SC2207
1515
_comp_compgen -- -W "$(command usage complete-word --shell bash -f "$spec_file" --cword="$cword" -- "${words[@]}")"
1616
_comp_ltrim_colon_completions "$cur"

lib/src/complete/bash.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ pub fn complete_bash(opts: &CompleteOptions) -> String {
3535
if opts.cache_key.is_some() {
3636
format!(
3737
r#"if [[ ! -f "$spec_file" ]]; then
38-
{usage_cmd} > "$spec_file"
38+
{usage_cmd} >| "$spec_file"
3939
fi"#
4040
)
4141
} else {
42-
format!(r#"{usage_cmd} > "$spec_file""#)
42+
format!(r#"{usage_cmd} >| "$spec_file""#)
4343
}
4444
} else if let Some(spec) = &opts.spec {
4545
let heredoc = format!(
46-
r#"cat > "$spec_file" <<'__USAGE_EOF__'
46+
r#"cat >| "$spec_file" <<'__USAGE_EOF__'
4747
{spec}
4848
__USAGE_EOF__"#,
4949
spec = spec.to_string().trim()

lib/src/complete/snapshots/usage__complete__bash__tests__complete_bash-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ _mycli() {
1515
_comp_initialize -n : -- "$@" || return
1616
local spec_file="${TMPDIR:-/tmp}/usage__usage_spec_mycli_1_2_3.spec"
1717
if [[ ! -f "$spec_file" ]]; then
18-
mycli complete --usage > "$spec_file"
18+
mycli complete --usage >| "$spec_file"
1919
fi
2020
# shellcheck disable=SC2207
2121
_comp_compgen -- -W "$(command usage complete-word --shell bash -f "$spec_file" --cword="$cword" -- "${words[@]}")"

lib/src/complete/snapshots/usage__complete__bash__tests__complete_bash-3.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ _mycli() {
1414
local cur prev words cword was_split comp_args
1515
_comp_initialize -n : -- "$@" || return
1616
local spec_file="${TMPDIR:-/tmp}/usage__usage_spec_mycli.spec"
17-
cat > "$spec_file" <<'__USAGE_EOF__'
17+
cat >| "$spec_file" <<'__USAGE_EOF__'
1818
name mycli
1919
bin mycli
2020
source_code_link_template "https://github.com/jdx/mise/blob/main/src/cli/{{path}}.rs"

lib/src/complete/snapshots/usage__complete__bash__tests__complete_bash.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ _mycli() {
1414
local cur prev words cword was_split comp_args
1515
_comp_initialize -n : -- "$@" || return
1616
local spec_file="${TMPDIR:-/tmp}/usage__usage_spec_mycli.spec"
17-
mycli complete --usage > "$spec_file"
17+
mycli complete --usage >| "$spec_file"
1818
# shellcheck disable=SC2207
1919
_comp_compgen -- -W "$(command usage complete-word --shell bash -f "$spec_file" --cword="$cword" -- "${words[@]}")"
2020
_comp_ltrim_colon_completions "$cur"

lib/src/complete/snapshots/usage__complete__zsh__tests__complete_zsh-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ _mycli() {
2929

3030
local spec_file="${TMPDIR:-/tmp}/usage__usage_spec_mycli_1_2_3.spec"
3131
if [[ ! -f "$spec_file" ]]; then
32-
mycli complete --usage > "$spec_file"
32+
mycli complete --usage >| "$spec_file"
3333
fi
3434
_arguments "*: :(($(command usage complete-word --shell zsh -f "$spec_file" -- "${words[@]}" )))"
3535
return 0

lib/src/complete/snapshots/usage__complete__zsh__tests__complete_zsh-3.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _mycli() {
1818
fi
1919

2020
local spec_file="${TMPDIR:-/tmp}/usage__usage_spec_mycli.spec"
21-
cat > "$spec_file" <<'__USAGE_EOF__'
21+
cat >| "$spec_file" <<'__USAGE_EOF__'
2222
name mycli
2323
bin mycli
2424
source_code_link_template "https://github.com/jdx/mise/blob/main/src/cli/{{path}}.rs"

lib/src/complete/snapshots/usage__complete__zsh__tests__complete_zsh.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ _mycli() {
2828
fi
2929

3030
local spec_file="${TMPDIR:-/tmp}/usage__usage_spec_mycli.spec"
31-
mycli complete --usage > "$spec_file"
31+
mycli complete --usage >| "$spec_file"
3232
_arguments "*: :(($(command usage complete-word --shell zsh -f "$spec_file" -- "${words[@]}" )))"
3333
return 0
3434
}

lib/src/complete/zsh.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ _{bin_snake}() {{
5656
if opts.cache_key.is_some() {
5757
format!(
5858
r#"if [[ ! -f "$spec_file" ]]; then
59-
{usage_cmd} > "$spec_file"
59+
{usage_cmd} >| "$spec_file"
6060
fi"#
6161
)
6262
} else {
63-
format!(r#"{usage_cmd} > "$spec_file""#)
63+
format!(r#"{usage_cmd} >| "$spec_file""#)
6464
}
6565
} else if let Some(spec) = &opts.spec {
6666
let heredoc = format!(
67-
r#"cat > "$spec_file" <<'__USAGE_EOF__'
67+
r#"cat >| "$spec_file" <<'__USAGE_EOF__'
6868
{spec}
6969
__USAGE_EOF__"#,
7070
spec = spec.to_string().trim()

0 commit comments

Comments
 (0)