From f6262a2e280c747695e7cf60a7c1c2e9e7a25902 Mon Sep 17 00:00:00 2001 From: Ilan Cosman Date: Wed, 25 Nov 2020 09:22:35 -0800 Subject: [PATCH] Set variables in background job --- functions/_tide_item_cmd_duration.fish | 8 ++++---- functions/fish_prompt.fish | 17 ++++++++++------- functions/tide/tests/cmd_duration.fish | 2 +- functions/tide/tests/context.fish | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/functions/_tide_item_cmd_duration.fish b/functions/_tide_item_cmd_duration.fish index 31831ec..4e9f122 100644 --- a/functions/_tide_item_cmd_duration.fish +++ b/functions/_tide_item_cmd_duration.fish @@ -1,8 +1,8 @@ function _tide_item_cmd_duration - if test $_tide_cmd_duration -gt $tide_cmd_duration_threshold - set -l seconds (math --scale=$tide_cmd_duration_decimals "$_tide_cmd_duration/1000" % 60) - set -l minutes (math --scale=0 "$_tide_cmd_duration/60000" % 60) - set -l hours (math --scale=0 "$_tide_cmd_duration/3600000") + if test $CMD_DURATION -gt $tide_cmd_duration_threshold + set -l seconds (math --scale=$tide_cmd_duration_decimals "$CMD_DURATION/1000" % 60) + set -l minutes (math --scale=0 "$CMD_DURATION/60000" % 60) + set -l hours (math --scale=0 "$CMD_DURATION/3600000") set_color $tide_cmd_duration_color diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index e37dc44..8961300 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -1,13 +1,16 @@ function fish_prompt - set -lx _tide_last_pipestatus $pipestatus - set -lx _tide_last_status $status - set -lx _tide_fish_pid $fish_pid # Used for right prompt + fish --command " + set -g _tide_last_pipestatus $pipestatus + set -g _tide_last_status $status + set -g _tide_fish_pid $fish_pid + + test -n \"$SSH_TTY\" && set -g SSH_TTY + set COLUMNS $COLUMNS + set CMD_DURATION $CMD_DURATION - set -lx COLUMNS $COLUMNS - set -q SSH_TTY && set -lx SSH_TTY $SSH_TTY - set -lx _tide_cmd_duration $CMD_DURATION + command kill $_tide_last_pid 2>/dev/null + set -U _tide_left_prompt_display_$fish_pid (_tide_prompt)" & - fish --command "command kill $_tide_last_pid 2>/dev/null; set -U _tide_left_prompt_display_$fish_pid (_tide_prompt)" & set -g _tide_last_pid (jobs --last --pid) disown diff --git a/functions/tide/tests/cmd_duration.fish b/functions/tide/tests/cmd_duration.fish index a81d59a..2899e1d 100644 --- a/functions/tide/tests/cmd_duration.fish +++ b/functions/tide/tests/cmd_duration.fish @@ -1,7 +1,7 @@ @mesg '---------cmd_duration---------' function _cmd_duration -a duration threshold decimals - set -lx _tide_cmd_duration $duration + set -lx CMD_DURATION $duration set -lx tide_cmd_duration_threshold $threshold set -lx tide_cmd_duration_decimals $decimals diff --git a/functions/tide/tests/context.fish b/functions/tide/tests/context.fish index 707e00f..a8783f0 100644 --- a/functions/tide/tests/context.fish +++ b/functions/tide/tests/context.fish @@ -8,5 +8,5 @@ end @test 'None' -z (set -lx tide_context_always_display false; _context) @test 'Default' (set -lx tide_context_always_display true; _context ) = $USER'@'$hostname -@test 'SSH' (set -g SSH_TTY 'true'; _context) = $USER'@'$hostname +@test 'SSH' (set -g SSH_TTY /dev/pts/0; _context) = $USER'@'$hostname @test 'Root' (_tide_decolor (sudo fish --command="source $sourceFile;_tide_item_context")) = 'root@'$hostname \ No newline at end of file