summaryrefslogtreecommitdiff
path: root/dot_config/private_fish/functions/autosource.fish
blob: c0642180a547000e8f5a2fbfeedbe6b86f9a4766 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
set -q __fish_autosource_path
or set __fish_autosource_path $__fish_config_dir/plug

# you must include '' for completions to work
set -q __fish_autosource_exts
or set __fish_autosource_exts .fish ''

function autosource -S -d 'Source plugin'
    for plug in $argv
        for f in $__fish_autosource_path/$plug$__fish_autosource_exts
            if test -f $f -a -r $f
                source $f
                break
            end
        end
    end
end

function __complete_autosource
    for d in $__fish_autosource_path
        set -l len (math (string length $d) + 2) # 1-index + /
        for f in $d/**$__fish_autosource_exts
            if test -f $f -a -r $f
                echo $f | string sub -s $len
            end
        end
    end | sort | uniq
end

complete -c autosource -x -a "(__complete_autosource)"