oh-my-fish/pkg/omf/cli/omf.install.fish
Derek Stavis ea0b464f1d omf.theme: Rework theme activation code
- 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
2015-10-07 00:50:14 -03:00

58 lines
1.8 KiB
Fish

function omf.install -a type_flag name_or_url
function _display_success
echo (omf::em)"$argv successfully installed."(omf::off)
end
function _display_error
echo (omf::err)"Could not install $argv."(omf::off) 1^&2
end
switch $type_flag
case "--theme"
set install_type "theme"
set parent_path "themes"
case "--pkg"
set install_type "package"
set parent_path "pkg"
case "*"
echo (omf::err)"Argument to omf.install must be --theme [name|URL] or --pkg [name|URL]"(omf::off)
return $OMF_INVALID_ARG
end
if test -e $OMF_PATH/db/$parent_path/$name_or_url
set target $parent_path/$name_or_url
else
set -l local_name (basename $name_or_url | sed "s/^pkg-//;s/^plugin-//;s/^theme-//")
if test -e $OMF_PATH/$parent_path/$local_name
echo (omf::err)"Error: $local_name $install_type already installed."(omf::off) 1^&2
else
echo (omf::dim)"Trying to clone from URL..."(omf::off)
if omf.repo.clone $name_or_url $OMF_PATH/$parent_path/$local_name
omf.bundle.add $install_type $name_or_url
_display_success "$install_type $name_or_url"
else
_display_error "$install_type $name_or_url"
return $OMF_UNKNOWN_ERR
end
end
return 0
end
if test -e $OMF_PATH/$target
echo (omf::dim)"Updating $name_or_url $install_type..."(omf::off)
omf.repo.pull $OMF_PATH/$target
echo (omf::em)"$name_or_url $install_type up to date."(omf::off)
else
echo (omf::dim)"Installing $name_or_url $install_type..."(omf::off)
if omf.repo.clone (cat $OMF_PATH/db/$target) $OMF_PATH/$target
omf.bundle.add $install_type $name_or_url
_display_success "$install_type $name_or_url"
else
_display_error "$install_type $name_or_url"
return $OMF_UNKNOWN_ERR
end
end
return 0
end