-
Notifications
You must be signed in to change notification settings - Fork 19
/
tacklebox.fish
144 lines (121 loc) · 4.02 KB
/
tacklebox.fish
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Tacklebox: https://github.com/justinmayer/tacklebox
###
# Helper functions
###
function __tacklebox_add_plugin
set -l plugin "$argv[1]"
set -l plugin_path "plugins/$plugin"
for repository in $tacklebox_path[-1..1]
__tacklebox_prepend_path $repository/$plugin_path fish_function_path
end
end
function __tacklebox_add_module
set -l module "$argv[1]"
set -l module_path "modules/$module"
for repository in $tacklebox_path[-1..1]
for module_file in $repository/$module_path/*.fish
source $module_file
end
end
end
function __tacklebox_add_completion
set -l plugin "$argv[1]"
set -l completion_path "plugins/$plugin/completions"
for repository in $tacklebox_path[-1..1]
__tacklebox_prepend_path $repository/$completion_path fish_complete_path
end
end
function __tacklebox_source_plugin_load_file
set -l plugin "$argv[1]"
set -l load_file_path "plugins/$plugin/$plugin.load"
for repository in $tacklebox_path[-1..1]
if test -e $repository/$load_file_path
source $repository/$load_file_path
end
end
end
function __tacklebox_load_theme
set -l theme "$argv[1]"
set -l theme_path "themes/$theme"
for repository in $tacklebox_path[-1..1]
__tacklebox_prepend_path $repository/$theme_path fish_function_path
end
end
function __tacklebox_strip_word --no-scope-shadowing --description '__tacklebox_strip_word word varname'
set -l word "$argv[1]"
set -l list "$argv[2]"
if set -l idx (contains -i -- $word $$list)
set -e -- {$list}[$idx]
else
return 1
end
end
function __tacklebox_prepend_path --no-scope-shadowing --description \
'Prepend the given path, if it exists, to the specified path list (defaults to PATH)'
set -l path "$argv[1]"
set -l list PATH
if set -q argv[2]
set list $argv[2]
end
if test -d $path
# If the path is already in the list, remove it first.
# Prepending puts it in front, where it belongs
if set -l idx (contains -i -- $path $$list)
set -e -- {$list}[$idx]
end
set -- $list $path $$list
end
end
function __tacklebox_append_path --no-scope-shadowing --description \
'Append the given path, if it exists, to the specified path list (defaults to PATH)'
set -l path "$argv[1]"
set -l list PATH
if set -q argv[2]
set list $argv[2]
end
if test -d $path
# If the path is already in the list, skip it.
if not contains -- $path $$list
set -- $list $$list $path
end
end
end
###
# Configuration
###
# Support Fish 2.x and 3.x data directories, respectively
set -l fish_data_dir $__fish_datadir $__fish_data_dir
# Standardize function path, to be restored later.
set -l user_function_path $fish_function_path
# Ensure the function path is global, not universal
set -g fish_function_path "$fish_data_dir/functions"
# Add all functions
for repository in $tacklebox_path[-1..1]
__tacklebox_prepend_path $repository/functions fish_function_path
end
# Add all specified plugins
for plugin in $tacklebox_plugins
__tacklebox_add_plugin $plugin
__tacklebox_add_completion $plugin
__tacklebox_source_plugin_load_file $plugin
end
# Add all specified modules
for module in $tacklebox_modules
__tacklebox_add_module $module
end
# Load user-specified theme
if test -n "$tacklebox_theme"
__tacklebox_load_theme $tacklebox_theme
end
# Add back the user and sysconf functions as appropriate
for path in $fish_function_path
# don't append either system path
if not contains -- "$path" "$__fish_sysconfdir/functions" "$fish_data_dir/functions"
__tacklebox_append_path $path user_function_path
end
end
if __tacklebox_strip_word "$__fish_sysconfdir/functions" user_function_path
set user_function_path $user_function_path "$__fish_sysconfdir/functions"
end
__tacklebox_strip_word "$fish_data_dir/functions" user_function_path
set -g fish_function_path $user_function_path "$fish_data_dir/functions"