oh-my-fish/pkg/omf/functions/themes/omf.theme.set.fish
Derek Willian Stavis fcc9d4dc0a key bindings: test if reload function is available (#368)
This fixes a rare case when fish's builtin function
__fish_reload_key_bindings is not defined.
2016-07-23 20:49:42 -03:00

43 lines
1.4 KiB
Fish

function omf.theme.set -a target_theme
if not contains "$target_theme" (omf.packages.list --installed --theme)
echo (omf::err)"Theme not installed!"(omf::off)
echo Install it using (omf::em)omf install $target_theme(omf::off)
return $OMF_INVALID_ARG
end
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 $OMF_INVALID_ARG
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
# Reload fish key bindings if reload is available and needed
functions -q __fish_reload_key_bindings
and test (count {$OMF_CONFIG,$OMF_PATH}/key_binding?.fish) -gt 0
and __fish_reload_key_bindings
# Persist the changes
echo "$target_theme" > "$OMF_CONFIG/theme"
return 0
end