0

I have the following in a file which is sourced from ~/.zshrc:

# Starship prompt
cp -f ~/.config/starship.toml ~/.config/starship-zsh.toml
export STARSHIP_CONFIG="$HOME/.config/starship-zsh.toml"
starship config character.success_symbol "[%](white)"
starship config character.error_symbol "[%](bold red)"
eval "$(starship init zsh)"

This is so that I only need to keep one starship configuration file updated for both bash and zsh, but still have a different prompt character for each.

When logging in I get asked whether it is okay to overwrite the existing file. This doesn't happen with I put the above lines in .zshrc itself, but it does in this file that is sourced from .zshrc. I have it like this as this file is conditionally sourced only when a certain set of packages have been installed.

I can workaround this by deleting the file first, but I would like to know why this is happening even with the -f switch.

1 Answer 1

1

You probably have an alias or wrapper function that sets some option which overrides the effect of -f. Use \command cp to force the use of the command directly, bypassing functions and aliases.

(The leading \ is for the unlikely case where you have something like alias command='command ' set.)

3
  • Oh, of course, I forgot that these files are being sourced in the current shell so my aliases would affect anything in them.
    – paradroid
    Apr 29, 2023 at 4:10
  • 2
    It's a bit annoying and confusing that -f doesn't cancel -i in cp (as the OP likely has a cp() command cp -i "$@" function or alias cp='cp -i alias) like it does for rm and mv, but it has different semantics in cp; it's about removing the destination file if any before creating the copy anew instead of overwriting it so is not the opposite of -i there. Apr 29, 2023 at 10:24
  • In general, aliasing cp or rm to include the -i option is a really bad idea. Sooner or later you'll find yourself on a system without your settings and wonder why rm * has just finished very quickly instead of prompting you. Give the aliases a different name.
    – okapi
    May 3, 2023 at 21:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .