在Ubuntu 20.04上安装和设置i3 Windows Manager

欢迎来到我们的教程,了解如何在Ubuntu 20.04上安装i3 Windows Manager。 i3是一个 平铺窗口管理器 对于X11。 “一个 平铺窗口管理器 是一个窗口管理器,将屏幕组织成相互不重叠的帧,与更流行的基于坐标的重叠对象(窗口)堆叠尝试完全模拟桌面隐喻的方法相反。 ”

在Ubuntu 20.04上安装和设置i3 Windows Manager

运行系统更新

首先,运行系统软件包更新。

apt update

在Ubuntu 20.04上安装i3

i3 Windows Manager可以通过安装 i3 该软件包可在默认的Ubuntu 20.04存储库上使用。

apt show i3
Package: i3
Version: 4.17.1-1
Priority: optional
Section: universe/x11
Source: i3-wm
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Michael Stapelberg <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 20.5 kB
Depends: i3-wm (= 4.17.1-1)
Recommends: i3lock (>= 2.2), suckless-tools, i3status (>= 2.3), dunst
Homepage: https://i3wm.org/
Download-Size: 1,996 B
APT-Sources: http://ke.archive.ubuntu.com/ubuntu focal/universe amd64 Packages

要有效使用i3窗口管理器,还需要其他工具。 这些包括;

  • i3 window manager:i3-wm本身
  • i3lock 屏幕锁
  • i3status 用于系统信息
  • suckless-tools 对于dmenu

这些软件包与i3元软件包一起安装。

从Ubuntu / Debian Repos安装最新的i3 Windows Manager

i3的当前稳定版本是4.18.2。 但是,如果您可以检查默认Ubuntu仓库提供的版本,您将意识到它不是最新的。

为确保我们安装了最新版本并确保无缝更新/升级,请创建i3-wm存储库;

/usr/lib/apt/apt-helper download-file https://debian.sur5r.net/i3/pool/main/s/sur5r-keyring/sur5r-keyring_2020.02.03_all.deb 
keyring.deb SHA256:c5dd35231930e3c8d6a9d9539c846023fe1a08e4b073ef0d2833acd815d80d48
dpkg -i keyring.deb
echo "deb [arch=amd64] https://debian.sur5r.net/i3/ $(grep '^DISTRIB_CODENAME=' /etc/lsb-release | cut -f2 -d=) universe" > /etc/apt/sources.list.d/sur5r-i3.list

更新您的软件包来源列表。

apt update

现在,您应该可以通过运行以下命令来安装最新版本的i3-wm;

apt install i3

在Ubuntu 20.04上配置i3 Windows Manager

安装完成后,您现在可以继续在Ubuntu 20.04上配置i3-wm。

首先,注销系统,然后再次登录。 登录时,请确保选择i3会话作为登录屏幕。

成功登录后,系统将提示您是否:

  • 自动生成i3-wm配置文件, ~/.config/i3/config 要么
  • 只需使用默认配置文件。

在Ubuntu 20.04上安装和设置i3 Windows Manager

在此设置中,我们将采用必须自动生成i3-wm配置文件的第一个选项。 稍后我们将对其进行修改以适合我们的需求。 因此,按 输入 并继续。

接下来,您需要定义i3-wm修改键($ mod)。 您在这里有两个选择:可以使用 Windows logo key 或者 Alt key。 在此设置中,我们将使用流行的$ mod键, Windows logo key 作为我们的i3-wm修改器,默认情况下处于选中状态。 使用向上或向下箭头键选择 $ mod 键。

在Ubuntu 20.04上安装和设置i3 Windows Manager

按下写更改 输入

现在,您应该受到黑屏的欢迎,其底部的状态栏类似于下面的屏幕快照所示;

在Ubuntu 20.04上安装和设置i3 Windows Manageri3的基本用法

现在,它已随基本配置设置一起安装,现在有一些组合键可用于执行一些基本任务。

请注意,$ mod代表您选择的修饰键。 Alt或Win键。 这是我们设置中的Win键

  • 打开一个终端: $mod + ENTER
  • 通过dmenu启动系统应用程序: $mod + d。 这会在屏幕顶部打开一个菜单,您可以在其中放置关键字来搜索特定的应用程序。
  • 开启和关闭进入全屏模式: $mod + f
  • 关闭应用程序窗口; $mod + Shift + q
  • 重新启动i3: $mod + Shift + r
  • 退出i3 Windows Manager: $mod + Shift + e

在Ubuntu 20.04上自定义i3

接下来,我们要使i3更具吸引力且易于使用。 您可以通过修改 ~/.config/i3/config 文件。

下面是我们的示例i3 wm配置;

# Please see http://i3wm.org/docs/userguide.html for a complete reference!
#

set_from_resource $darkred     color1  #000000
set_from_resource $red         color9  #000000
set_from_resource $darkgreen   color2  #000000
set_from_resource $green       color10 #000000
set_from_resource $darkyellow  color3  #000000
set_from_resource $yellow      color11 #000000
set_from_resource $darkblue    color4  #000000
set_from_resource $blue        color12 #000000
set_from_resource $darkmagenta color5  #000000
set_from_resource $magenta     color13 #000000
set_from_resource $darkcyan    color6  #000000
set_from_resource $cyan        color14 #000000
set_from_resource $darkwhite   color7  #000000
set_from_resource $white       color15 #000000

# Use custom colors for black
 set $black       #282828
 set $darkblack   #1d2021
 set $transparent #00000000

set $mod Mod4
set $mod1 Mod1
set $terminator terminator


# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
font pango:monospace 12

# This font is widely installed, provides lots of unicode glyphs, right-to-left
# text rendering and scalability on retina/hidpi displays (thanks to pango).

font pango:DejaVu Sans Mono 12
#font pango:Meslo LG L Regular Nerd Font Complete 15

# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# start a terminator by pressing Mod key + x or ENTER
bindsym $mod+Return exec $terminator
bindsym $mod+x exec $terminator

# Custom bindsyms
bindsym $mod+p exec ~/.config/i3/bin/logout
bindsym $mod+l exec i3lock -i /home/koromicha/Pictures/linuxtux.png
bindsym $mod+c exec google-chrome
bindsym $mod+r mode "resize"
bindsym $mod+Shift+f exec /home/koromicha/.config/i3/bin/rofifinder


# Enable Print Screen
#bindsym --release $mod+Print exec gnome-screenshot -i
bindsym --release $mod+Print exec shutter -s

# kill focused window
bindsym $mod+q kill

# start dmenu (a program launcher)
bindsym $mod+d exec --no-startup-id ~/.config/i3/bin/rofi_app_launcher


# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
# bindsym $mod+l focus up
bindsym $mod+semicolon focus right

# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# move focused window
bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+l move up
bindsym $mod+Shift+semicolon move right

# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right


# split in horizontal orientation
bindsym $mod+h split h

# split in vertical orientation
bindsym $mod+v split v

# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle

# change container layout (stacked, tabbed, toggle split)
bindsym $mod+s layout stacking
#bindsym $mod+w layout tabbed
bindsym $mod+t layout tabbed
bindsym $mod+e layout toggle split

# toggle tiling / floating
bindsym $mod+Shift+space floating toggle

# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle

# focus the parent container
bindsym $mod+a focus parent
# focus the child container
bindsym $mod+z focus child

# Workspace Variables
set $ws1 "1: "
#set $ws2 "2: "
set $ws2 "2: "
set $ws3 "3: "
set $ws4 "4: "
set $ws5 "5: "
set $ws6 "6:"
set $ws7 "7:"
set $ws8 "8: "
set $ws9 "9: "


# switch to workspace
bindsym $mod+1 workspace $ws1
bindsym $mod+2 workspace $ws2
bindsym $mod+3 workspace $ws3
bindsym $mod+4 workspace $ws4
bindsym $mod+5 workspace $ws5
bindsym $mod+6 workspace $ws6
bindsym $mod+7 workspace $ws7
bindsym $mod+8 workspace $ws8
bindsym $mod+9 workspace $ws9
bindsym $mod+0 workspace $ws10

# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace $ws1
bindsym $mod+Shift+2 move container to workspace $ws2
bindsym $mod+Shift+3 move container to workspace $ws3
bindsym $mod+Shift+4 move container to workspace $ws4
bindsym $mod+Shift+5 move container to workspace $ws5
bindsym $mod+Shift+6 move container to workspace $ws6
bindsym $mod+Shift+7 move container to workspace $ws7
bindsym $mod+Shift+8 move container to workspace $ws8
bindsym $mod+Shift+9 move container to workspace $ws9
bindsym $mod+Shift+0 move container to workspace $ws10

# reload the configuration file
bindsym $mod+Shift+c reload
# restart i3 inplace
bindsym $mod+Shift+r restart
# exit i3 (logs you out of your X session)
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"

# resize window (you can also use the mouse for that)
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode

        # Pressing left will shrink the window’s width.
        # Pressing right will grow the window’s width.
        # Pressing up will shrink the window’s height.
        # Pressing down will grow the window’s height.
        bindsym j resize shrink width 10 px or 10 ppt
        bindsym k resize grow height 10 px or 10 ppt
        bindsym l resize shrink height 10 px or 10 ppt
        bindsym semicolon resize grow width 10 px or 10 ppt

        # same bindings, but for the arrow keys
        bindsym Left resize shrink width 10 px or 10 ppt
        bindsym Up resize grow height 10 px or 10 ppt
        bindsym Down resize shrink height 10 px or 10 ppt
        bindsym Right resize grow width 10 px or 10 ppt

        # back to normal: Enter or Escape
        bindsym Return mode "default"
        bindsym Escape mode "default"
}
#
# Pulse Audio controls
# run pactl list sinks
#bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +5% #increase sound volume
#bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -5% #decrease sound volume#
#bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 1 toggle # mute sound

# Amixer

bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -D pulse sset Master 5%+ #increase sound volume
bindsym XF86AudioLowerVolume exec --no-startup-id amixer -D pulse sset Master 5%- #decrease sound volume#
bindsym XF86AudioMute exec --no-startup-id amixer -q set Master toggle # mute sound

# Sreen brightness controls
# enable passwordless sudo for ybacklight. echo "koromicha ALL=NOPASSWD: /usr/bin/ybacklight" > /etc/sudoers.d/ybacklight
bindsym XF86MonBrightnessUp exec sudo ybacklight -inc 5 # increase screen brightness
bindsym XF86MonBrightnessDown exec sudo ybacklight -dec 5 # decrease screen brightness

# i3blocks
bar {
    status_command i3blocks
    position top
    font pango:Hack, FontAwesome 11

    colors {
        separator #081419
        background #253941
        #statusline #839496
        focused_workspace #fdf6e3 #6c71c4 #fdf6e3
        active_workspace #fdf6e3 #6c71c4 #fdf6e3
        inactive_workspace #002b36 #586e75 #002b36
        urgent_workspace #d33682 #d33682 #fdf6e3

        statusline         $white
        separator          $transparent
  }
}


set $m1 #808080 
set $m2 #FFF0E0

# Startup programs
exec --no-startup-id dunst 
exec_always compton &;
exec --no-startup-id clipit &; 
exec_always feh --bg-scale /home/koromicha/Pictures/linux-wallpaper.jpg
exec_always --no-startup-id nm-applet


# Bind App to workspace
# Check class by using xprop command
assign [class="chromium"] $ws2
assign [class="Firefox"] $ws2
assign [class="Atom"] $ws3
assign [class="Foxit Reader"] $ws3
assign [class="Pcmanfm"] $ws4
assign [class="VirtualBox"] $ws5
assign [class="Virt-manager"] $ws5
assign [class="Skype"] $ws6
assign [class="mpv"] $ws9
assign [class="vlc"] $ws9
assign [class="Thunderbird"] $ws7
assign [class="(?i)libreoffice-startcenter"] $ws8
assign [class="(?i)soffice"] $ws8
assign [class="(?i)libreoffice"] $ws8


# Assign to certain workspace
assign [window_role="browser"] $ws2

# Press $mod+o followed by either f, s, l, m, v, k, d, t, Esc or Return {ENTER),
# to launch FoxiReader, Skype, lxappearance, thunderbird, VirtualBox,
# KVM Virt-manager, spectacle, pcmanfm file manager, 
# or return to the default mode, respectively.
set $mode_launcher Launcher
bindsym $mod+o mode "$mode_launcher"

mode "$mode_launcher" {
    bindsym f exec FoxitReader 
    bindsym s exec skypeforlinux
    bindsym l exec lxappearance  
    bindsym m exec thunderbird  
    bindsym v exec VirtualBox 
    bindsym k exec virt-manager 
    bindsym d exec spectacle 
    bindsym t exec "pcmanfm /home/koromicha"

    bindsym Esc mode "default"
    bindsym Return mode "default"
}

# Shutdown, Reboot, Lock Screen, and Logout 

set $power_mode "power"
bindsym $mod+Shift+q      mode $power_mode
mode $power_mode {
    bindsym p         exec systemctl poweroff
    bindsym r         exec systemctl reboot 
    bindsym l         exec i3lock -i /home/koromicha/Pictures/linuxtux.png, mode "default"
    bindsym q         exec --no-startup-id i3-msg exit, mode "default"
    bindsym h         exec sudo systemctl hibernate 
    bindsym s         exec sudo systemctl suspend
    bindsym Return    mode "default"
    bindsym Escape    mode "default"
}

# Floating windows
for_window [window_role="task_dialog|bubble|page-info|Preferences|pop-up"] floating enable
for_window [window_role="Open Files"] floating enable sticky
for_window [window_role="File Operation Progress"] floating enable sticky
for_window [class="qBittorrent" window_role="pop-up"] floating enable
for_window [window_type="dialog"] floating enable
for_window [window_type="menu"] floating enable

# Sticky window
for_window [instance="file_progress"]  sticky enable
for_window [class="info|Mate-color-select|gcolor2|timesup|QtPass|GtkFileChooserDialog"] sticky enable

# Focus window settings
no_focus [window_role="pop-up"]
focus_on_window_activation focus

上面的配置为我们提供了这样的窗口;

在Ubuntu 20.04上安装和设置i3 Windows Manager

以上需要什么

安装需要包

以上显示需要许多软件包,以及上面的配置文件中定义的各种快捷方式。

apt install feh fonts-font-awesome rofi pulseaudio-utils xbacklight a alsa-tools clipit gcc git terminator locate pcmanfm acpi libnotify-bin

如果xbacklight不起作用,请安装ybacklight来控制屏幕亮度。

git clone https://github.com/szekelyszilv/ybacklight.git
cd ybacklight/src
gcc ybacklight.c -o /usr/bin/ybacklight

安装快门获取屏幕截图;

sudo add-apt-repository -y -u ppa:linuxuprising/shutter
apt install shutter

安装i3注销脚本

按照上面的i3配置定义,注销脚本,按下该按钮后,将显示如下所示的注销界面 $mod+p 组合键,安装在 ~/.config/i3/bin/logout

在Ubuntu 20.04上安装和设置i3 Windows Manager

创建i3二进制脚本目录并安装注销脚本。

mkdir ~/.config/i3/bin/
vim ~/.config/i3/bin/logout
#!/usr/bin/env bash
# Manage logout with rofi
option=`echo -e "suspendnlock screennlogoutnrebootnpoweroffnKill user $USER" | rofi -width 600 -dmenu -p system:`
case $option in
    suspend)
        sudo  /usr/bin/systemctl syspend
        ;;
    'lock screen')
        i3lock -i /home/koromicha/Pictures/linuxtux.png
        ;;
    logout)
        i3-nagbar -t warning -m 'Are you sure you  want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'
        ;;
    reboot)
        /usr/bin/systemctl reboot
        ;;
    poweroff)
        /usr/bin/systemctl poweroff
        ;;
    'kill user $USER')
        loginctl kill-user $USER
        ;;
esac

注意:该脚本是服务器上提供的注销脚本的修改版本。 Jmutai点文件 github仓库。 确保使脚本可执行;

chmod +x ~/.config/i3/bin/logout

使用Rofi搜索和查找文件

rofi可用于搜索和定位系统中的文件和文件夹。 以下是我们使用的rofi finder脚本;

vim ~/.config/i3/bin/rofifinder
#!/bin/bash
xdg-open "$(locate -i / | rofi -threads 0 -width 100 -dmenu -i -p "Find")"

可以按我们的配置启动rofi finder,方法是按 $mod+Shift+f 组合键。 看起来是这样的;

Rofi查找器Ubuntu 20.04

请注意,脚本使用 locate 命令。 如果尚未安装,请安装它,并更新mlocate数据库;

apt install mlocate && updatedb

使用Rofi启动系统应用

您还可以配置rofi以使用i3-dmenu-desktop启动系统应用程序。 以下是本指南中用于启动系统应用程序的脚本;

vim ~/.config/i3/bin/rofi_app_launcher
#!/usr/bin/env bash
# Run rofi app launcher
i3-dmenu-desktop --dmenu="rofi -dmenu -i -p 'apps'"
chmod +x ~/.config/i3/bin/rofi_app_launcher

rofi应用启动器的i3配置为;

# start dmenu (a program launcher)
bindsym $mod+d exec --no-startup-id ~/.config/i3/bin/rofi_app_launcher

根据我们的配置启动rofi应用启动器的快捷方式是: $mod+d。 参见示例启动菜单屏幕;

rofi应用启动器

要自定义rofi窗口,请使用 rofi-theme-selector

其他定制;

使用快门启用打印屏幕

# Enable Print Screen
#bindsym --release $mod+Print exec gnome-screenshot -i
bindsym --release $mod+Print exec shutter -s

杀死一个聚焦的窗户;

# kill focused window
bindsym $mod+q kill

在工作区中的不同窗口之间更改焦点(请参见相应的快捷键);

# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
# bindsym $mod+l focus up
bindsym $mod+semicolon focus right

# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# move focused window
bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+l move up
bindsym $mod+Shift+semicolon move right

# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

垂直分割视窗($ mod + v)或水平($ mod + h);

# split in horizontal orientation
bindsym $mod+h split h

# split in vertical orientation
bindsym $mod+v split v

将窗口设置为全屏模式($ mod + f);

# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle

将窗口设置为平铺或浮动模式($mod+Shift+space);

# toggle tiling / floating
bindsym $mod+Shift+space floating toggle

更改父窗口或子窗口的焦点;

# focus the parent container
bindsym $mod+a focus parent
# focus the child container
bindsym $mod+z focus child

为不同的工作区设置图标;

# Workspace Variables
set $ws1 "1: "
#set $ws2 "2: "
set $ws2 "2: "
set $ws3 "3: "
set $ws4 "4: "
set $ws5 "5: "
set $ws6 "6:"
set $ws7 "7:"
set $ws8 "8: "

在Ubuntu 20.04上安装和设置i3 Windows Manager

注意,我们还将各种应用程序绑定到它们各自的工作空间。

# Bind App to workspace
# Check class by using xprop command
assign [class="chromium"] $ws2
assign [class="Firefox"] $ws2
assign [class="Atom"] $ws3
assign [class="Foxit Reader"] $ws3
assign [class="Pcmanfm"] $ws4
assign [class="VirtualBox"] $ws5
assign [class="Virt-manager"] $ws5
assign [class="Skype"] $ws6
assign [class="mpv"] $ws9
assign [class="vlc"] $ws9
assign [class="Thunderbird"] $ws7
assign [class="(?i)libreoffice-startcenter"] $ws8
assign [class="(?i)soffice"] $ws8
assign [class="(?i)libreoffice"] $ws8


# Assign to certain workspace
assign [window_role="browser"] $ws2

设置i3壁纸

首先,让我们设置一个墙纸。 可以使用设置i3壁纸 feh,一款轻巧,可配置且用途广泛的图像查看器。 在终端上运行命令。

feh --bg-scale /path/to/wallpaper.jpg

这将自动更改您的墙纸。 要确保在登录i3会话时始终设置墙纸,请编辑 〜/ .config / i3 / config 并为您的墙纸图像设置正确的路径;

exec_always feh --bg-scale /path/to/wallpaper.jpg

配置i3block

i3blocks 是i3status的替代产品。 i3blocks在默认的Ubuntu 20.04存储库上可用。 通过运行以下命令安装i3blocks及其它;

接下来,通过替换i3,将i3配置为使用i3block而不是i3status bar {} 具有以下配置的部分;

# i3blocks
bar {
    status_command i3blocks
    position top
    font pango:Hack, FontAwesome 11

    colors {
        separator #081419
        background #253941
        #statusline #839496
        focused_workspace #fdf6e3 #6c71c4 #fdf6e3
        active_workspace #fdf6e3 #6c71c4 #fdf6e3
        inactive_workspace #002b36 #586e75 #002b36
        urgent_workspace #d33682 #d33682 #fdf6e3

        statusline         $white
        separator          $transparent
  }
}

这应该更改i3状态栏。 您还需要i3blocks小块。 “块是单个块的配置,是状态行的一部分”。 您可以在 区块页面。 在我的设置中,大多数脚本都来自 维维尼小块

在继续获取Blocklets脚本之前,请编辑i3blocks.conf以定义图标字体。 真棒字体 本指南中使用了图标;

vim /etc/i3blocks.conf
# i3blocks config file
#
# Please see man i3blocks for a complete reference!
# The man page is also hosted at http://vivien.github.io/i3blocks
#
# List of valid properties:
#
# align
# color
# command
# full_text
# instance
# interval
# label
# min_width
# name
# separator
# separator_block_width
# short_text
# signal
# urgent

# Global properties
#
# The top properties below are applied to every block, but can be overridden.
# Each block command defaults to the script name to avoid boilerplate.
command=~/.config/i3/blocklets/$BLOCK_NAME
separator=false
separator_block_width= 10
markup=pango
align=right

# RAM usage
[memory]
interval=1
label= 
color=#4CAF50

# CPU Usage
[cpu_usage]
label= 
interval=2
color=#87AFAF

# /home Partition Usage
[disk-home]
label=:
interval=30
color=#586E75

# Network Interface IP
[iface]
color=#B4B7B4
interval=1
separator=false
label= 

# Wi-Fi SSID
[ssid]
label=  
color=#d33682
interval=2

#Network Bandwidth
[bandwidth]
interval=1
color=#d33682

# Screen brightness
[brightness]
label= 
interval=1
signal=2
color=#738899

# Battery level
[battery]
interval=10

# Date and Time Calendar
[time]
label= 
interval=1
color=#50C878

# Battery level notification
[batnotify]
interval=10
separator_block_width=4

创建一个目录来存储小块脚本;

mkdir ~/.config/i3/blocklets

此设置中使用的一些块是:

ls .config/i3/blocklets/ -1
bandwidth
batnotify
battery
brightness
cpu_usage
disk-home
iface
memory
ssid
time

以下是脚本内容;

RAM使用情况;

#!/bin/sh
# Copyright (C) 2014 Julien Bonjean 

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

TYPE="${BLOCK_INSTANCE:-mem}"

awk -v type=$TYPE '
/^MemTotal:/ {
	mem_total=$2
}
/^MemFree:/ {
	mem_free=$2
}
/^Buffers:/ {
	mem_free+=$2
}
/^Cached:/ {
	mem_free+=$2
}
/^SwapTotal:/ {
	swap_total=$2
}
/^SwapFree:/ {
	swap_free=$2
}
END {
	if (type == "swap") {
		free=swap_free/1024/1024
		used=(swap_total-swap_free)/1024/1024
		total=swap_total/1024/1024
	} else {
		free=mem_free/1024/1024
		used=(mem_total-mem_free)/1024/1024
		total=mem_total/1024/1024
	}
	pct=used/total*100

	# full text
	printf("%.1fG/%.1fG (%.f%%)n", used, total, pct)

	# short text
	printf("%.f%%n", pct)

	# color
	if (pct > 90) {
		print("#FF0000n")
	} else if (pct > 80) {
		print("#FFAE00n")
	} else if (pct > 70) {
		print("#FFF600n")
	}
}
' /proc/meminfo

case $BLOCK_BUTTON in
    1)
        termite -e  htop
        ;;
esac
@bonjean.info>

CPU使用率脚本;

#!/usr/bin/perl
#
# Copyright 2014 Pierre Mavro 
# Copyright 2014 Vivien Didelot 
# Copyright 2014 Andreas Guldstrand 
#
# Licensed under the terms of the GNU GPL v3, or any later version.

use strict;
use warnings;
use utf8;
use Getopt::Long;

# default values
my $t_warn = 50;
my $t_crit = 80;
my $cpu_usage = -1;

sub help {
    print "Usage: cpu_usage [-w ] [-c ]n";
    print "-w : warning threshold to become yellown";
    print "-c : critical threshold to become redn";
    exit 0;
}

GetOptions("help|h" => &help,
           "w=i"    => $t_warn,
           "c=i"    => $t_crit);

# Get CPU usage
$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is
open (MPSTAT, 'mpstat 1 1 |') or die;
while () {
    if (/^.*s+(d+.d+)s+$/) {
        $cpu_usage = 100 - $1; # 100% - %idle
        last;
    }
}
close(MPSTAT);

$cpu_usage eq -1 and die 'Can't find CPU information';

# Print short_text, full_text
printf "%.2f%%n", $cpu_usage;
printf "%.2f%%n", $cpu_usage;

# Print color, if needed
if ($cpu_usage >= $t_crit) {
    print "#C75D50n";
    exit 33;
} elsif ($cpu_usage >= $t_warn) {
    print "#D7875Fn";
}

exit 0;
@gmail.com>@didelot.org>@deimos.fr>

/ home分区用法;

#!/bin/sh
# Copyright (C) 2014 Julien Bonjean 

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

DIR="${BLOCK_INSTANCE:-$HOME}"
ALERT_LOW="${1:-10}" # color will turn red under this value (default: 10%)

df -h -P -l "$DIR" | awk -v alert_low=$ALERT_LOW '
//.*/ {
	# full text
	print $4

	# short text
	print $4

	use=$5

	# no need to continue parsing
	exit 0
}

END {
	gsub(/%$/,"",use)
	if (100 - use < alert_low) {
		# color
		print "#FF0000"
	}
}
'
# Mouse settings
case $BLOCK_BUTTON in
    1) i3-msg exec 'caja --browser' ;;    # left click, locate +xdg-open files with rofi
    3) i3-msg exec ~/.config/i3/bin/rofi_finder # find files on right click
esac
@bonjean.info>

默认路由网络接口​​IP

#!/bin/bash
# Copyright (C) 2014 Julien Bonjean 
# Copyright (C) 2014 Alexander Keller 

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

#------------------------------------------------------------------------

# Use the provided interface, otherwise the device used for the default route.
if [[ -n $BLOCK_INSTANCE ]]; then
  IF=$BLOCK_INSTANCE
else
  IF=$(ip route | awk '/^default/ { print $5 ; exit }')
fi

#------------------------------------------------------------------------

# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
# connection (think desktop), the corresponding block should not be displayed.
[[ ! -d /sys/class/net/${IF} ]] && exit

#------------------------------------------------------------------------

if [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
  echo down # full text
  echo down # short text
  echo #FF0000 # color
  exit
fi

case $1 in
  -4)
    AF=inet ;;
  -6)
    AF=inet6 ;;
  *)
    AF=inet6? ;;
esac

# if no interface is found, use the first device with a global scope
IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^/]+).* scope global/ && print $1 and exit")

case $BLOCK_BUTTON in
    1)
        termite -e 'ping 8.8.8.8'         ;;

    3) echo -n "$IPADDR" | xclip -q -se c 
        ;;
esac

#------------------------------------------------------------------------

echo "$IPADDR" # full text
echo "$IPADDR" # short text
@nycroth.com>@bonjean.info>

Wi-Fi SSID;

#!/usr/bin/env bash
# Be sure to change the WLAN interface
echo "$(iw dev wlp0s20f3 link | grep SSID | cut -d " " -f 2-)"

网络带宽;

#!/bin/bash

# Use the provided interface, otherwise the device used for the default route.
if [[ -n $BLOCK_INSTANCE ]]; then
  INTERFACE=$BLOCK_INSTANCE
else
  INTERFACE=$(ip route | awk '/^default/ { print $5 ; exit }')
fi

# # if the connection is down, the corresponding block should not be displayed.
if ! [ -e "/sys/class/net/${INTERFACE}/operstate" ] || ! [ "`cat /sys/class/net/${INTERFACE}/operstate`" = "up" ]
then
    exit 0
fi

# path to store the old results in
path="/dev/shm/$(basename $0)-${INTERFACE}"

# grabbing data for each adapter.
read rx < "/sys/class/net/${INTERFACE}/statistics/rx_bytes"
read tx < "/sys/class/net/${INTERFACE}/statistics/tx_bytes"

# get time
time=$(date +%s)

# write current data if file does not exist. Do not exit, this will cause
# problems if this file is sourced instead of executed as another process.
if ! [[ -f "${path}" ]]; then
  echo "${time} ${rx} ${tx}" > "${path}"
  chmod 0666 "${path}"
fi

# read previous state and update data storage
read old < "${path}"
echo "${time} ${rx} ${tx}" > "${path}"

# parse old data and calc time passed
old=(${old//;/ })
time_diff=$(( $time - ${old[0]} ))

# sanity check: has a positive amount of time passed
[[ "${time_diff}" -gt 0 ]] || exit

# calc bytes transferred, and their rate in byte/s
rx_diff=$(( $rx - ${old[1]} ))
tx_diff=$(( $tx - ${old[2]} ))
rx_rate=$(( $rx_diff / $time_diff ))
tx_rate=$(( $tx_diff / $time_diff ))

# shift by 10 bytes to get KiB/s. If the value is larger than
# 1024^2 = 1048576, then display MiB/s instead

# outgoing
tx_kib=$(( $tx_rate >> 10 ))
if [[ "$tx_rate" -gt 1048576 ]]; then
    tx_mbs=$(printf '%s' "`echo "scale=1; $tx_kib / 1024" | bc`")
  echo -n "${tx_mbs}M↑."
else
  echo -n "${tx_kib}K↑."
fi

# incoming
rx_kib=$(( $rx_rate >> 10 ))
if [[ "$rx_rate" -gt 1048576 ]]; then
    rx_mbs=$( printf '%s' "`echo "scale=1; $rx_kib / 1024" | bc`")
  echo -n "${rx_mbs}M↓"
else
  echo -n "${rx_kib}K↓"
fi

# mouse buttons  
case $BLOCK_BUTTON in
    1) tm-cli ;; # transmission-remote-cli
    3) rofi-connm # rofi connection manager 
esac

系统电池状态;

检查电池实例并替换值x in BATX;

ls /sys/class/power_supply/
!/bin/sh
# Copyright (C) 2014 Julien Bonjean 

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

INSTANCE="${1:-BAT1}"
ALERT_LOW="${2:-25}" # color will turn red under this value (default: 10%)
UPOWER="/usr/bin/upower"

if [ ! -x "$UPOWER" ]; then
	echo "upower not found"
	exit 1
fi

$UPOWER -i /org/freedesktop/UPower/devices/battery_$INSTANCE |
	awk -v alert_low=$ALERT_LOW '
/state:/ {
	state = $2
}
/time to full:/ {
	remaining_time = $4 " " substr ($5, 0, 1)
}
/time to empty:/ {
	remaining_time = $4 " " substr ($5, 0, 1)
}
/percentage:/ {
	percentage = $2;
}
END {
	if (state == "charging")
        label = ""
	else if (percentage == "100%")
		label = ""
	else if (percentage > 99)
		label = ""
	else if (percentage > 75)
		label = ""
	else if (percentage > 50)
		label = ""
	else if (percentage > 25)
		label = ""
    else if (percentage > 10) 
		label = ""
    else if (percentage > 5)  
		label = ""
	
    # full text & "[email protected]" > /dev/null;
    print label " " percentage

	# short text
	print label " " percentage

	# color
	gsub(/%$/,"",percentage)
    if (percentage == "100")
		print "#c5c8c6"
    else if (state == "charging")
		print "#c5c8c6"
    else if (+ percentage < + alert_low)
        print "#cc6666"
    else if (percentage < 26)
        print "#af9f87"
    else
        print "#7ea3a3"
}
# mouse buttons
case $BLOCK_BUTTON in
  3) toggle-dpms ;; # left click, control DPMS 
  2) toggle-red ;;  # right click, redshift on/off
  1) getacpi ;; # dialog with battery info
  5) sudo brightness up ;; 
  # xbacklight doesn't work with modesetting use brightness script
  4) sudo brightness down ;; 
esac
@bonjean.info>

日期和时间日历;

#!/bin/bash
date_time=$(date '+%a %d-%m-%Y %R:%S')
echo "$date_time"

#Buttons Control
case "$BLOCK_BUTTON" in
    1) exec zenity --calendar
        ;;
esac

电池放电通知脚本。 确保相应地更换电池实例BATx。

#!/bin/bash

# Battery notifier script for i3
# First warning is at 30%,  Critical warning less than 15%

discharge_mode=`acpi -a | grep -o off`

# Get current battery level and set threshold
battery_level=$(cat /sys/class/power_supply/BAT1/capacity)
critical_value=15
warning_value=30

# Messages to print to notification
message="*** Battery level is ${battery_level}%, critical, sleeping in 30 seconds time ***"
warn_message="*** Battery level is ${battery_level}%, warning, connect your charger ***"

# Notification icon to use
not_icon="/usr/share/icons/gnome/scalable/status/battery-low-symbolic.svg"

if [ "$discharge_mode" == "off" ]; then
  if [  "$battery_level" -le "$critical_value" ]; then
    if [ -f "$not_icon" ]; then
        notify-send -u critical -i "$not_icon" -t 60000 "$message"
       # i3-nagbar -m "$message"
        sleep 300
        sudo  /lib/systemd/systemd-sleep hybrid-sleep
    else
         notify-send -u critical  -t 60000 "$message"
        #i3-nagbar -m "$message"
        sleep 120
        sudo  /lib/systemd/systemd-sleep hybrid-sleep

    fi
   elif [  "$battery_level" -eq "$warning_value" ]; then
     notify-send -u low -i "$not_icon" -t 60000 "$warn_message"
fi
fi

这就是我们的i3状态栏现在的样子;

在Ubuntu 20.04上安装和设置i3 Windows Manager

这就是我们在Ubuntu 20.04上如何安装和设置i3 Windows Manager的指南中的内容。 可以根据自己的喜好自定义这个很棒的工具。 请享用! !

进一步阅读

有关全面的i3参考,请参阅《 i3用户指南》。

i3用户指南

其他教程

在Ubuntu 20.04上安装和设置ZSH和Oh-My-Zsh

在Ubuntu 20.04上安装Bitwarden Password Manager

使用Prometheus和Grafana监控OpenVPN连接

在Ubuntu 20.04上使用Apt-Cacher NG安装和配置APT缓存服务器

Sidebar