diff --git a/plugins/gi/_update_gi_completions.fish b/plugins/gi/_update_gi_completions.fish new file mode 100644 index 0000000..9d80857 --- /dev/null +++ b/plugins/gi/_update_gi_completions.fish @@ -0,0 +1,21 @@ +function _update_gi_completions -d "Update completions for gitignore.io" + set compl_dir ~/.config/fish/completions + set compl_file "$compl_dir/gi.fish" + + # Download list of ignore types + set -l gi_list (gi list | tr ',' ' ') + if test -z $gi_list + echo "No result returned from gitignore.io" >&2 + return 1 + end + + # Backup existing completions + if test -e $compl_file + mv -f $compl_file {$compl_file}.bak + else if not test -d $compl_dir + mkdir -p $compl_dir + end + + # Output new completions + echo complete -c gi -a \"update-completions $gi_list\" >$compl_file +end diff --git a/plugins/gi/gi.fish b/plugins/gi/gi.fish new file mode 100644 index 0000000..f63b93f --- /dev/null +++ b/plugins/gi/gi.fish @@ -0,0 +1,9 @@ +function gi -d "gitignore.io cli for fish" + if test $argv[1] = 'update-completions' + _update_gi_completions + return $status + end + + set -l params (echo $argv|tr ' ' ',') + curl -s http://www.gitignore.io/api/$params +end diff --git a/plugins/gi/gi.load b/plugins/gi/gi.load deleted file mode 100644 index 2cd6aa5..0000000 --- a/plugins/gi/gi.load +++ /dev/null @@ -1,18 +0,0 @@ -# gitignore.io cli for fish - -function gi - set -l params (echo $argv|tr ' ' ',') - curl -s http://www.gitignore.io/api/$params -end - -# enable the complation by invoking `gi list` -if not set -q -g gi_list - ping -t 2 -c 1 -q gitignore.io >/dev/null - set gi_available $status - - if test $gi_available - set -g gi_list (gi list| tr ',' ' ' ^/dev/null) - end -end - -complete -c gi -a "$gi_list"