プレイヤーズ・ハイ

 雑多な日記

HHKB BT を Karabiner でいい感じにセットアップする

HHKB BT が接続されたときにだけ起動される Private.xml を作成し上書きする.

Vendor ID と Product ID の調べ方

System Information を起動

Bluetooth のところに出ている.

  • Vendor ID: 0x04FE
  • Product ID: 0x0202

Private.xml

Karabiner の Misc & Uninstall から Private.xml を開き以下をコピペ.

HHKB BT のキーの場所 元々 変更後
一番右上 `~ (バッククォート・チルダ) delete
一番右上の左 \| (バックスラッシュ・パイプ) Esc
一番右上の下 delete \| (バックスラッシュ・パイプ)
Esc Esc `~ (バッククォート・チルダ)

Mac の US キーボードっぽく

このままだと Esc が使えないので,control + [ で Esc の代替とします.

【追記】

一番右上の左,バックスラッシュ・パイプを delete ではなく,Esc としました.

<?xml version="1.0"?>
<root>
  <devicevendordef>
    <vendorname>PFU</vendorname>
    <vendorid>0x04FE</vendorid>
  </devicevendordef>

  <deviceproductdef>
    <productname>HHKB_BT</productname>
    <productid>0x0202</productid>
  </deviceproductdef>

  <item>
    <name>Backslash(\) to Escape in HHKB BT</name>
    <identifier>private.deviceproductdef.bs_esc</identifier>
    <device_only>DeviceVendor::PFU, DeviceProduct::HHKB_BT</device_only>
    <autogen>__KeyToKey__ KeyCode::BACKSLASH, KeyCode::ESCAPE</autogen>
  </item>

  <item>
    <name>Delete to Backslash(\) in HHKB BT</name>
    <identifier>private.deviceproductdef.dlt_bs</identifier>
    <device_only>DeviceVendor::PFU, DeviceProduct::HHKB_BT</device_only>
    <autogen>__KeyToKey__ KeyCode::DELETE, KeyCode::BACKSLASH</autogen>
  </item>

  <item>
    <name>Backquote(`) to Delete in HHKB BT</name>
    <identifier>private.deviceproductdef.esc_bs</identifier>
    <device_only>DeviceVendor::PFU, DeviceProduct::HHKB_BT</device_only>
    <autogen>__KeyToKey__ KeyCode::BACKQUOTE, KeyCode::DELETE</autogen>
  </item>

  <item>
    <name>Escape to Backquote(`) in HHKB BT</name>
    <identifier>private.deviceproductdef.esc_bq</identifier>
    <device_only>DeviceVendor::PFU, DeviceProduct::HHKB_BT</device_only>
    <autogen>__KeyToKey__ KeyCode::ESCAPE, KeyCode::BACKQUOTE</autogen>
  </item>

  <item>
     <name>Ctrl-L+[ also works as Escape in HHKB BT</name>
     <identifier>private.ctrl_[_to_escape</identifier>
     <device_only>DeviceVendor::PFU, DeviceProduct::HHKB_BT</device_only>
     <autogen>__KeyToKey__ KeyCode::BRACKET_LEFT, ModifierFlag::CONTROL_L, KeyCode::ESCAPE</autogen>
   </item>

</root>

【追記】

やっぱり Esc の位置が代わるのはかなりストレスだったので,以下のように変更しました. control + [ のメタキーは残しています.

HHKB BT のキーの場所 元々 変更後
一番右上 `~ (バッククォート・チルダ) delete
一番右上の左 \| (バックスラッシュ・パイプ) `~ (バッククォート・チルダ)
一番右上の下 delete \| (バックスラッシュ・パイプ)
Esc Esc Esc(そのまま)
<?xml version="1.0"?>
<root>
  <devicevendordef>
    <vendorname>PFU</vendorname>
    <vendorid>0x04FE</vendorid>
  </devicevendordef>

  <deviceproductdef>
    <productname>HHKB_BT</productname>
    <productid>0x0202</productid>
  </deviceproductdef>

  <item>
    <name>Backslash(\) to Backquote(`) in HHKB BT</name>
    <identifier>private.deviceproductdef.bs_bq</identifier>
    <device_only>DeviceVendor::PFU, DeviceProduct::HHKB_BT</device_only>
    <autogen>__KeyToKey__ KeyCode::BACKSLASH, KeyCode::BACKQUOTE</autogen>
  </item>

  <item>
    <name>Delete to Backslash(\) in HHKB BT</name>
    <identifier>private.deviceproductdef.dlt_bs</identifier>
    <device_only>DeviceVendor::PFU, DeviceProduct::HHKB_BT</device_only>
    <autogen>__KeyToKey__ KeyCode::DELETE, KeyCode::BACKSLASH</autogen>
  </item>

  <item>
    <name>Backquote(`) to Delete in HHKB BT</name>
    <identifier>private.deviceproductdef.esc_bs</identifier>
    <device_only>DeviceVendor::PFU, DeviceProduct::HHKB_BT</device_only>
    <autogen>__KeyToKey__ KeyCode::BACKQUOTE, KeyCode::DELETE</autogen>
  </item>

  <item>
     <name>Ctrl-L+[ also works as Escape in HHKB BT</name>
     <identifier>private.ctrl_[_to_escape</identifier>
     <device_only>DeviceVendor::PFU, DeviceProduct::HHKB_BT</device_only>
     <autogen>__KeyToKey__ KeyCode::BRACKET_LEFT, ModifierFlag::CONTROL_L, KeyCode::ESCAPE</autogen>
   </item>

</root>

Neovim のインストール on RHEL 7 / CentOS 7 あと dein.vim とか

Neovim のインストール

Neovim 用の yum リポジトリー登録

$ sudo vi /etc/yum.repos.d/neovim.repo

[dperson-neovim]
name=Copr repo for neovim owned by dperson
baseurl=https://copr-be.cloud.fedoraproject.org/results/dperson/neovim/epel-7-$basearch/
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://copr-be.cloud.fedoraproject.org/results/dperson/neovim/pubkey.gpg
enabled=1
enabled_metadata=1

$ sudo yum install neovim

$ vi ~/.bashrc

alias vi='/bin/nvim'

dein.vim のインストール

$ mkdir -p ~/.cache/dein

$ cd ~/.cache/dein

$ curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh

$ sh ./installer.sh ~/.cache/dein

以下を ~/.vimrc or init.vim に貼り付け

"dein Scripts-----------------------------
if &compatible
  set nocompatible               " Be iMproved
endif

" Required:
set runtimepath+=/home/ユーザー名/.cache/dein/repos/github.com/Shougo/dein.vim

" Required:
call dein#begin('/home/ユーザー名/.cache/dein')

" Let dein manage dein
" Required:
call dein#add('Shougo/dein.vim')

" Add or remove your plugins here:
call dein#add('Shougo/neosnippet.vim')
call dein#add('Shougo/neosnippet-snippets')

" You can specify revision/branch/tag.
call dein#add('Shougo/vimshell', { 'rev': '3787e5' })

" Required:
call dein#end()

" Required:
filetype plugin indent on

" If you want to install not installed plugins on startup.
"if dein#check_install()
"  call dein#install()
"endif

"End dein Scripts-------------------------

初回起動

$ vi -u ~/.vimrc or ~/.init.vim

:call dein#install()

.vimrc カスタマイズ

以下のように .vimrc をカスタマイズ

$ vi ~/.vimrc

"dein Scripts-----------------------------
if &compatible
  set nocompatible               " Be iMproved
endif

" Required:
set runtimepath+=/home/ユーザー名/.cache/dein/repos/github.com/Shougo/dein.vim

" Required:
call dein#begin('/home/ユーザー名/.cache/dein')

" Let dein manage dein
" Required:
call dein#add('Shougo/dein.vim')

" Add or remove your plugins here:
call dein#add('Shougo/neosnippet.vim')
call dein#add('Shougo/neosnippet-snippets')
call dein#add('vim-scripts/bash-support.vim')
call dein#add('tomasr/molokai')
call dein#add('cseelus/vim-colors-lucid')

" You can specify revision/branch/tag.
call dein#add('Shougo/vimshell', { 'rev': '3787e5' })

" Required:
call dein#end()

" Required:
filetype plugin indent on

" If you want to install not installed plugins on startup.
if dein#check_install()
  call dein#install()
endif

"End dein Scripts-------------------------

" color scheme
colorscheme molokai

" syntax
syntax enable

" ---------- 基本設定 ----------
syntax enable                    " 構文ハイライト有効化
set number                       " 行番号表示
set showmatch                    " 対応括弧強調表示
set backspace=indent,eol,start   " backspaceを有効化

" ---------- タブ設定 ----------
set expandtab                    " ソフトタブ有効化
set tabstop=4                    " タブ文字幅はスペース 4 つ
set softtabstop=4                " ソフトタブ幅はスペース 4 つ
" set shiftwidth=4               " 自動で挿入されるインデントのスペース幅

" ---------- インデント ----------
" set autoindent                 " 改行時自動インデント
set noautoindent

" display settings
set number
set ruler
set list

" encoding
set encoding=utf8
set fileencoding=utf8

" cursor
set cursorline
set cursorcolumn

設定ファイルのコンバート

$ mkdir ~/.config

$ mkdir ~/.vim

$ ln -s ~/.vim ~/.config/nvim

$ ln -s ~/.vimrc ~/.config/nvim/init.vim

以上です!! 快適な Vim ライフを!!

追記 自分用メモ

原因が分からないのだが,カラースキーマ molokai が使えなくなることがあった.

" colorscheme molokai
colorscheme elflord

などとし,一旦別のカラースキーマを設定し,再度 molokai に戻すと直った.

エラーメッセージが埋もれてしまったので正確な原因は不明だが dein#recache_runtimepath() を実行すればよかったのかもしれない.

RHEL (CentOS) 7 における locale 設定

どうせメモるならブログ書こうかと.

ssh ログインすると

-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

locale コマンド叩くと

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

色々調べて,/etc/sysconfig/i18n に以下を記述し再起動したけど直らない.

LANG=ja_JP.UTF-8
LC_CTYPE=ja_JP.UTF-8

結論 RHEL (CentOS) 7 系では,/etc/locale.conf に設定するのでした. (上記をそのまま書いて # source /etc/locale.conf で O.K.)

あと localectl コマンドっていうのが追加されたようです.ctl 好きやなー.

$ localectl status で現状確認

以上です!!

Chef 小ネタ その一

Chef Server の構築と運用についてブログを書こうと思っているものの、中々まとまって時間が取れないため、小ネタを 2 つほど紹介します。

knife-opc について

knife の設定を正しく終えている Chef Workstation 環境で knife opc コマンドが使えずに困っていた。 具体的には以下のとおり。

$ knife opc user list
ERROR: You authenticated successfully to https://CHEF_SERVER_NAME/organizations/CHEF_ORG_NAME as CHEF_ADMIN_NAME but you are not authorized for this action
Response:  missing read permission

knife.rb に chef_server_url も chef_server_root も正しく指定しているのに、だ。

以下を読むと分かるのだが、

chef/knife-opc https://github.com/chef/knife-opc

knife opc コマンド実行時は、pivotal という Chef Client 名で認証するようだ。

よって sudo chef gem install knife-opc しておいて、以下のコマンドで目的を達成できた。

$ sudo knife opc user list --key /etc/opscode/pivotal.pem --user pivotal

だが、上記のドキュメントにも書いてあるのだが、chef-server-ctl コマンドが knife opc コマンドの管理者としてのアクションのラッパーになっており、こちらを使用するのが推奨されている。 上記コマンドと同じことをしたいなら、以下のようにする。

$ sudo chef-server-ctl user-list

レシピにおける not_if "grep ..." の書き方

シェルでは以下のように grep できるとする。

$ grep 'export PATH="/opt/chefdk/embedded/bin:$PATH"' ~/.bash_profile
export PATH="/opt/chefdk/embedded/bin:$PATH"

ところがこれを bash resource のガード条件として以下のように not_if で書くと syntax error になる(syntax error, unexpected tLABEL)。

not_if "grep 'export PATH="/opt/chefdk/embedded/bin:$PATH"' ~/.bash_profile

解消法は、単純に、ダブルクォーテーションをエスケープするだけ。

not_if "grep 'export PATH=\"/opt/chefdk/embedded/bin:$PATH\"' ~/.bash_profile

Chef活用ガイド コードではじめる構成管理

Chef活用ガイド コードではじめる構成管理

  • 作者: 澤登亨彦,樋口大輔,クリエーションライン株式会社
  • 出版社/メーカー: KADOKAWA/アスキー・メディアワークス
  • 発売日: 2014/04/25
  • メディア: 大型本
  • この商品を含むブログ (1件) を見る

Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

入門Chef Solo - Infrastructure as Code

入門Chef Solo - Infrastructure as Code