From 0a230f59f97e9e5f3e0789f4913c6ba690bef3e4 Mon Sep 17 00:00:00 2001 From: gwbeip Date: Mon, 26 Jan 2026 14:25:36 +0800 Subject: [PATCH] starship related --- .../{starship.toml => starship_default.toml} | 0 zsh/functions/config_starship.sh | 43 ++++++++++--------- zsh/zshrc | 3 +- 3 files changed, 25 insertions(+), 21 deletions(-) rename starship/{starship.toml => starship_default.toml} (100%) diff --git a/starship/starship.toml b/starship/starship_default.toml similarity index 100% rename from starship/starship.toml rename to starship/starship_default.toml diff --git a/zsh/functions/config_starship.sh b/zsh/functions/config_starship.sh index 20d16da..a936ab5 100644 --- a/zsh/functions/config_starship.sh +++ b/zsh/functions/config_starship.sh @@ -1,24 +1,27 @@ function starship_polyjuice() { - if [ ! -n "${ZSH_POLYJUICE_STARSHIP_CONFIG_FILE}" ]; then - echo "STARSHIP_CONFIG_FILE is not set. Please source `\$HOME/.zshrc` first." - return - fi - starship_config_file="$HOME/.config/starship.toml" - if [ -f $starship_config_file ]; then - if $(file "$starship_config_file" | grep -q "symbolic link") ; then - if [[ $(readlink "$starship_config_file") != $(realpath "$ZSH_POLYJUICE_STARSHIP_CONFIG_FILE") ]]; then - ln -sf "$ZSH_POLYJUICE_STARSHIP_CONFIG_FILE" "$starship_config_file" - fi - else - if [ ! -f "$starship_config_file.bkp" ]; then - mv "$starship_config_file" "$starship_config_file.bkp" - ln -s "$ZSH_POLYJUICE_STARSHIP_CONFIG_FILE" "$starship_config_file" + local config_file_dir="$(dirname "$ZSH_POLYJUICE_STARSHIP_CONFIG_FILE")" + case "$1" in + list) + ls $config_file_dir + ;; + set) + local _target="$config_file_dir/starship_$2.toml" + if [ -f "$_target" ]; then + export STARSHIP_CONFIG=$_target + echo "Starship config set to '$_target'" else - echo "Backup file already exists. Please remove $starship_config_file.bkp and try again." - return + echo "Config '$_target' does not exist." fi - fi - else - ln -sf "$ZSH_POLYJUICE_STARSHIP_CONFIG_FILE" "$starship_config_file" - fi + ;; + reset) + export STARSHIP_CONFIG="$ZSH_POLYJUICE_STARSHIP_CONFIG_FILE" + ;; + *) + echo "Usage: starship_polyjuice [args]" + echo "Commands:" + echo " list List available Starship configs in the polyjuice directory." + echo " set Select a config by base name (omit the .toml extension)." + echo " reset Reset the Starship configuration to the default polyjuice configuration." + ;; + esac } diff --git a/zsh/zshrc b/zsh/zshrc index a34e1c4..04271c2 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -20,7 +20,7 @@ export ZSH_POLYJUICE_PLUGINS_PATH="$ZSH_POLYJUICE_PATH/plugins" export ZSH_POLYJUICE_ALIAS_PATH="$ZSH_POLYJUICE_PATH/alias" export ZSH_POLYJUICE_SETTINGS_PATH="$ZSH_POLYJUICE_PATH/settings" export ZSH_POLYJUICE_FUNCTIONS_PATH="$ZSH_POLYJUICE_PATH/functions" -export ZSH_POLYJUICE_STARSHIP_CONFIG_FILE="$ZSH_POLYJUICE_PATH/../starship/starship.toml" +export ZSH_POLYJUICE_STARSHIP_CONFIG_FILE="$ZSH_POLYJUICE_PATH/../starship/starship_default.toml" # Load basic settings `zsh/settings` for _file in "$ZSH_POLYJUICE_SETTINGS_PATH"/*.sh; do @@ -59,6 +59,7 @@ fi # using starship as prompt if (( $+commands[starship] )); then + export STARSHIP_CONFIG="$ZSH_POLYJUICE_STARSHIP_CONFIG_FILE" eval "$(starship init zsh)" else echo '[starship] not found, please install it.'