aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fish/completions/fisher.fish7
-rw-r--r--fish/conf.d/plugins.fish13
-rw-r--r--fish/fish_plugins5
-rw-r--r--fish/functions/fisher.fish251
-rw-r--r--fish/functions/fundle.fish462
5 files changed, 475 insertions, 263 deletions
diff --git a/fish/completions/fisher.fish b/fish/completions/fisher.fish
deleted file mode 100644
index 6d23ce4..0000000
--- a/fish/completions/fisher.fish
+++ /dev/null
@@ -1,7 +0,0 @@
-complete --command fisher --exclusive --long help --description "Print help"
-complete --command fisher --exclusive --long version --description "Print version"
-complete --command fisher --exclusive --condition __fish_use_subcommand --arguments install --description "Install plugins"
-complete --command fisher --exclusive --condition __fish_use_subcommand --arguments update --description "Update installed plugins"
-complete --command fisher --exclusive --condition __fish_use_subcommand --arguments remove --description "Remove installed plugins"
-complete --command fisher --exclusive --condition __fish_use_subcommand --arguments list --description "List installed plugins matching regex"
-complete --command fisher --exclusive --condition "__fish_seen_subcommand_from update remove" --arguments "(fisher list)"
diff --git a/fish/conf.d/plugins.fish b/fish/conf.d/plugins.fish
new file mode 100644
index 0000000..564400f
--- /dev/null
+++ b/fish/conf.d/plugins.fish
@@ -0,0 +1,13 @@
+if not functions --query fundle
+ eval (curl --silent \
+ --fail \
+ --location \
+ "https://raw.githubusercontent.com/danhper/fundle/refs/heads/master/install-fundle.fish")
+end
+
+fundle plugin "franciscolourenco/done"
+fundle plugin "jorgebucaran/autopair.fish"
+fundle plugin "patrickf1/fzf.fish"
+fundle plugin "jorgebucaran/hydro"
+
+fundle init
diff --git a/fish/fish_plugins b/fish/fish_plugins
deleted file mode 100644
index f7c066a..0000000
--- a/fish/fish_plugins
+++ /dev/null
@@ -1,5 +0,0 @@
-jorgebucaran/fisher
-franciscolourenco/done
-jorgebucaran/autopair.fish
-patrickf1/fzf.fish
-jorgebucaran/hydro
diff --git a/fish/functions/fisher.fish b/fish/functions/fisher.fish
deleted file mode 100644
index 4f5be4f..0000000
--- a/fish/functions/fisher.fish
+++ /dev/null
@@ -1,251 +0,0 @@
-function fisher --argument-names cmd --description "A plugin manager for Fish"
- set --query fisher_path || set --local fisher_path $__fish_config_dir
- set --local fisher_version 4.4.8
- set --local fish_plugins $__fish_config_dir/fish_plugins
-
- switch "$cmd"
- case -v --version
- echo "fisher, version $fisher_version"
- case "" -h --help
- echo "Usage: fisher install <plugins...> Install plugins"
- echo " fisher remove <plugins...> Remove installed plugins"
- echo " fisher uninstall <plugins...> Remove installed plugins (alias)"
- echo " fisher update <plugins...> Update installed plugins"
- echo " fisher update Update all installed plugins"
- echo " fisher list [<regex>] List installed plugins matching regex"
- echo "Options:"
- echo " -v, --version Print version"
- echo " -h, --help Print this help message"
- echo "Variables:"
- echo " \$fisher_path Plugin installation path. Default: $__fish_config_dir" | string replace --regex -- $HOME \~
- case ls list
- string match --entire --regex -- "$argv[2]" $_fisher_plugins
- case install update remove uninstall
- isatty || read --local --null --array stdin && set --append argv $stdin
-
- test "$cmd" = uninstall && set cmd remove
-
- set --local install_plugins
- set --local update_plugins
- set --local remove_plugins
- set --local arg_plugins $argv[2..-1]
- set --local old_plugins $_fisher_plugins
- set --local new_plugins
-
- test -e $fish_plugins && set --local file_plugins (string match --regex -- '^[^\s]+$' <$fish_plugins | string replace -- \~ ~)
-
- if ! set --query argv[2]
- if test "$cmd" != update
- echo "fisher: Not enough arguments for command: \"$cmd\"" >&2 && return 1
- else if ! set --query file_plugins
- echo "fisher: \"$fish_plugins\" file not found: \"$cmd\"" >&2 && return 1
- end
- set arg_plugins $file_plugins
- else if test "$cmd" = install && ! set --query old_plugins[1]
- set --append arg_plugins $file_plugins
- end
-
- for plugin in $arg_plugins
- set plugin (test -e "$plugin" && realpath $plugin || string lower -- $plugin)
- contains -- "$plugin" $new_plugins || set --append new_plugins $plugin
- end
-
- if set --query argv[2]
- for plugin in $new_plugins
- if contains -- "$plugin" $old_plugins
- test "$cmd" = remove &&
- set --append remove_plugins $plugin ||
- set --append update_plugins $plugin
- else if test "$cmd" = install
- set --append install_plugins $plugin
- else
- echo "fisher: Plugin not installed: \"$plugin\"" >&2 && return 1
- end
- end
- else
- for plugin in $new_plugins
- contains -- "$plugin" $old_plugins &&
- set --append update_plugins $plugin ||
- set --append install_plugins $plugin
- end
-
- for plugin in $old_plugins
- contains -- "$plugin" $new_plugins || set --append remove_plugins $plugin
- end
- end
-
- set --local pid_list
- set --local source_plugins
- set --local fetch_plugins $update_plugins $install_plugins
- set --local fish_path (status fish-path)
-
- echo (set_color --bold)fisher $cmd version $fisher_version(set_color normal)
-
- for plugin in $fetch_plugins
- set --local source (command mktemp -d)
- set --append source_plugins $source
-
- command mkdir -p $source/{completions,conf.d,themes,functions}
-
- $fish_path --command "
- if test -e $plugin
- command cp -Rf $plugin/* $source
- else
- set resp (command mktemp)
- set temp (command mktemp -d)
- set repo (string split -- \@ $plugin) || set repo[2] HEAD
-
- if set path (string replace --regex -- '^(https://)?gitlab.com/' '' \$repo[1])
- set name (string split -- / \$path)[-1]
- set url https://gitlab.com/\$path/-/archive/\$repo[2]/\$name-\$repo[2].tar.gz
- else
- set url https://api.github.com/repos/\$repo[1]/tarball/\$repo[2]
- end
-
- echo Fetching (set_color --underline)\$url(set_color normal)
-
- set http (command curl -q --silent -L -o \$resp -w %{http_code} \$url)
-
- if test \"\$http\" = 200 && command tar -xzC \$temp -f \$resp 2>/dev/null
- command cp -Rf \$temp/*/* $source
- else if test \"\$http\" = 403
- echo fisher: GitHub API rate limit exceeded \(HTTP 403\) >&2
- command rm -rf $source
- else
- echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2
- command rm -rf $source
- end
-
- command rm -rf \$temp
- end
-
- set files $source/* && string match --quiet --regex -- .+\.fish\\\$ \$files
- " &
-
- set --append pid_list (jobs --last --pid)
- end
-
- wait $pid_list 2>/dev/null
-
- for plugin in $fetch_plugins
- if set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] && test ! -e $source
- if set --local index (contains --index -- "$plugin" $install_plugins)
- set --erase install_plugins[$index]
- else
- set --erase update_plugins[(contains --index -- "$plugin" $update_plugins)]
- end
- end
- end
-
- for plugin in $update_plugins $remove_plugins
- if set --local index (contains --index -- "$plugin" $_fisher_plugins)
- set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files
-
- if contains -- "$plugin" $remove_plugins
- 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 | string replace -- \~ ~
- set --erase _fisher_plugins[$index]
- end
-
- 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)
- complete --erase --command $name
- end
-
- set --erase $plugin_files_var
- end
- end
-
- if set --query update_plugins[1] || set --query install_plugins[1]
- command mkdir -p $fisher_path/{functions,themes,conf.d,completions}
- end
-
- for plugin in $update_plugins $install_plugins
- set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)]
- set --local files $source/{functions,themes,conf.d,completions}/*
-
- if set --local index (contains --index -- $plugin $install_plugins)
- set --local user_files $fisher_path/{functions,themes,conf.d,completions}/*
- set --local conflict_files
-
- for file in (string replace -- $source/ $fisher_path/ $files)
- contains -- $file $user_files && set --append conflict_files $file
- end
-
- if set --query conflict_files[1] && set --erase install_plugins[$index]
- echo -s "fisher: Cannot install \"$plugin\": please remove or move conflicting files first:" \n" "$conflict_files >&2
- continue
- end
- end
-
- for file in (string replace -- $source/ "" $files)
- command cp -RLf $source/$file $fisher_path/$file
- 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 | 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 | string replace -- \~ ~
-
- 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
- end
- end
- end
-
- command rm -rf $source_plugins
-
- if set --query _fisher_plugins[1]
- set --local commit_plugins
-
- for plugin in $file_plugins
- contains -- (string lower -- $plugin) (string lower -- $_fisher_plugins) && set --append commit_plugins $plugin
- end
-
- for plugin in $_fisher_plugins
- contains -- (string lower -- $plugin) (string lower -- $commit_plugins) || set --append commit_plugins $plugin
- end
-
- string replace --regex -- $HOME \~ $commit_plugins >$fish_plugins
- else
- set --erase _fisher_plugins
- command rm -f $fish_plugins
- end
-
- set --local total (count $install_plugins) (count $update_plugins) (count $remove_plugins)
-
- test "$total" != "0 0 0" && echo (string join ", " (
- test $total[1] = 0 || echo "Installed $total[1]") (
- test $total[2] = 0 || echo "Updated $total[2]") (
- test $total[3] = 0 || echo "Removed $total[3]")
- ) plugin/s
- case \*
- echo "fisher: Unknown command: \"$cmd\"" >&2 && return 1
- end
-end
-
-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
- else
- for var in (set --names | string match --entire --regex '^_fisher_.+_files$')
- set $var (string replace -- ~ \~ $$var)
- end
- functions --erase _fisher_fish_postexec
- end
-end
diff --git a/fish/functions/fundle.fish b/fish/functions/fundle.fish
new file mode 100644
index 0000000..2399145
--- /dev/null
+++ b/fish/functions/fundle.fish
@@ -0,0 +1,462 @@
+set __fundle_current_version '0.7.1'
+
+function __fundle_seq -a upto
+ seq 1 1 $upto 2>/dev/null
+end
+
+function __fundle_next_arg -a index
+ set -l args $argv[2..-1]
+ set -l arg_index (math $index + 1)
+ if test (count $args) -lt $arg_index
+ echo "missing argument for $args[$index]"
+ return 1
+ end
+ set -l arg $args[$arg_index]
+ switch $arg
+ case '--*'
+ echo "expected argument for $args[$index], got $arg"; and return 1
+ case '*'
+ echo $arg; and return 0
+ end
+end
+
+function __fundle_compare_versions -a version1 -a version2
+ for i in (__fundle_seq 4)
+ set -l v1 (echo $version1 | cut -d '.' -f $i | sed -Ee 's/[a-z]+//g')
+ set -l v2 (echo $version2 | cut -d '.' -f $i | sed -Ee 's/[a-z]+//g')
+ if test \( -n $v1 -a -z $v2 \) -o \( -n $v1 -a -n $v2 -a $v1 -lt $v2 \)
+ echo -n "lt"; and return 0
+ else if test \( -z $v1 -a -n $v2 \) -o \( -n $v1 -a -n $v2 -a $v1 -gt $v2 \)
+ echo -n "gt"; and return 0
+ end
+ end
+ echo -n "eq"; and return 0
+end
+
+function __fundle_date -d "returns a date"
+ set -l d (date +%s%N)
+ if echo $d | string match -rvq 'N'
+ echo $d
+ else
+ gdate +%s%N
+ end
+ return 0
+end
+
+function __fundle_self_update -d "updates fundle"
+ set -l fundle_repo_url "https://github.com/tuvistavie/fundle.git"
+ # This `sed` stays for now since doing it easily with `string` requires "--filter", which is only in 2.6.0
+ set -l latest (command git ls-remote --tags $fundle_repo_url | sed -n -e 's|.*refs/tags/v\(.*\)|\1|p' | tail -n 1)
+ if test (__fundle_compare_versions $latest (__fundle_version)) != "gt"
+ echo "fundle is already up to date"; and return 0
+ else
+ set -l file_url_template 'https://raw.githubusercontent.com/tuvistavie/fundle/VERSION/functions/fundle.fish'
+ set -l file_url (string replace 'VERSION' -- "v$latest" $file_url_template)
+ set -l tmp_file (mktemp /tmp/fundle.XXX)
+ set -l update_message "fundle has been updated to version $latest"
+ curl -Ls $file_url > $tmp_file; and mv $tmp_file (status -f); and echo $update_message; and return 0
+ end
+end
+
+function __fundle_url_rev -d "prints the revision from the url" -a git_url
+ set -l rev (echo $git_url | cut -d '#' -f 2 -s)
+ if test -n "$rev"
+ echo $rev
+ else
+ echo HEAD
+ end
+end
+
+function __fundle_remote_url -d "prints the remote url from the full git url" -a git_url
+ echo $git_url | cut -d '#' -f 1
+end
+
+function __fundle_rev_parse -d "prints the revision if any" -a dir -a commitish
+ set -l sha (command git --git-dir $dir rev-parse -q --verify $commitish 2>/dev/null)
+ if test $status -eq 0
+ echo -n $sha
+ return 0
+ end
+ return 1
+end
+
+function __fundle_commit_sha -d "returns sha of the commit-ish" -a dir -a commitish
+ if test -d "$dir/.git"
+ set dir "$dir/.git"
+ end
+ if __fundle_rev_parse $dir "origin/$commitish"
+ return 0
+ end
+ __fundle_rev_parse $dir $commitish
+end
+
+function __fundle_plugins_dir -d "returns fundle directory"
+ if test -z "$fundle_plugins_dir"
+ if test -n "$XDG_CONFIG_HOME"
+ echo $XDG_CONFIG_HOME/fish/fundle
+ else
+ echo $HOME/.config/fish/fundle
+ end
+ else
+ echo $fundle_plugins_dir
+ end
+end
+
+function __fundle_no_git -d "check if git is installed"
+ # `command -q` is >= 2.5.0
+ if not command -s git > /dev/null 2>&1
+ echo "git needs to be installed and in the path"
+ return 0
+ end
+ return 1
+end
+
+function __fundle_check_date -d "check date"
+ if date +%s%N | string match -rvq 'N'
+ return 0
+ end
+ if command -s gdate > /dev/null 2>&1
+ return 0
+ end
+ echo "You need to have a GNU date compliant date installed to use profiling. Use 'brew install coreutils' on OSX"
+ return 1
+end
+
+function __fundle_get_url -d "returns the url for the given plugin" -a repo
+ set split (string split @ $repo)
+ set repo $split[1]
+ set tag $split[2]
+ set url "https://github.com/$repo.git"
+
+ test ! -z "$tag"; and set url (string join "#tags/" "$url" "$tag")
+ echo "$url"
+end
+
+
+function __fundle_plugin_index -d "returns the index of the plugin" -a plugin
+ for i in (__fundle_seq (count $__fundle_plugin_names))
+ if test "$__fundle_plugin_names[$i]" = "$plugin"
+ return $i
+ end
+ end
+ # NOTE: should never reach this point
+ echo "could not find plugin: $plugin"
+ exit 1
+end
+
+function __fundle_checkout_revision -a plugin -a git_url
+ set -l plugin_dir (__fundle_plugins_dir)/$plugin
+ set -l git_dir $plugin_dir/.git
+
+ set -l sha (__fundle_commit_sha $git_dir (__fundle_url_rev $git_url))
+ if test $status -eq 0
+ command git --git-dir="$git_dir" --work-tree="$plugin_dir" checkout -q -f $sha
+ else
+ echo "Could not checkout $plugin revision $sha"
+ return 1
+ end
+end
+
+function __fundle_update_plugin -d "update the given plugin" -a plugin -a git_url
+ echo "Updating $plugin"
+
+ set -l remote_url (__fundle_remote_url $git_url)
+ set -l git_dir (__fundle_plugins_dir)/$plugin/.git
+
+ command git --git-dir=$git_dir remote set-url origin $remote_url 2>/dev/null
+ command git --git-dir=$git_dir fetch -q 2>/dev/null
+
+ __fundle_checkout_revision $plugin $git_url
+end
+
+function __fundle_install_plugin -d "install the given plugin" -a plugin -a git_url
+ if __fundle_no_git
+ return 1
+ end
+
+ set -l plugin_dir (__fundle_plugins_dir)/$plugin
+ set -l git_dir $plugin_dir/.git
+ set -l remote_url (__fundle_remote_url $git_url)
+
+ if test -d $plugin_dir
+ echo "$argv[1] installed in $plugin_dir"
+ return 0
+ else
+ echo "Installing $plugin"
+ command git clone -q $remote_url $plugin_dir
+ __fundle_checkout_revision $plugin $git_url
+ end
+end
+
+function __fundle_update -d "update the given plugin, or all if unspecified" -a plugin
+ if test -n "$plugin"; and test ! -d (__fundle_plugins_dir)/$plugin/.git
+ echo "$plugin not installed. You may need to run 'fundle install'"
+ return 1
+ end
+
+ if test -n "$plugin"
+ set -l index (__fundle_plugin_index $plugin)
+ __fundle_update_plugin "$plugin" $__fundle_plugin_urls[$index]
+ else
+ for i in (__fundle_seq (count $__fundle_plugin_names))
+ __fundle_update_plugin $__fundle_plugin_names[$i] $__fundle_plugin_urls[$i]
+ end
+ end
+end
+
+function __fundle_show_doc_msg -d "show a link to fundle docs"
+ if test (count $argv) -ge 1
+ echo $argv
+ end
+ echo "See the docs for more info. https://github.com/tuvistavie/fundle"
+end
+
+function __fundle_load_plugin -a plugin -a path -a fundle_dir -a profile -d "load a plugin"
+ if begin; set -q __fundle_loaded_plugins; and contains $plugin $__fundle_loaded_plugins; end
+ return 0
+ end
+
+ set -l plugin_dir (string replace -r '/.$' '' -- "$fundle_dir/$plugin/$path")
+
+ if not test -d $plugin_dir
+ __fundle_show_doc_msg "$plugin not installed. You may need to run 'fundle install'"
+ return 1
+ end
+
+ # Take everything but "plugin-" from the last path component
+ set -l plugin_name (string replace -r '.*/(plugin-)?(.*)$' '$2' -- $plugin)
+ set -l init_file "$plugin_dir/init.fish"
+ set -l conf_dir "$plugin_dir/conf.d"
+ set -l bindings_file "$plugin_dir/key_bindings.fish"
+ set -l functions_dir "$plugin_dir/functions"
+ set -l completions_dir "$plugin_dir/completions"
+ set -l plugin_paths $__fundle_plugin_name_paths
+
+ if begin; test -d $functions_dir; and not contains $functions_dir $fish_function_path; end
+ set fish_function_path $fish_function_path[1] $functions_dir $fish_function_path[2..-1]
+ end
+
+ if begin; test -d $completions_dir; and not contains $completions_dir $fish_complete_path; end
+ set fish_complete_path $fish_complete_path[1] $completions_dir $fish_complete_path[2..-1]
+ end
+
+ if test -f $init_file
+ source $init_file
+ else if test -d $conf_dir
+ # read all *.fish files in conf.d
+ for f in $conf_dir/*.fish
+ source $f
+ end
+ else
+ # For compatibility with oh-my-fish themes, if there is no `init.fish` file in the plugin,
+ # which is the case with themses, the root directory of the plugin is trerated as a functions
+ # folder, so we include it in the `fish_function_path` variable.
+ if not contains $plugin_dir $fish_function_path
+ set fish_function_path $fish_function_path[1] $plugin_dir $fish_function_path[2..-1]
+ end
+ end
+
+ if test -f $bindings_file
+ set -g __fundle_binding_paths $bindings_file $__fundle_binding_paths
+ end
+
+ set -g __fundle_loaded_plugins $plugin $__fundle_loaded_plugins
+
+ set -l dependencies (printf '%s\n' $plugin_paths $__fundle_plugin_name_paths | sort | uniq -u)
+ for dependency in $dependencies
+ set -l name_path (string split : -- $dependency)
+ if test "$profile" -eq 1
+ set -l start_time (__fundle_date +%s%N)
+ __fundle_load_plugin $name_path[1] $name_path[2] $fundle_dir $profile
+ set -l ellapsed_time (math \((__fundle_date +%s%N) - $start_time\) / 1000)
+ echo "$name_path[1]": {$ellapsed_time}us
+ else
+ __fundle_load_plugin $name_path[1] $name_path[2] $fundle_dir $profile
+ end
+ end
+
+ emit "init_$plugin_name" $plugin_dir
+end
+
+function __fundle_bind -d "set up bindings"
+ if functions -q fish_user_key_bindings; and not functions -q __fish_user_key_bindings
+ functions -c fish_user_key_bindings __fish_user_key_bindings
+ end
+
+ function fish_user_key_bindings
+ for bindings in $__fundle_binding_paths
+ source $bindings
+ end
+ if functions -q __fish_user_key_bindings
+ __fish_user_key_bindings
+ end
+ end
+end
+
+function __fundle_init -d "initialize fundle"
+ set -l fundle_dir (__fundle_plugins_dir)
+
+ if test (count $__fundle_plugin_names) -eq 0
+ __fundle_show_doc_msg "No plugin registered. You need to call 'fundle plugin NAME' before using 'fundle init'. \
+
+Try reloading your shell if you just edited your configuration."
+ return 1
+ end
+
+ set -l profile 0
+ if begin; contains -- -p $argv; or contains -- --profile $argv; and __fundle_check_date; end
+ set profile 1
+ end
+
+ set -l has_uninstalled_plugins 0
+ for name_path in $__fundle_plugin_name_paths
+ set -l name_path (string split : -- $name_path)
+ if test "$profile" -eq 1
+ set -l start_time (__fundle_date +%s%N)
+ __fundle_load_plugin $name_path[1] $name_path[2] $fundle_dir $profile
+ set -l ellapsed_time (math \((__fundle_date +%s%N) - $start_time\) / 1000)
+ echo "$name_path[1]": {$ellapsed_time}us
+ else
+ __fundle_load_plugin $name_path[1] $name_path[2] $fundle_dir $profile || set has_uninstalled_plugins 1
+ end
+ end
+
+ __fundle_bind
+ return $has_uninstalled_plugins
+end
+
+function __fundle_install -d "install plugin"
+ if test (count $__fundle_plugin_names) -eq 0
+ __fundle_show_doc_msg "No plugin registered. You need to call 'fundle plugin NAME' before using 'fundle install'"
+ end
+
+ for i in (__fundle_seq (count $__fundle_plugin_names))
+ __fundle_install_plugin $__fundle_plugin_names[$i] $__fundle_plugin_urls[$i] $argv
+ end
+
+ set -l original_plugins_count (count (__fundle_list -s))
+ __fundle_init
+
+ # if plugins count increase after init, new plugins have dependencies
+ # install new plugins dependencies if any
+ if test (count (__fundle_list -s)) -gt $original_plugins_count
+ __fundle_install $argv
+ end
+end
+
+function __fundle_clean -d "cleans fundle directory"
+ set -l fundle_dir (__fundle_plugins_dir)
+ set -l used_plugins (__fundle_list -s)
+ set -l installed_plugins $fundle_dir/*/*/
+ for installed_plugin in $installed_plugins
+ set -l plugin (string trim --chars="/" \
+ (string replace -r -- "$fundle_dir" "" $installed_plugin))
+ if not contains $plugin $used_plugins
+ echo "Removing $plugin"
+ rm -rf $fundle_dir/$plugin
+ end
+ end
+end
+
+function __fundle_plugin -d "add plugin to fundle" -a name
+ set -l plugin_url ""
+ set -l plugin_path "."
+ set -l argv_count (count $argv)
+ set -l skip_next true
+ if test $argv_count -eq 0 -o -z "$argv"
+ echo "usage: fundle plugin NAME [[--url] URL] [--path PATH]"
+ return 1
+ else if test $argv_count -gt 1
+ for i in (__fundle_seq (count $argv))
+ test $skip_next = true; and set skip_next false; and continue
+ set -l arg $argv[$i]
+ switch $arg
+ case '--url'
+ set plugin_url (__fundle_next_arg $i $argv)
+ test $status -eq 1; and echo $plugin_url; and return 1
+ set skip_next true
+ case '--path'
+ set plugin_path (__fundle_next_arg $i $argv)
+ test $status -eq 1; and echo $plugin_path; and return 1
+ set skip_next true
+ case '--*'
+ echo "unknown flag $arg"; and return 1
+ case '*'
+ test $i -ne 2; and echo "invalid argument $arg"; and return 1
+ set plugin_url $arg
+ end
+ end
+ end
+ test -z "$plugin_url"; and set plugin_url (__fundle_get_url $name)
+ set name (string split @ $name)[1]
+
+ if not contains $name $__fundle_plugin_names
+ set -g __fundle_plugin_names $__fundle_plugin_names $name
+ set -g __fundle_plugin_urls $__fundle_plugin_urls $plugin_url
+ set -g __fundle_plugin_name_paths $__fundle_plugin_name_paths $name:$plugin_path
+ end
+end
+
+function __fundle_version -d "prints fundle version"
+ echo $__fundle_current_version
+end
+
+function __fundle_print_help -d "prints fundle help"
+ echo "usage: fundle (init | plugin | list | install | update | clean | self-update | version | help)"
+end
+
+function __fundle_list -d "list registered plugins"
+ if begin; contains -- -s $argv; or contains -- --short $argv; end
+ for name in $__fundle_plugin_names
+ echo $name
+ end
+ else
+ for i in (__fundle_seq (count $__fundle_plugin_names))
+ echo {$__fundle_plugin_names[$i]}\n\t{$__fundle_plugin_urls[$i]}
+ end
+ end
+end
+
+function fundle -d "run fundle"
+ if __fundle_no_git
+ return 1
+ end
+
+ set -l sub_args ""
+
+ switch (count $argv)
+ case 0
+ __fundle_print_help
+ return 1
+ case 1
+ case '*'
+ set sub_args $argv[2..-1]
+ end
+
+ switch $argv[1]
+ case "init"
+ __fundle_init $sub_args
+ case "plugin"
+ __fundle_plugin $sub_args
+ case "list"
+ __fundle_list $sub_args
+ case "plugins"
+ echo "'fundle plugins' has been replaced by 'fundle list'"
+ case "install"
+ __fundle_install $sub_args
+ case "update"
+ __fundle_update $sub_args
+ case "clean"
+ __fundle_clean
+ case "self-update"
+ __fundle_self_update
+ case "version" -v --version
+ __fundle_version
+ case "help" -h --help
+ __fundle_print_help
+ return 0
+ case "*"
+ __fundle_print_help
+ return 1
+ end
+end