Skip to content

Commit e953fcd

Browse files
authored
Merge pull request #40 from phanen/perf/startup
perf(startup): skip load of fifc rules when in interactive shell
2 parents 1bc3014 + 6681b51 commit e953fcd

File tree

2 files changed

+55
-66
lines changed

2 files changed

+55
-66
lines changed

conf.d/fifc.fish

Lines changed: 54 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,64 @@
1-
# Keybindings
2-
for mode in default insert
3-
if not set --query --universal fifc_keybinding
1+
if status is-interactive
2+
# Keybindings
3+
set -qU fifc_keybinding
4+
or set -U fifc_keybinding \t
5+
6+
set -qU fifc_open_keybinding
7+
or set -U fifc_open_keybinding ctrl-o
8+
9+
for mode in default insert
410
bind --mode $mode \t _fifc
5-
else
611
bind --mode $mode $fifc_keybinding _fifc
712
end
8-
end
9-
10-
if not set --query --universal fifc_open_keybinding
11-
set --universal fifc_open_keybinding ctrl-o
12-
end
13-
1413

15-
# Private
16-
set -gx _fifc_comp_count 0
17-
set -gx _fifc_unordered_comp
18-
set -gx _fifc_ordered_comp
14+
# Only load fifc rules when fish is launched fzf
15+
else if set -q _fifc_launched_by_fzf
16+
# Private
17+
set -gx _fifc_comp_count 0
18+
set -gx _fifc_unordered_comp
19+
set -gx _fifc_ordered_comp
1920

20-
# Set sources
21-
fifc \
22-
-n 'test "$fifc_group" = "directories"' \
23-
-s _fifc_source_directories
24-
fifc \
25-
-n 'test "$fifc_group" = "files"' \
26-
-s _fifc_source_files
27-
fifc \
28-
-n 'test "$fifc_group" = processes' \
29-
-s 'ps -ax -o pid=,command='
30-
31-
# Builtin preview/open commands
32-
fifc \
33-
-n 'test "$fifc_group" = "options"' \
34-
-p _fifc_preview_opt \
35-
-o _fifc_open_opt
36-
fifc \
37-
-n 'test \( -n "$fifc_desc" -o -z "$fifc_commandline" \); and type -q -f -- "$fifc_candidate"' \
38-
-r '^(?!\\w+\\h+)' \
39-
-p _fifc_preview_cmd \
40-
-o _fifc_open_cmd
41-
fifc \
42-
-n 'test -n "$fifc_desc" -o -z "$fifc_commandline"' \
43-
-r '^(functions)?\\h+' \
44-
-p _fifc_preview_fn \
45-
-o _fifc_open_fn
46-
fifc \
47-
-n 'test -f "$fifc_candidate"' \
48-
-p _fifc_preview_file \
49-
-o _fifc_open_file
50-
fifc \
51-
-n 'test -d "$fifc_candidate"' \
52-
-p _fifc_preview_dir \
53-
-o _fifc_open_dir
54-
fifc \
55-
-n 'test "$fifc_group" = processes -a (ps -p (_fifc_parse_pid "$fifc_candidate") &>/dev/null)' \
56-
-p _fifc_preview_process \
57-
-o _fifc_open_process \
58-
-e '^\\h*([0-9]+)'
21+
# Set sources
22+
fifc \
23+
-n 'test "$fifc_group" = "directories"' \
24+
-s _fifc_source_directories
25+
fifc \
26+
-n 'test "$fifc_group" = "files"' \
27+
-s _fifc_source_files
28+
fifc \
29+
-n 'test "$fifc_group" = processes' \
30+
-s 'ps -ax -o pid=,command='
5931

32+
# Builtin preview/open commands
33+
fifc \
34+
-n 'test "$fifc_group" = "options"' \
35+
-p _fifc_preview_opt \
36+
-o _fifc_open_opt
37+
fifc \
38+
-n 'test \( -n "$fifc_desc" -o -z "$fifc_commandline" \); and type -q -f -- "$fifc_candidate"' \
39+
-r '^(?!\\w+\\h+)' \
40+
-p _fifc_preview_cmd \
41+
-o _fifc_open_cmd
42+
fifc \
43+
-n 'test -n "$fifc_desc" -o -z "$fifc_commandline"' \
44+
-r '^(functions)?\\h+' \
45+
-p _fifc_preview_fn \
46+
-o _fifc_open_fn
47+
fifc \
48+
-n 'test -f "$fifc_candidate"' \
49+
-p _fifc_preview_file \
50+
-o _fifc_open_file
51+
fifc \
52+
-n 'test -d "$fifc_candidate"' \
53+
-p _fifc_preview_dir \
54+
-o _fifc_open_dir
55+
fifc \
56+
-n 'test "$fifc_group" = processes -a (ps -p (_fifc_parse_pid "$fifc_candidate") &>/dev/null)' \
57+
-p _fifc_preview_process \
58+
-o _fifc_open_process \
59+
-e '^\\h*([0-9]+)'
60+
end
6061

6162
# Fisher
6263
function _fifc_uninstall --on-event fifc_uninstall
63-
for i in (seq (count $_fifc_unordered_comp))
64-
set -e $_fifc_unordered_comp[$i]
65-
end
66-
67-
for i in (seq (count $_fifc_ordered_comp))
68-
set -e $_fifc_ordered_comp[$i]
69-
end
70-
71-
set -e _fifc_comp_count
72-
set -e _fifc_source_count
73-
set -e _fifc_unordered_comp
74-
set -e _fifc_ordered_comp
7564
end

functions/_fifc.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function _fifc
2828
set fifc_fzf_query (string trim --chars '\'' -- "$fifc_fzf_query")
2929

3030
set -l fzf_cmd "
31-
fzf \
31+
_fifc_launched_by_fzf=1 SHELL=fish fzf \
3232
-d \t \
3333
--exact \
3434
--tiebreak=length \

0 commit comments

Comments
 (0)