mr/mbaでLinux初期設定

はじめに

MacBook Air で Ubuntuベースのディストリビューションを使う場合を想定しています

# NOPASSWD
echo $USER ALL=NOPASSWD: ALL | sudo tee /etc/sudoers.d/$USER

# hardware keyboard [Apple Aluminium (JIS)]
# MacBook AirでUbuntuキーボードレイアウトを設定する - 考えるエンジニア https://takacity.blog.fc2.com/blog-entry-252.html
sudo dpkg-reconfigure keyboard-configuration

# toggle fn key (永続化)
sudo tee /etc/modprobe.d/hid_apple.conf <<'...'
options hid_apple fnmode=2
...
sudo update-initramfs -u -k all

# fn key behaviour (テンポラリ)
#  0 : disabled (fn + F8 = only F8 = F8)
#  1 : fn + F8 = F8,      only F8 = special
#  2 : fn + F8 = special, only F8 = F8
echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode

# disable auto update
sudo dpkg-reconfigure -p low unattended-upgrades

# change directory name in English
LANG=C xdg-user-dirs-gtk-update

# Disables window maximization when the application starts
gsettings set org.gnome.mutter auto-maximize false

# Disable window maximization when moving the window to the top of the screen
gsettings set org.gnome.mutter edge-tiling false

ブート時のエラーを無くす

boot - Ubuntu 20.04 Failed to Set MokListRT: Invallid Parameter - Ask Ubuntu

sudo sh -x <<'...'
cd /boot/efi/EFI/ubuntu
cp grubx64.efi shimx64.efi
reboot
...

タッチパッド操作の変更

事前にパッケージ類のインストールを済ませておくこと

3本指スワイプの左右を入れ替えるconfigを作成する例

# libinput-gestures
mkdir ~/.config || true
tee ~/.config/libinput-gestures.conf <<'...'
gesture swipe left  3 xdotool key alt+Left
gesture swipe right 3 xdotool key alt+Right
...
libinput-gestures-setup restart

sh/ネタ/コマンド出力にタイムスタンプ

はじめに

coreutils の ts コマンドが使えないときに、それっぽい出力を得る方法です

タイムスタンプを付与しつつバッファリングしないようにすると見た目が良いので awk を使います

例1:エイリアス

コマンド出力結果をパイプで繋ぎます(coreutils の ts コマンドと似たような使い勝手です)

# エイリアス登録(ダブルクオーテーションで括る例)
$ alias ts="awk '{print strftime(\"[%F %T] \") \$0; fflush() }'"

# 確認(シングルクォーテーションで登録するならこっち)
$ alias ts
alias ts='awk '\''{print strftime("[%F %T] ") $0; fflush() }'\'''

出力例

# ls にタイムスタンプ
$ ls | ts
[2021-03-02 07:56:17] 1000202334
[2021-03-02 07:56:17] Desktop
[2021-03-02 07:56:17] Downloads

# ping にタイムスタンプ
$ ping -c1 192.168.10.1 | ts
[2021-03-02 07:56:31] PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
[2021-03-02 07:56:31] 64 bytes from 192.168.10.1: icmp_seq=1 ttl=63 time=2.96 ms
[2021-03-02 07:56:31]
[2021-03-02 07:56:31] --- 192.168.10.1 ping statistics ---
[2021-03-02 07:56:31] 1 packets transmitted, 1 received, 0% packet loss, time 0ms
[2021-03-02 07:56:31] rtt min/avg/max/mdev = 2.960/2.960/2.960/0.000 ms

# sudo も大丈夫
#   最初の3行は標準エラー出力なのでタイムスタンプは付きません
$ sudo apt update | ts

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

[2021-03-02 07:56:43] Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
[2021-03-02 07:56:43] Hit:2 http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04  InRelease
[2021-03-02 07:56:43] Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease
[2021-03-02 07:56:44] Hit:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease
[2021-03-02 07:56:44] Hit:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease
[2021-03-02 07:56:45] Reading package lists...
[2021-03-02 07:56:45] Building dependency tree...
[2021-03-02 07:56:45] Reading state information...
[2021-03-02 07:56:45] 3 packages can be upgraded. Run 'apt list --upgradable' to see them.

標準エラーにタイムスタンプを付けるのも簡単です

# 標準エラーをリダイレクトしてタイムスタンプを付与
$ sudo apt update 2>&1 | ts
[2021-03-02 08:06:52]
[2021-03-02 08:06:52] WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
[2021-03-02 08:06:52]
[2021-03-02 08:06:53] Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
[2021-03-02 08:06:53] Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
(略)

例2:シェル関数

time コマンドのように、コマンドを後置します

ts(){
  eval "$@" | awk '{print strftime("[%F %T] ") $0; fflush() }'
}

出力例

# 確認
$ type ts
ts is a function
ts ()
{
    eval "$@" | awk '{print strftime("[%F %T] ") $0; fflush() }'
}

# ls にタイムスタンプ
$ ts ls
[2021-03-02 07:58:42] 1000202334
[2021-03-02 07:58:42] Desktop
[2021-03-02 07:58:42] Downloads

# ping にタイムスタンプ
$ ts ping -c1 192.168.10.1
[2021-03-02 07:58:50] PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
[2021-03-02 07:58:50] 64 bytes from 192.168.10.1: icmp_seq=1 ttl=63 time=3.90 ms
[2021-03-02 07:58:50]
[2021-03-02 07:58:50] --- 192.168.10.1 ping statistics ---
[2021-03-02 07:58:50] 1 packets transmitted, 1 received, 0% packet loss, time 0ms
[2021-03-02 07:58:50] rtt min/avg/max/mdev = 3.896/3.896/3.896/0.000 ms

# sudo の例
$ ts sudo apt update

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

[2021-03-02 07:58:55] Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
[2021-03-02 07:58:55] Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
[2021-03-02 07:58:55] Hit:3 http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04  InRelease
(略)

参考


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2021-03-02 (火) 15:43:15