From 7059667c1242a9408ada2b417b11c7423a49e4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Mar=C3=B3y?= Date: Sat, 20 Apr 2024 10:39:55 +0200 Subject: [PATCH 1/3] Use universal variables instead of tmpfiles --- conf.d/__async_prompt.fish | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/conf.d/__async_prompt.fish b/conf.d/__async_prompt.fish index adc5dc4..145002a 100644 --- a/conf.d/__async_prompt.fish +++ b/conf.d/__async_prompt.fish @@ -1,7 +1,7 @@ status is-interactive or exit 0 -set -g __async_prompt_tmpdir (command mktemp -d) +set -g __async_prompt_var _async_prompt_$fish_pid # Setup after the user defined prompt functions are loaded. function __async_prompt_setup_on_startup --on-event fish_prompt @@ -11,9 +11,12 @@ function __async_prompt_setup_on_startup --on-event fish_prompt end for func in (__async_prompt_config_functions) + set -U $__async_prompt_var'_'$func function $func -V func - test -e $__async_prompt_tmpdir'/'$fish_pid'_'$func - and cat $__async_prompt_tmpdir'/'$fish_pid'_'$func + if set -q $__async_prompt_var'_'$func + set -l result $__async_prompt_var'_'$func + echo -n $$result + end end end end @@ -26,16 +29,12 @@ not set -q async_prompt_on_variable and set async_prompt_on_variable fish_bind_mode function __async_prompt_fire --on-event fish_prompt (for var in $async_prompt_on_variable; printf '%s\n' --on-variable $var; end) for func in (__async_prompt_config_functions) - set -l tmpfile $__async_prompt_tmpdir'/'$fish_pid'_'$func - - if functions -q $func'_loading_indicator' && test -e $tmpfile - read -zl last_prompt <$tmpfile - eval (string escape -- $func'_loading_indicator' "$last_prompt") >$tmpfile + if functions -q $func'_loading_indicator' && set -q $__async_prompt_var'_'$func + set $__async_prompt_var'_'$func ($func'_loading_indicator' $__async_prompt_var'_'$func) end __async_prompt_config_inherit_variables | __async_prompt_spawn \ - $func' | read -z prompt - echo -n $prompt >'$tmpfile + $func end end @@ -134,10 +133,10 @@ function __async_prompt_spawn -a cmd else true end - '$cmd' + set '$__async_prompt_var\'_\'$cmd' ('$cmd') __async_prompt_signal' & if test (__async_prompt_config_disown) = 1 - disown + builtin disown end end @@ -196,6 +195,15 @@ function __async_prompt_repaint_prompt --on-signal (__async_prompt_config_intern commandline -f repaint >/dev/null 2>/dev/null end -function __async_prompt_tmpdir_cleanup --on-event fish_exit - rm -rf "$__async_prompt_tmpdir" +function __async_prompt_variable_cleanup --on-event fish_exit + set -l prefix (string replace $fish_pid '' $__async_prompt_var) + set -l prompt_vars (set --show | string match -rg '^\$('"$prefix"'\d+_[a-z_]+):' | uniq) + for var in $prompt_vars + set -l pid (string match -rg '^'"$prefix"'(\d+)_[a-z_]+' $var) + if not ps $pid &> /dev/null + or test $pid -eq $fish_pid + set -Ue $var + end + end + set -ge __async_prompt_var end From 44cfaa90f60063f1c05e92a5c89568b1db44b7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Mar=C3=B3y?= Date: Sun, 21 Apr 2024 11:35:03 +0200 Subject: [PATCH 2/3] Clean up danglind prompt variables on exit --- conf.d/__async_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf.d/__async_prompt.fish b/conf.d/__async_prompt.fish index 145002a..3c55e2b 100644 --- a/conf.d/__async_prompt.fish +++ b/conf.d/__async_prompt.fish @@ -195,7 +195,7 @@ function __async_prompt_repaint_prompt --on-signal (__async_prompt_config_intern commandline -f repaint >/dev/null 2>/dev/null end -function __async_prompt_variable_cleanup --on-event fish_exit +function __async_prompt_tmpdir_cleanup --on-event fish_exit set -l prefix (string replace $fish_pid '' $__async_prompt_var) set -l prompt_vars (set --show | string match -rg '^\$('"$prefix"'\d+_[a-z_]+):' | uniq) for var in $prompt_vars From 41c7a16fec0339ba9e55ea66183fda8504e290fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Mar=C3=B3y?= Date: Sun, 21 Apr 2024 11:35:45 +0200 Subject: [PATCH 3/3] Rename cleanup function as tmpdir is not used anymore --- conf.d/__async_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf.d/__async_prompt.fish b/conf.d/__async_prompt.fish index 3c55e2b..145002a 100644 --- a/conf.d/__async_prompt.fish +++ b/conf.d/__async_prompt.fish @@ -195,7 +195,7 @@ function __async_prompt_repaint_prompt --on-signal (__async_prompt_config_intern commandline -f repaint >/dev/null 2>/dev/null end -function __async_prompt_tmpdir_cleanup --on-event fish_exit +function __async_prompt_variable_cleanup --on-event fish_exit set -l prefix (string replace $fish_pid '' $__async_prompt_var) set -l prompt_vars (set --show | string match -rg '^\$('"$prefix"'\d+_[a-z_]+):' | uniq) for var in $prompt_vars