Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding CTRL-Z #7152

Closed
kosayoda opened this issue Jun 24, 2020 · 12 comments
Closed

Binding CTRL-Z #7152

kosayoda opened this issue Jun 24, 2020 · 12 comments

Comments

@kosayoda
Copy link

Version & Other Details:

fish, version 3.1.2
Linux 5.7.2-arch1-1 x86_64 GNU/Linux
xterm-256-color

Issue:
Is there currently a way to bind CTRL-Z? #1879 led to stty stuff in three other eventually closed issues that I don't understand. Thanks in advance!

@zanchey
Copy link
Member

zanchey commented Jun 24, 2020

The short answer is no - Ctrl-Z is intercepted by the terminal (well, the line discipline) and never forwarded as a keystroke to fish.

You'll see this if you run fish_key_reader - pushing Ctrl-Z produces no response.

The longer answer is yes, if you alter the terminal's character for sending the suspend signal to something else:

> stty susp '^N'
> fish_key_reader
Press a key:
              hex:   1A  char: \cZ
bind \cZ 'do something'

(but now you can't use Ctrl-N for a keybinding)

@kosayoda
Copy link
Author

Thanks for the reply!

> stty susp '^N'

This does not seem to work on my side, any idea why?

$ stty -a
speed 38400 baud; rows 22; columns 104; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>;
start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff -iuclc -ixany -imaxbel
-iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho

Running stty susp '^N' does not reflect in stty -a.

@zanchey
Copy link
Member

zanchey commented Jun 24, 2020

Oh, sorry, that won't work in 3.1.2 because 29754f3 isn't in a released version yet. You'd have to do something like stty susp '^N'; fish to start a new shell with the new modes, which is awful I'm afraid. exec fish resets the modes :-(

@faho
Copy link
Member

faho commented Jun 24, 2020

Is there a particular reason why we leave this enabled inside fish, at all? AFAICT we ignore the signal anyway?

@faho faho closed this as completed in 3d2dc85 Jun 24, 2020
@faho
Copy link
Member

faho commented Jun 24, 2020

Yeah, we already ignore SIGTSTP unconditionally inside fish, so we can just disable the key mapping to free it up for our use.

@faho faho added enhancement and removed question labels Jun 24, 2020
@faho faho added this to the fish 3.2.0 milestone Jun 24, 2020
@krobelus
Copy link
Member

Sweet, thanks @faho!

Should we bind it to undo? (In addition to Ctrl+_?) That could be what users expect these days.
We don't want to bind Ctrl+Y to redo but I'd be fine with this inconsistency since redo is much less important.

@faho
Copy link
Member

faho commented Jun 25, 2020

Should we bind it to undo? (In addition to Ctrl+_?)

Sounds good.

@zanchey
Copy link
Member

zanchey commented Jun 25, 2020

Yeah, we already ignore SIGTSTP unconditionally inside fish, so we can just disable the key mapping to free it up for our use.

🤯

@kosayoda
Copy link
Author

o/ Thanks @faho!
To anyone coming here looking to bind CTRL-Z to put the last suspended job to the foreground, here's one way to do it:

 function fish_user_key_bindings
    bind \cz 'fg 2>/dev/null; commandline -f repaint'
 end
  • 2>/dev/null removes the Send job X, “PROGRAM” to foreground message, omit that if you wish to keep it.
  • commandline -f repaint tells fish to redraw the prompt to avoid weird cursor position issues.

@bryanenders
Copy link

@faho This was working, but it seems to have regressed.

@krobelus
Copy link
Member

krobelus commented Oct 14, 2020

@endersstocker works for me on latest master. It's probably best to ask on gitter or open a new issue if the problem persists.

@faho
Copy link
Member

faho commented Oct 14, 2020

Works for me, too.

Please make sure you're running a fish after 3d2dc85 (i.e. a build from git, not the latest release 3.1.2). If you can still confirm with that, ideally da0acb2 (current git master), your operating system would be great to know - 90d8df8 changed this to use _POSIX_VDISABLE (but special-cases the "not supported" value), so it's possible your OS is broken.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants