mirror of
https://github.com/oh-my-fish/oh-my-fish
synced 2024-11-03 15:40:32 +00:00
Redesign gitignore plugin
- removed code that fetches completions frim gitignore.io each time fish is started -- makes logins slow! - gi.load becomes gi.fish, only contains gi function - add _update_gi_completions.fish: fetches list of completions from gitignore.io and places it into ~/.config/fish/completions - modify gi function to accept update-completions argument
This commit is contained in:
parent
1e7e712f87
commit
5829ff0f5a
21
plugins/gi/_update_gi_completions.fish
Normal file
21
plugins/gi/_update_gi_completions.fish
Normal file
@ -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
|
9
plugins/gi/gi.fish
Normal file
9
plugins/gi/gi.fish
Normal file
@ -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
|
@ -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"
|
Loading…
Reference in New Issue
Block a user