summaryrefslogtreecommitdiffstats
path: root/.config/fish
diff options
context:
space:
mode:
authorYigit Sever2022-05-15 00:01:08 +0300
committerYigit Sever2022-05-15 00:01:08 +0300
commita0a52e3cd4d35bffd43887cd62ed845a31bc3f1e (patch)
tree8d945acb374d8943070c21ff80bdac319c61a628 /.config/fish
parent5b7bc27c4d3df2a421f8ba1c22bf776c00141906 (diff)
downloaddotfiles-a0a52e3cd4d35bffd43887cd62ed845a31bc3f1e.tar.gz
dotfiles-a0a52e3cd4d35bffd43887cd62ed845a31bc3f1e.tar.bz2
dotfiles-a0a52e3cd4d35bffd43887cd62ed845a31bc3f1e.zip
fish: bring in async prompt
diffstat (limited to '.config/fish')
-rw-r--r--.config/fish/conf.d/__async_prompt.fish130
1 files changed, 130 insertions, 0 deletions
diff --git a/.config/fish/conf.d/__async_prompt.fish b/.config/fish/conf.d/__async_prompt.fish
new file mode 100644
index 0000000..8a51156
--- /dev/null
+++ b/.config/fish/conf.d/__async_prompt.fish
@@ -0,0 +1,130 @@
1# https://github.com/acomagu/fish-async-prompt/blob/master/conf.d/__async_prompt.fish
2status is-interactive
3or exit 0
4
5set -g __async_prompt_tmpdir (command mktemp -d)
6
7# Setup after the user defined prompt functions are loaded.
8function __async_prompt_setup_on_startup --on-event fish_prompt
9 functions -e (status current-function)
10
11 for func in (__async_prompt_config_functions)
12 function $func -V func
13 test -e $__async_prompt_tmpdir'/'$fish_pid'_'$func
14 and cat $__async_prompt_tmpdir'/'$fish_pid'_'$func
15 end
16 end
17end
18
19not set -q async_prompt_on_variable
20and set async_prompt_on_variable fish_bind_mode
21function __async_prompt_fire --on-event fish_prompt (for var in $async_prompt_on_variable; printf '%s\n' --on-variable $var; end)
22 set st $status
23
24 for func in (__async_prompt_config_functions)
25 set -l tmpfile $__async_prompt_tmpdir'/'$fish_pid'_'$func
26
27 if functions -q $func'_loading_indicator' && test -e $tmpfile
28 read -zl last_prompt <$tmpfile
29 eval (string escape -- $func'_loading_indicator' "$last_prompt") >$tmpfile
30 end
31
32 __async_prompt_config_inherit_variables | __async_prompt_spawn $st \
33 $func' | read -z prompt
34 echo -n $prompt >'$tmpfile
35 end
36end
37
38function __async_prompt_spawn
39 set -l envs
40 begin
41 set st $argv[1]
42 while read line
43 switch "$line"
44 case 'fish_bind_mode'
45 echo fish_bind_mode $fish_bind_mode
46 case FISH_VERSION PWD _ history 'fish_*' hostname version
47 case status
48 echo status $st
49 case SHLVL
50 set envs $envs SHLVL=(math $SHLVL - 1)
51 case '*'
52 echo $line (string escape -- $$line)
53 end
54 end
55 end | read -lz vars
56 echo $vars | env $envs fish -c '
57 function __async_prompt_set_status
58 return $argv
59 end
60 function __async_prompt_signal
61 kill -s "'(__async_prompt_config_internal_signal)'" '$fish_pid'
62 end
63 while read -a line
64 test -z "$line"
65 and continue
66
67 if test "$line[1]" = status
68 set st $line[2]
69 else
70 eval set "$line"
71 end
72 end
73
74 not set -q st
75 and true
76 or __async_prompt_set_status $st
77 '$argv[2]'
78 __async_prompt_signal
79 sleep 0.3
80 __async_prompt_signal
81 sleep 0.3
82 __async_prompt_signal' &
83 disown
84end
85
86function __async_prompt_config_inherit_variables
87 if set -q async_prompt_inherit_variables
88 if test "$async_prompt_inherit_variables" = all
89 set -ng
90 else
91 for item in $async_prompt_inherit_variables
92 echo $item
93 end
94 end
95 else
96 echo status
97 echo SHLVL
98 echo CMD_DURATION
99 echo fish_bind_mode
100 end
101end
102
103function __async_prompt_config_functions
104 set -l funcs (
105 if set -q async_prompt_functions
106 string join \n $async_prompt_functions
107 else
108 echo fish_prompt
109 echo fish_right_prompt
110 end
111 )
112 for func in $funcs
113 functions -q "$func"
114 or continue
115
116 echo $func
117 end
118end
119
120function __async_prompt_config_internal_signal
121 if test -z "$async_prompt_signal_number"
122 echo SIGUSR1
123 else
124 echo "$async_prompt_signal_number"
125 end
126end
127
128function __async_prompt_repaint_prompt --on-signal (__async_prompt_config_internal_signal)
129 commandline -f repaint >/dev/null 2>/dev/null
130end