mirror of
https://github.com/oh-my-fish/oh-my-fish.git
synced 2024-11-26 10:13:46 +08:00
Merge pull request #102 from derekstavis/omf-theme-no-refresh
Rework omf theme code: Integrate with fish_config, ditch refresh calls
This commit is contained in:
commit
27af4e366c
10
pkg/omf/cli/omf.check.fish_prompt.fish
Normal file
10
pkg/omf/cli/omf.check.fish_prompt.fish
Normal file
|
@ -0,0 +1,10 @@
|
|||
function omf.check.fish_prompt
|
||||
set -l prompt_file "fish_prompt.fish"
|
||||
set -l theme (cat $OMF_CONFIG/theme)
|
||||
|
||||
set -l user_functions_path (omf.xdg.config_home)/fish/functions
|
||||
set -l fish_prompt (readlink "$user_functions_path/$prompt_file" ^/dev/null)
|
||||
|
||||
not test -e "$fish_prompt"; and return 0
|
||||
contains -- "$fish_prompt" {$OMF_CONFIG,$OMF_PATH}/themes/$theme/$prompt_file
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function __omf.doctor.theme
|
||||
if test -e ~/.config/fish/functions/fish_prompt.fish
|
||||
if not omf.check.fish_prompt
|
||||
echo (omf::err)"Warning: "(omf::off)(omf::em)"fish_prompt.fish"(omf::off)" is overridden."
|
||||
echo (omf::em)" fish_config"(omf::off)" command persists the prompt to "(omf::em)"~/.config/fish/functions/fish_prompt.fish"(omf::off)
|
||||
echo " That file takes precedence over Oh My Fish's themes. Remove the file to fix it:"
|
||||
|
|
|
@ -5,7 +5,6 @@ function omf.install -a type_flag name_or_url
|
|||
|
||||
function _display_error
|
||||
echo (omf::err)"Could not install $argv."(omf::off) 1^&2
|
||||
return $OMF_UNKNOWN_ERR
|
||||
end
|
||||
|
||||
switch $type_flag
|
||||
|
@ -33,6 +32,7 @@ function omf.install -a type_flag 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
|
||||
|
@ -49,6 +49,9 @@ function omf.install -a type_flag 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
|
||||
|
|
|
@ -1,6 +1,31 @@
|
|||
function omf.theme
|
||||
if not test -e $OMF_CONFIG/themes/$argv[1]
|
||||
omf.install --theme $argv[1]
|
||||
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
|
||||
echo "$argv[1]" > $OMF_CONFIG/theme
|
||||
|
||||
# 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
|
||||
|
|
5
pkg/omf/cli/omf.xdg.config_home.fish
Normal file
5
pkg/omf/cli/omf.xdg.config_home.fish
Normal file
|
@ -0,0 +1,5 @@
|
|||
function omf.xdg.config_home -d "Return the config directory based on XDG specs"
|
||||
set -q XDG_CONFIG_HOME;
|
||||
and echo "$XDG_CONFIG_HOME";
|
||||
or echo "$HOME/.config"
|
||||
end
|
|
@ -120,10 +120,11 @@ function omf -d "Oh My Fish"
|
|||
|
||||
omf.list_themes | column | sed -E "s/$regex/"(omf::em)"\1"(omf::off)"/"
|
||||
omf::off
|
||||
|
||||
else if test (count $argv) -eq 2
|
||||
if not contains -- $argv[2] (omf.list_installed_themes)
|
||||
omf.install --theme $argv[2]; or return 1
|
||||
end
|
||||
omf.theme $argv[2]
|
||||
refresh
|
||||
else
|
||||
echo (omf::err)"Invalid number of arguments"(omf::off) 1^&2
|
||||
echo "Usage: $_ "(omf::em)"$argv[1]"(omf::off)" [<theme name>]" 1^&2
|
||||
|
|
Loading…
Reference in New Issue
Block a user