LoginSignup
13
10

More than 1 year has passed since last update.

Rofiの設定

Last updated at Posted at 2018-04-02

はじめに

私はArch Linuxでi3wmを使っています。これまでランチャーはi3wmの標準のdmenuを使っていました。しかし、dmenuはカスタマイズ性とおしゃれさに欠けるのでRofiに移行しました。

Rofiの設定ファイル

#.config/rofi/config.rasi
configuration {
  modi: "window,drun,system:~/.config/rofi/rofi_system.sh";
  sidebar-mode:  true;
  hide-scrollbar: true;
  kb-cancel: "Escape,Control+bracketleft";
  kb-mode-previous: "Alt+u";
  kb-mode-next: "Alt+i";
}
@theme "/usr/share/rofi/themes/Arc-Dark.rasi"

modiに有効にするモードを設定します。独自のモードも作れます。
kb-(コマンド)にはキーバインドを設定します。rofi -show keysでキーバインドのの設定が見れるので、気に入らないキーバインドを変更します。
themeでテーマを設定する。rofi-theme-selectorでテーマのpreviewを見ながら設定を変更できます。

独自のモード

シェルスクリプトで記述します。表示したい項目を改行区切りで標準出力に出力します。選択すると選択した文字列を引数として再度シェルスクリプトを実行します。

#!/usr/bin/env bash

set -euCo pipefail

function main() {
  # 表示したい項目と実際に実行するコマンドを連想配列として定義する。
  local -Ar menu=(
    ['Lock']='dm-tool lock'
    ['Logout']='i3-msg exit'
    ['Poweroff']='systemctl poweroff'
    ['Reboot']='systemctl reboot'
  )

  local -r IFS=$'\n'
  # 引数があるなら$1に対応するコマンドを実行する。
  # 引数がないなら連想配列のkeyを表示する。
  [[ $# -ne 0 ]] && eval "${menu[$1]}" || echo "${!menu[*]}"
}

main $@

2018-04-02-132029_1366x768_scrot.png

コマンドを実行時に確認を取る

独自のモードでpoweroffを実行するのですが、誤って実行する可能性があります。なので、実行を行う時に確認をとるようにシェルスクリプトを変更します。選択すると(項目名 / yes, 項目名 / no)が表示され、yesを選択するとコマンドを実行する。noを選択すると元に戻る。

#!/usr/bin/env bash

set -euCo pipefail

declare -Ar menu=(
  ['Logout']='i3-msg exit'
  ['Poweroff']='systemctl poweroff'
  ['Reboot']='systemctl reboot'
)

function print_keys() {
  local -r IFS=$'\n'
  echo "${!menu[*]}"
}

function main() {
  local -r yes='yes' no='no'

  if [[ $# -eq 0 ]]; then
    print_keys
  elif [[ $# -eq 1 ]]; then
    echo $1 ${no}
    echo $1 ${yes}
  elif [[ $2 == ${yes} ]]; then
    eval "${menu[$1]}"
  elif [[ $2 == ${no} ]]; then
    print_keys
  fi
}

main $@

2018-04-02-132428_1366x768_scrot.png

13
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
10