mirror of
https://github.com/oh-my-fish/oh-my-fish.git
synced 2025-01-24 14:56:16 +08:00
ea0b464f1d
- Move theme installation to cli entry point (omf.fish) - Generalize XDG_CONFIG_HOME code in `omf.xdg.config_home` - Generalize prompt conflicts check in `omf.checks.fish_prompt` * Migrate `omf.doctor` to use it + Change theme activation steps - Create user function path if not existent - Check for conflicts in fish_prompt, aborts if found - Remove current theme from autoloading paths - Add target theme to autoloading paths - Link target theme's fish_prompt to user's - Persist selected theme to $OMF_CONFIG/theme This approach brings two major advantages: - Theme prompt now shows accordingly in fish_config web interface - Faster theme changes, reducing it from seconds to some milis - Avoids calling refresh, which makes users much more happy
32 lines
991 B
Fish
32 lines
991 B
Fish
function omf.theme -a target_theme
|
|
set -l current_theme (cat $OMF_CONFIG/theme)
|
|
test "$target_theme" = "$current_theme"; and return 0
|
|
|
|
set -l prompt_filename "fish_prompt.fish"
|
|
set -l user_functions_path (omf.xdg.config_home)/fish/functions
|
|
|
|
mkdir -p "$user_functions_path"
|
|
|
|
if not omf.check.fish_prompt
|
|
echo (omf::err)"Conflicting prompt setting."(omf::off)
|
|
echo "Run "(omf::em)"omf doctor"(omf::off)" and fix issues before continuing."
|
|
return 1
|
|
end
|
|
|
|
# Replace autoload paths of current theme with the target one
|
|
autoload -e {$OMF_CONFIG,$OMF_PATH}/themes/$current_theme
|
|
autoload {$OMF_CONFIG,$OMF_PATH}/themes/$target_theme
|
|
|
|
# Find target theme's fish_prompt and link to user function path
|
|
for path in {$OMF_CONFIG,$OMF_PATH}/themes/$target_theme/$prompt_filename
|
|
if test -e $path
|
|
ln -sf $path $user_functions_path/$prompt_filename; and break
|
|
end
|
|
end
|
|
|
|
# Persist the changes
|
|
echo "$target_theme" > "$OMF_CONFIG/theme"
|
|
|
|
return 0
|
|
end
|