fisher/functions/__fisher_plugin.fish
Jorge Bucaran ab43e5f804
Introducting Fisherman's official website:
www.fisherman.sh

Still a WIP. Powered by Jekyll and hosted by GitHub
pages.

* Refactor fisher install / fisher uninstall by
extracting the logic to enable / disable plugins
into __fisher_plugin. The algorithm to enable/disable
plugins is essentially the same. The only difference
is enable, copies/symlinks files and disable removes
them from $fisher_config/.... Closes #45.

* Add support for legacy oh-my-fish! plugins using
.load initialization files. Closes #35.

* Add support for Tackle Fish framework initialization
modules. Closes #35.

* Add support for plugins that share scripts in
languages like Python or Perl. For example
oh-my-fish/plugin-vi-mode assumes there is a
vi-mode-impl.py file in the same path of the running
script. This opens the door for including code
snippets in other languages.

* Any files inside a share directory, except for *.md
or *.fish files, are copied to $fisher_config/functions.
This allows you to run legacy plugins that retrieve
the currently running script path with (dirname
(status -f)) out of the box.

* A cleaner alternative is using the new $fisher_share
variable like this: python
$fisher_share/my_plugin_script.py.

* $fisher_share points to $fisher_config/share by
default, but you may change this in your user
config.fish. This path contains copies (or symbolic
links) to the same script files copied to
$fisher_config/functions.

* Introduce the $fisher_share_extensions variable to
let you customize what extensions Fisherman is aware
of. Only extensions in this array will be processed
during the install process. The default is py rb php
pl awk sed.

* .fish and .md extensions are always ignored.

* Remove ad-hoc debug d function created by mistake
in the Fisherman config.fish file. Closes #34.

* Remove almost useless fisher --alias. You can still
create aliases using $fisher_alias. It's difficult
to add auto-complete to this feature, and even if
we do so, it is slow.

* Fix bug introduced in the previous release caused
by swapping the lines that calculate the index of
the current plugin being installed/updated/uninstalled
and the line that displays the value, causing the
CLI to show incorrect values. Closes #36. Thanks
@kballard

* Add cache, enabled and disabled options to fisher
--list. Now you can type fisher -l enabled to get a
list of what plugins are currently enabled.

* Add new $fisher_plugins universal variable to keep
track of what plugins are enabled / disabled.

* Update completions after a plugin is installed,
updated or uninstalled.

* Improve autocomplete speed by removing the descriptions
from plugins installed with custom URLs.

* fisher --list displays nothing and returns 1 when
there are no plugins installed. Closes #38.

* fisher uninstall does not attempt to uninstall plugins
already disabled by looking at the $fisher_plugins
array. --force will bypass this. Closes #40
2016-01-12 05:00:34 +09:00

157 lines
4.6 KiB
Fish

function __fisher_plugin -a enable name path -d "enable or disable plugins"
set -l batch
set -l option
switch $enable
case --disable
set -e enable
end
if test -L $path
set option link
end
for file in $path/*.load
set -l base (basename $file).fish
if set -q enable
__fisher_copy "$option" $file $fisher_config/conf.d/$base
set batch $batch $fisher_config/conf.d/$base
else
rm -f $fisher_config/conf.d/$base
end
end
for file in $path/{*,{conf.d,modules}/*,functions/**}.fish
set -l base (basename $file)
if test $base = uninstall.fish
if not set -q enable
set batch $batch $file
end
continue
end
switch $file
case \?\*/{conf.d,modules}/\?\*
switch "$base"
case \*$name\*
case \*
set base $name.$base
end
if set -q enable
__fisher_copy "$option" $file $fisher_config/conf.d/$base
set batch $batch $fisher_config/conf.d/$base
else
rm -f $fisher_config/conf.d/$base
end
case \*
switch $base
case {$name,fish_{,right_}prompt}.fish
if set -q enable
source $file
__fisher_copy "$option" $file $fisher_config/functions/$base
else
functions -e (basename $base .fish)
rm -f $fisher_config/functions/$base
if test "$base" = fish_prompt.fish
source $__fish_datadir/functions/fish_prompt.fish ^ /dev/null
end
end
case \*\?.config.fish
if set -q enable
__fisher_copy "$option" $file $fisher_config/conf.d/$base
set batch $batch $fisher_config/conf.d/$base
else
rm -f $fisher_config/conf.d/$base
end
case {,before.}init.fish
set base $name.$base
if set -q enable
__fisher_copy "$option" $file $fisher_config/conf.d/$base
set batch $batch $fisher_config/conf.d/$base
else
rm -f $fisher_config/conf.d/$base
end
case \*
if set -q enable
__fisher_copy "$option" $file $fisher_config/functions/$base
else
rm -f $fisher_config/functions/$base
end
end
end
end
if not set -q fisher_share_extensions[1]
set fisher_share_extensions py rb php pl awk sed
end
for file in $path/{share/,}*.$fisher_share_extensions
set -l base (basename $file)
switch $file
case \*.md \*.fish
continue
end
if set -q enable
__fisher_copy "$option" $file $fisher_config/functions/$base
__fisher_copy "$option" $file $fisher_share/$base
else
rm -f {$fisher_config/functions,$fisher_share}/$base
end
end
for file in $path/completions/*.fish
if set -q enable
__fisher_copy "$option" $file $fisher_config/completions/(basename $file)
else
rm -f $fisher_config/completions/(basename $file)
end
end
for n in (seq 9)
if test -d $path/man/man$n
mkdir -p $fisher_config/man/man$n
end
for file in $path/man/man$n/*.$n
if set -q enable
__fisher_copy "$option" $file $fisher_config/man/man$n
else
rm -f $fisher_config/man/man$n/(basename $file)
end
end
end
if set -q batch[1]
for file in $batch
source $file
end
end
set -l index (contains -i -- $name $fisher_plugins)
if set -q enable
if test -z "$index"
set -U fisher_plugins $fisher_plugins $name
end
else
if test "$index" -ge 1
set -e fisher_plugins[$index]
end
end
complete -ec fisher
source $fisher_home/completions/fisher.fish
end