-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
--- | ||
layout: post | ||
title: "Ctrl+Sで画面停止する機能を無効化する" | ||
description: "" | ||
category: | ||
tags: [Unix] | ||
--- | ||
|
||
## あらすじ | ||
|
||
たまにターミナルの応答がまったく効かなくなることがあって困ってた。 | ||
|
||
どうやらそういう命令があった模様。(`Ctrl+S`)多分、Windowsの保存感覚で押下していた。 | ||
知らなかった…。 | ||
|
||
- [「Ctrl」+「s」による「画面への出力の停止」を無効化 - PukiWiki](http://www.lovebug.jp/index.php?%E3%80%8CCtrl%E3%80%8D%2B%E3%80%8Cs%E3%80%8D%E3%81%AB%E3%82%88%E3%82%8B%E3%80%8C%E7%94%BB%E9%9D%A2%E3%81%B8%E3%81%AE%E5%87%BA%E5%8A%9B%E3%81%AE%E5%81%9C%E6%AD%A2%E3%80%8D%E3%82%92%E7%84%A1%E5%8A%B9%E5%8C%96) | ||
|
||
## 環境 | ||
|
||
```bash | ||
$ lsb_release -a | ||
No LSB modules are available. | ||
Distributor ID: Ubuntu | ||
Description: Ubuntu 18.04.2 LTS | ||
Release: 18.04 | ||
Codename: bionic | ||
``` | ||
|
||
## 解決方法 | ||
|
||
`Ctrl+S`を無効化する。 | ||
|
||
ただし、Bashの場合これを無効化するとインクリメンタルサーチ(`i-search`)が活きるようになるのでビックリしないように。 | ||
|
||
- [stty(1) manページ](https://nxmnpg.lemoda.net/ja/1/stty) | ||
|
||
### 確認 | ||
|
||
まずは`Ctrl+`で発動するコマンドを確認してみる。 | ||
|
||
```bash | ||
$ stty -a | ||
(略) | ||
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; | ||
(略) | ||
``` | ||
|
||
- intr = ^C; 割り込み(interrupt) | ||
- quit = ^\; 終了(quit) | ||
- erase = ^?; 最後にタイプした文字消去 | ||
- kill = ^U; 現在の行消去(パスフレーズ入力時も消去される) | ||
- eof = ^D ファイル終了(end of file) | ||
- **start = ^Q;** | ||
- **stop = ^S;** | ||
- susp = ^Z; 停止(suspend) | ||
- rprnt = ^R; | ||
- werase = ^W; | ||
- lnext = ^V; | ||
- discard = ^O; | ||
|
||
などなど…。 | ||
|
||
### 無効化 | ||
|
||
startもstopも暴発した時以外使った事ないのでこの先もいらないでしょう。 | ||
|
||
```bash | ||
$ stty start undef | ||
$ stty stop undef | ||
``` | ||
|
||
または | ||
|
||
```bash | ||
$ stty -ixon | ||
``` | ||
|
||
の方がいいかも。 | ||
|
||
> ixon (-ixon) | ||
> | ||
> 制御コードの START/STOP を使った出力フロー制御を有効 (無効) にします。 | ||
## 注意事項 | ||
|
||
これを`.bashrc`に直接書くと非対話時(scp等)でコケる。(`.bashrc`で標準出力など**してはいけない**) | ||
|
||
```bash | ||
$ scp -P 3333 foo.py ubuntu@localhost: | ||
ubuntu@localhost's password: | ||
stty: standard input: Inappropriate ioctl for device | ||
``` | ||
そのため、対話モードの時のみ実行されるようにする必要がある。 | ||
変数`$-`に現在のオプションが格納されている。対話モードの場合は`$-`に`i`が付加されるので、これを条件にしてやればよい。 | ||
```bash | ||
$ echo $- | ||
himBHs | ||
``` | ||
```bash | ||
[[ $- == *i* ]] && stty -ixon | ||
``` | ||
[How to check if a shell is login/interactive/batch - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/26676/how-to-check-if-a-shell-is-login-interactive-batch)にあるように、対話モードか否かの判断は色々な方法でできる。 | ||
## 参考 | ||
- [Man page of BASH](https://linuxjm.osdn.jp/html/GNU_bash/man1/bash.1.html) | ||
- [linux - Getting stty: standard input: Inappropriate ioctl for device when using scp through an ssh tunnel - Stack Overflow](https://stackoverflow.com/questions/24623021/getting-stty-standard-input-inappropriate-ioctl-for-device-when-using-scp-thro) | ||