Skip to content

Commit

Permalink
Replace $HOME with ~ in plugin state (#611)
Browse files Browse the repository at this point in the history
Now it should be easier to sync dotfiles across machines
that have different $HOME locations.

Close #611
  • Loading branch information
jorgebucaran committed Jul 2, 2022
1 parent 604f8ff commit 1662b79
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions functions/fisher.fish
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ function fisher --argument-names cmd --description "A plugin manager for Fish"
for name in (string replace --filter --regex -- '.+/conf\.d/([^/]+)\.fish$' '$1' $$plugin_files_var)
emit {$name}_uninstall
end
printf "%s\n" Removing\ (set_color red --bold)$plugin(set_color normal) " "$$plugin_files_var
printf "%s\n" Removing\ (set_color red --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~
set --erase _fisher_plugins[$index]
end

command rm -rf $$plugin_files_var
command rm -rf (string replace -- \~ ~ $$plugin_files_var)

functions --erase (string replace --filter --regex -- '.+/functions/([^/]+)\.fish$' '$1' $$plugin_files_var)

for name in (string replace --filter --regex -- '.+/completions/([^/]+)\.fish$' '$1' $$plugin_files_var)
Expand Down Expand Up @@ -176,14 +177,15 @@ function fisher --argument-names cmd --description "A plugin manager for Fish"
end

set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files
set --query files[1] && set --universal $plugin_files_var (string replace -- $source $fisher_path $files)

set --query files[1] && set --universal $plugin_files_var (string replace -- $source $fisher_path $files | string replace -- ~ \~)

contains -- $plugin $_fisher_plugins || set --universal --append _fisher_plugins $plugin
contains -- $plugin $install_plugins && set --local event install || set --local event update

printf "%s\n" Installing\ (set_color --bold)$plugin(set_color normal) " "$$plugin_files_var
printf "%s\n" Installing\ (set_color --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~

for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var)
for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var | string replace -- \~ ~)
source $file
if set --local name (string replace --regex -- '.+conf\.d/([^/]+)\.fish$' '$1' $file)
emit {$name}_$event
Expand Down Expand Up @@ -221,14 +223,17 @@ function fisher --argument-names cmd --description "A plugin manager for Fish"
end
end

## Migrations ##
function _fisher_fish_postexec --on-event fish_postexec
if ! set --query _fisher_upgraded_to_4_4
set --universal _fisher_upgraded_to_4_4
if functions --query _fisher_list
set --query XDG_DATA_HOME[1] || set --local XDG_DATA_HOME ~/.local/share
command rm -rf $XDG_DATA_HOME/fisher
functions --erase _fisher_{list,plugin_parse}
fisher update >/dev/null 2>/dev/null
set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share
test -e $XDG_DATA_HOME/fisher && command rm -rf $XDG_DATA_HOME/fisher
functions --erase _fisher_list _fisher_plugin_parse
set --erase fisher_data
else
for var in (set --names | string match --entire --regex '^_fisher_.+_files$')
set $var (string replace -- ~ \~ $$var)
end
functions --erase _fisher_fish_postexec
end
functions --erase _fisher_fish_postexec
end

0 comments on commit 1662b79

Please sign in to comment.