diff options
Diffstat (limited to '.config/fish')
| -rw-r--r-- | .config/fish/conf.d/__async_prompt.fish | 130 |
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 | ||
| 2 | status is-interactive | ||
| 3 | or exit 0 | ||
| 4 | |||
| 5 | set -g __async_prompt_tmpdir (command mktemp -d) | ||
| 6 | |||
| 7 | # Setup after the user defined prompt functions are loaded. | ||
| 8 | function __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 | ||
| 17 | end | ||
| 18 | |||
| 19 | not set -q async_prompt_on_variable | ||
| 20 | and set async_prompt_on_variable fish_bind_mode | ||
| 21 | function __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 | ||
| 36 | end | ||
| 37 | |||
| 38 | function __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 | ||
| 84 | end | ||
| 85 | |||
| 86 | function __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 | ||
| 101 | end | ||
| 102 | |||
| 103 | function __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 | ||
| 118 | end | ||
| 119 | |||
| 120 | function __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 | ||
| 126 | end | ||
| 127 | |||
| 128 | function __async_prompt_repaint_prompt --on-signal (__async_prompt_config_internal_signal) | ||
| 129 | commandline -f repaint >/dev/null 2>/dev/null | ||
| 130 | end | ||
