joseluisq / gitnow

Speed up your Git workflow. :tropical_fish:

Home Page:https://github.com/joseluisq/gitnow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"state" keybindings do not show the output of the command

shadyar-bakr opened this issue · comments

Keybindings like Alt+S do not show the output like state just shows a flash on the terminal,

Demonistration:
https://user-images.githubusercontent.com/47904282/125957057-fb196531-e2cc-4706-8807-d955fe88a001.mp4

I can not reproduce it using Fish 3.3.1 on my Linux computer. Maybe you can remove commandline -f repaint and try again.

function state -d "Gitnow: Show the working tree status in compact way"
if not __gitnow_is_git_repository
__gitnow_msg_not_valid_repository "state"
return
end
command git status -sb
commandline -f repaint
end

Only two keybindings do not work Alt + S(state) and Alt + C(commit-all), also Alt + E(stage) and Ctrl + E(unstage) are working but with no output.

Deleting line 29 does not fix the problem for me. Maybe because fish has default Alt + S keybinding for adding sudo ?

Is there any way to debug this, like a log file ?

Can you just change the key bindings to something else and try again?

I changed it to Ctrl + K but no luck.

Very stupid question but are you using lower case or upper case keybindings?
Because the default keybindings in .gitnow file are in lower case. Despite the comments which says the opposite.

I assume that you are following the keybindings configuration section.

Sorry for the confusion. This is my .gitnow

[ keybindings ]

# Alt + S -> Ctrl + K
state = \ck

# Alt + E
stage = \ee

# Ctrl + E
unstage = \ce

# Alt + M
show = \em

# Alt + C
commit-all = \ec

# Alt + D
pull = \ed

# Alt + P
push = \ep

# Alt + U
upstream = \eu

# Alt + L
logs = \el

# Alt + F
feature = \ef

# Alt + H
hotfix = \eh

Maybe because fish has default Alt + S keybinding for adding sudo ?

Maybe but your keybindings should take precedence.

Is there any way to debug this, like a log file ?

No really, but you can try to debug whatever not working keybinding adding some test output in order to see if the keybinding get triggered.

Actually I have no idea why is not working for you so I'm just guessing. Also you are saying that other keybindings are working which makes this a bit weird.
Maybe the commands names are conflicting with others called the same on your system?

If you can provide a way to reproduce this It would be great.

I tried to change the output of the command but still can not see any output of the command (just a flash as in the video provided in the first comment).

I have also deleted fisher + gitnow and cleaned the config folder and removed any custom function and abbr, but still can not solve it.

Also you are saying that other keybindings are working which makes this a bit weird.

The weirdest thing is I can type the commands(state, commit, commit-all) and they all work fine.

If you can provide a way to reproduce this It would be great.

I do not know how to do that, any suggestion?

I can upload .config/fish if that is needed or any file/folder.

I think looks like is something with the Fish keybindings but I'm not sure.

Can you try to create a simple .fish file in your Fish conf.d/ directory and program a keybinding on it. One similar to https://github.com/joseluisq/gitnow/blob/master/functions/__gitnow_config_file.fish#L130 and another with just a plain keybinding (E.g bind \cg 'state; commandline -f repaint').
Finally test both and share your results.

The idea is to discard if this is a Fish keybindings issue what I'm not really sure.

Sorry for the late response.

I have found out that the git status flag -sb creates the issue, I have removed the flag from here and the keybinding is working now

Another odd thing, I don't know if it's helpful or not, but if I remove commandline -f repaint and go to the web based fish config, I can still see the commandline -f repaint line. I don't know if that is normal behavior or not.

I have restored the original keybindings
image

If I create a binding like bind \cg 'git status -sb;' I can run this binding but after running it I have to press return to exit.

Great,

If I create a binding like bind \cg 'git status -sb;' I can run this binding but after running it I have to press return to exit.

Yes, it's because it's necessary to repaint the screen since state command produces output otherwise you will need to press the return key.

If a script produces output, it should finish by calling commandline -f repaint to tell fish that a repaint is in order.
https://fishshell.com/docs/current/cmds/bind.html

However since this repaint is only needed during bind usage, for example (alt + s) then we can try the following.
First, can you please replace this line with this below and tell me how is goes?

set cmd (echo -n "bind \\$v_command_val \"echo; $v_command_key; commandline -f repaint;\"")

Second, can you replace these two lines with just the following:

git status -sb

This is because we don't need to repaint many times on the state command but only one repaint during bind.

Try that out and let me know how is goes.

I have found out that the git status flag -sb creates the issue, I have removed the flag from here and the keybinding is working now

Are you able to run for example a plain git status -sb on your terminal (no via Gitnow)? If so it's not a git problem maybe a Fish or Gitnow script problem. Otherwise we could go with just a git status for state.

After editing both files as you suggested, I still have the problem.

Are you able to run for example a plain git status -sb on your terminal (no via Gitnow)? If so it's not a git problem maybe a Fish or Gitnow script problem. Otherwise we could go with just a git status for state.

I can run git status -sb fine, so maybe it is a Fish problem then.

function state -d "Gitnow: Show the working tree status in compact way"
    if not __gitnow_is_git_repository
        __gitnow_msg_not_valid_repository "state"
        return
    end

    git status -sb
end
if not [ "$v_command_key" = "" ]; and not [ "$v_command_val" = "" ]
    set -l cmd

    switch $v_command_key
        case 'release' 'hotfix' 'feature' 'bugfix'
            # Skip out if there is no a valid clipboard program
            if not test -n $gitnow_xpaste; continue; end

            set cmd (echo -n "bind \\$v_command_val \"echo; if $v_command_key ($gitnow_xpaste); commandline -f repaint; else ; end\"")
        case '*'
            # Check command key against a list of valid commands
            set -l v_valid 0
            for v in $gitnow_commands
                if [ "$v" = "$v_command_key" ]
                    set v_valid 1
                    break
                end
            end

            # If command key is not valid then just skip out
            if test $v_valid -eq 0; continue; end

            set cmd (echo -n "bind \\$v_command_val \"echo; $v_command_key; commandline -f repaint;\"")
    end

    eval $cmd
end

I can run git status -sb fine, so maybe it is a Fish problem then.

Ok, you can run the plain command directly using the Fish session. Right ?
If so it can be something with the Fish scripts code. Maybe Gitnow needs to approach this in another way. But I don't know.

So the solution can be just to use git status and this one set cmd (echo -n "bind \\$v_command_val \"echo; $v_command_key; commandline -f repaint;\"") right ?

Ok, you can run the plain command directly using the Fish session. Right ?

Yes.

So the solution can be just to use git status and this one set cmd (echo -n "bind \\$v_command_val \"echo; $v_command_key; commandline -f repaint;\"") right ?

git status Work and the second command I assume is for not repeating commandline -f repaint in every function?

git status Work and the second command I assume is for not repeating commandline -f repaint in every function?

Yes, basically two things.
First one PR for changing the state command to use just git status along with the repaint only for bind (key bindings).

Second another PR to remove all repaints for every Gitnow command previous tests obviously.

Feel free to contribute if you want.

Great, I will try

Great, another quick question, what Git version are you using on your machine?

version 2.32.0

Ok, I labeled this as a kind of bug but feel free to improve this if you want.

I have changed the state to git status, and removed all commandline -f repaint.

Replaced set cmd (echo -n "bind \\$v_command_val \"echo; if $v_command_key; commandline -f repaint; else ; end\"") with set cmd (echo -n "bind \\$v_command_val \"echo; $v_command_key; commandline -f repaint;\"").

But now even the Alt + S > state > git status doesn't show the files like a normal git status

image

Is this related by any chance ? fish-shell/fish-shell#7546

Looks like is not related since it talks about $status.

But another question did you try to use gitnow in a fresh Fish session? I mean without custom prompts or other plugins installed than just Gitnow? Maybe some of your plugins or prompts could interfere with Gitnow keybindings?

I have no idea why that occurs so let's investigate until we find a workaround for it.

Maybe kind of related to fish-shell/fish-shell#5033 ? but I'm not sure.

Replaced set cmd (echo -n "bind \\$v_command_val \"echo; if $v_command_key; commandline -f repaint; else ; end\"") with set cmd (echo -n "bind \\$v_command_val \"echo; $v_command_key; commandline -f repaint;\"").

Try to replace it with the following instead and see if it works:

set cmd (echo -n "bind \\$v_command_val \"printf \"\n\"; $v_command_key; commandline -f kill-whole-line; commandline -f execute;\"")

But another question did you try to use gitnow in a fresh Fish session? I mean without custom prompts or other plugins installed than just Gitnow? Maybe some of your plugins or prompts could interfere with Gitnow keybindings?

Well as it turned out it is caused by another thing after using this trick and installing fisher and gitnow. Gitnow behaves as it should.

image

Now I will remove my configurations and see what causes this issue.

It is the prompt Starship prompt

Great, you got it!
So let me know when you are done. At least discarding if it was really a Gitnow issue or not and feel free to close the issue.

BTW I think there is no reason to change the behaviour of the state command to something.

But maybe this one can be a future improvement.

Second another PR to remove all repaints for every Gitnow command previous tests obviously.

Yes, the state command doesn't need any changes, I will remove all repaint and I submit a PR after testing it.
Thank you