Skip to content

Commit

Permalink
初版発行
Browse files Browse the repository at this point in the history
  • Loading branch information
gosyujin committed Jun 20, 2019
1 parent 337ba2e commit e0dbf5a
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions layouts/partials/gitinfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
最終更新:
{{ if .Params.Draft }}
{{ .Date.Format "2006/01/02" }}
ドラフト版
{{ else }}
{{ .GitInfo.AuthorDate.Format "2006/01/02" }}
<a href="{{ .Site.Params.GithubCommitURL }}{{ .GitInfo.Hash }}">{{ .GitInfo.Subject }}</a>
Expand Down
116 changes: 116 additions & 0 deletions md/posts/2019-06-20-stty-ixon.md
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)

0 comments on commit e0dbf5a

Please sign in to comment.