tide icon indicating copy to clipboard operation
tide copied to clipboard

Add transient prompt feature

Open IlanCosman opened this issue 4 years ago β€’ 9 comments

Is your feature request related to a problem? Please describe

A multi-line prompt is nice to use, but takes up a ton of scroll-back history.

Describe the solution you'd like

The prompt should optionally change right before hitting enter to become one line. Powerlevel10k has this feature and it has been requested in the past.

IlanCosman avatar Feb 02 '21 15:02 IlanCosman

This would be sick!

pusewicz avatar Feb 15 '21 17:02 pusewicz

Yes, please!

matallui avatar Feb 17 '21 17:02 matallui

for visibility, see https://github.com/fish-shell/fish-shell/issues/7602 (and the linked PR which addresses it)

branchvincent avatar Jul 20 '21 00:07 branchvincent

fish-shell/fish-shell#7602 is closed now. It references a PR that was merged and a couple other closed issues.

Does that mean this is waiting on a new release of fish-shell to be available? Does Tide need https://github.com/fish-shell/fish-shell/milestone/30 to be completed for the transient prompt to work in Tide?

ahillio avatar Aug 29 '21 18:08 ahillio

@ahillio Yes, Fish 3.4 would have to come out before Tide adds transient prompt. There is also a bug with repaints that would need to get fixed beforehand. Rest assured that Tide will add this feature when it is ready to be added πŸ˜„

IlanCosman avatar Nov 09 '21 16:11 IlanCosman

Oh wow just found this issue. Yes please! πŸ˜€ can't wait for fish 3.4 to be release ^^

Crocmagnon avatar Dec 10 '21 17:12 Crocmagnon

@IlanCosman Sooooo… Can this be implemented? πŸ‘―

pusewicz avatar Apr 01 '22 11:04 pusewicz

The bug mentioned by Ilan is still not fixed: https://github.com/fish-shell/fish-shell/issues/8418

I guess we need to wait for this one too :)

Crocmagnon avatar Apr 01 '22 12:04 Crocmagnon

Interesting... that issue https://github.com/fish-shell/fish-shell/issues/8418 is referenced by another https://github.com/JanDeDobbeleer/oh-my-posh/issues/2467 and apparently oh-my-posh makes it possible to do a transient prompt in fish. I wonder if their method is something that could be used here?

ahillio avatar Jul 13 '22 21:07 ahillio

Probably worth a shot.

asportnoy avatar Oct 09 '22 23:10 asportnoy

πŸ‘ for this feature πŸ˜„

SolidRhino avatar Nov 17 '22 19:11 SolidRhino

Still waiting for this one πŸ™

k-kedzierski avatar Jan 16 '23 20:01 k-kedzierski

I wrote this, It works fine for me:

# rename fish_prompt to __transient_fish_prompt
if not type --query __transient_fish_prompt
    and type --query fish_prompt
    functions --copy fish_prompt __transient_fish_prompt
    functions --erase fish_prompt
end

# rename fish_right_prompt to __transient_fish_right_prompt
if not type --query __transient_fish_right_prompt
    and type --query fish_right_prompt
    functions --copy fish_right_prompt __transient_fish_right_prompt
    functions --erase fish_right_prompt
end

function ___default_transient_prompt
    printf (set_color 5FD700)"❯ "(set_color normal)
end

function ___reset_pipestatus
    return $argv[1]
end

set --global TRANSIENT normal
set --global TRANSIENT_RIGHT normal

function fish_prompt
    _transient_pipestatus=$pipestatus _transient_status=$status if test "$TRANSIENT" = normal
        if type --query __transient_fish_prompt
            ___reset_pipestatus $_transient_pipestatus
            __transient_fish_prompt
        else
            ___default_transient_prompt
        end
    else
        printf \e\[0J # clear from cursor to end of screen
        if type --query transient_prompt_func
            transient_prompt_func
        else
            ___default_transient_prompt
        end

        set --global TRANSIENT normal
        set --global TRANSIENT_RIGHT transient
        commandline --function repaint
    end
end

function fish_right_prompt
    if test "$TRANSIENT_RIGHT" = transient
        set --global TRANSIENT_RIGHT normal
        commandline --function repaint
        return 0
    end

    _transient_pipestatus=$pipestatus _transient_status=$status if test "$TRANSIENT_RIGHT" = normal
        if type --query __transient_fish_right_prompt
            ___reset_pipestatus $_transient_pipestatus
            __transient_fish_right_prompt
        end
    end
end

# transience related functions
function reset-transient --on-event fish_postexec
    set --global TRANSIENT normal
    set --global TRANSIENT_RIGHT normal
end

function transient_execute
    set --global TRANSIENT transient
    set --global TRANSIENT_RIGHT transient
    if test "$(commandline -b)" != "" # fix empty enter
        and commandline --paging-full-mode # Evaluates to true if the commandline is showing pager contents, such as tab completions and all lines are shown (no β€œ<n> more rows” message).
        set --global TRANSIENT normal
    end
    commandline --function repaint execute
end

function ctrl_c_transient_execute
    set --global TRANSIENT transient
    if test "$(commandline -b)" = ""
        commandline --function repaint execute
        return 0
    end

    commandline --function repaint cancel-commandline kill-inner-line repaint-mode
end

bind -M insert \r transient_execute
bind -M insert \cc ctrl_c_transient_execute

zzhaolei avatar Jan 31 '23 07:01 zzhaolei

I wrote this

I installed the plugin and it works like a charm so far. :)

real-or-random avatar Jan 31 '23 08:01 real-or-random

I wrote this, It works fine for me:

if not type --query __fish_prompt
    functions --copy fish_prompt __fish_prompt
    functions --erase fish_prompt
end

function fish_prompt
    set --function default_prompt (set_color 5FD700)"❯ "(set_color normal)

    if test "$TRANSIENT" = 1
        or test "$TRANSIENT" = 2
        printf \e\[0J # clear from cursor to end of screen
        if type --query transient_prompt_func
            transient_prompt_func
        else
            printf $default_prompt
        end

        if test "$TRANSIENT" = 2
            set --global TRANSIENT 0
            commandline --function repaint
        end
    else
        if type --query __fish_prompt
            __fish_prompt
        else
            printf $default_prompt
        end
    end
end

# transience related functions
function reset-transient --on-event fish_postexec
    set --global TRANSIENT 0
end

function transient_execute
    if commandline --is-valid
        set --global TRANSIENT 1
        commandline --function repaint
    else if test "$(commandline -b)" = "" # fix empty enter
        set --global TRANSIENT 2
        commandline --function repaint
    else
        set --global TRANSIENT 0
    end
    commandline --function execute
end

bind -M insert \r transient_execute # when enable vi keybinding use this bind
# bind \r transient_execute # disable vi keybinding use this bind

This is not working for me. I'm using macOS. I see no difference.

SolidRhino avatar Jan 31 '23 11:01 SolidRhino

I'm using MacOS. @SolidRhino the last line is important - if you are not using vi keybinding - you should swap comments and it would work as a Charm.

The other problem is about right_prompt - @zzhaolei do you know if it could be possible to remove right prompt as well?

m-messiah avatar Jan 31 '23 11:01 m-messiah

@SolidRhino try this

zzhaolei avatar Jan 31 '23 12:01 zzhaolei

@zzhaolei

The last lines of the code are now:

#bind -M insert \r transient_execute
#bind -M insert \cc ctrl_c_transient_execute
bind \r transient_execute
bind \cc ctrl_c_transient_execute

But still have this prompt: afbeelding

SolidRhino avatar Jan 31 '23 14:01 SolidRhino

@SolidRhino @m-messiah

Try this

This commit makes fish_right_prompt transient.

image

zzhaolei avatar Feb 01 '23 03:02 zzhaolei

This is literary the oldest open issue and so far lots of problems had to be solved to reach this state. now that https://github.com/IlanCosman/tide/issues/85#issuecomment-1409875980 works too, can we expect a PR :)

Naadiyaar avatar Jul 30 '23 07:07 Naadiyaar

This is literary the oldest open issue and so far lots of problems had to be solved to reach this state. now that #85 (comment) works too, can we expect a PR :)

@Naadiyaar Sure, cooked something up. Try the transient-prompt branch and set -U tide_transient_enabled true.

IlanCosman avatar Jul 31 '23 03:07 IlanCosman

This is literary the oldest open issue and so far lots of problems had to be solved to reach this state. now that #85 (comment) works too, can we expect a PR :)

@Naadiyaar Sure, cooked something up. Try the transient-prompt branch and set -U tide_transient_enabled true.

Awesome, tried it right now and it works flawlessly with icons, frames, right prompt... enabled, good work.

Naadiyaar avatar Jul 31 '23 04:07 Naadiyaar

it works flawlessly with icons, frames, right prompt...

Same here, thanks for working on this! I'll report any issues here should I run into them.

jacobwhall avatar Jul 31 '23 08:07 jacobwhall

v6 released

IlanCosman avatar Oct 04 '23 04:10 IlanCosman