ArchLinux Tutorial, Part 3: i3 Configuration and Operation – DZone Open Source | xxxArchLinux Tutorial, Part 3: i3 Configuration and Operation – DZone Open Source – xxx
菜单

ArchLinux Tutorial, Part 3: i3 Configuration and Operation – DZone Open Source

三月 14, 2020 - MorningStar

Over a million developers have joined DZone.

  • ArchLinux Tutorial, Part 3: i3 Configuration and Operation - DZone Open Source

    {{node.title}}

    {{node.type}} · {{ node.urlSource.name }} by

    Download {{node.downloads}}

  • {{totalResults}} search results

{{announcement.body}}

{{announcement.title}}

Let’s be friends:

1024)” dc-slot=”ads.sl1.slot(articles[0], 0)” tags=”ads.sl1.tags(articles[0], 0)” size=”ads.sl1.size(articles[0], 0)” style=”border:0;”>
1 && !articles[0].partner.isSponsoringArticle && (width > 1024)” dc-slot=”ads.sb2.slot(articles[0], 0)” tags=”ads.sb2.tags(articles[0], 0)” size=”ads.sb2.size(articles[0], 0)”>

ArchLinux Tutorial, Part 3: i3 Configuration and Operation

DZone ‘s Guide to

ArchLinux Tutorial, Part 3: i3 Configuration and Operation

The the last of these tutorials, we take a look at installing and configuring i3 in ArchLinux and what you can do with it.

Apr. 22, 20 · Open Source Zone ·

Free Resource

Join the DZone community and get the full member experience.

Join For Free

ArchLinux Tutorial, Part 3: i3 Configuration and Operation - DZone Open Source

Part 1: Basic ArchLinux Installation

Part 2: X Window System and i3 Installation

Part 3: i3 Configuration and Operation

In the last two posts, we covered a base ArchLinux installation on bare-bones hardware and X Window Server installation and basic configuration.

In this post, we will cover the i3 Window Manager Configuration and we will cover some configurations for the ranger file manager.

What is an i3? i3 is a tiling window manager. i3 is one of the fastest and customizable window managers that focuses primarily on efficiency and productivity. i3 provides a very different user experience compared to most common desktop managers like GNOME, KDE or even XFCE. The learning curve is steep, but once you get accustomed to a plethora of shortcuts, you will be surprised how efficient and productive the desktop environment can be.

First, let’s configure i3 start   when we are starting Xserve.

configure ~/.xinit.rc

#!/bin/sh  # ~/.xinit.rc  userresources=$HOME/.Xresources usermodmap=$HOME/.Xmodmap sysresources=/etc/X11/xinit/.Xresources sysmodmap=/etc/X11/xinit/.Xmodmap  # merge in defaults and keymaps  if [ -f $sysresources ]; then     xrdb -merge $sysresources fi  if [ -f $sysmodmap ]; then     xmodmap $sysmodmap fi  if [ -f "$userresources" ]; then     xrdb -merge "$userresources" fi  if [ -f "$usermodmap" ]; then     xmodmap "$usermodmap" fi  if [ -d /etc/X11/xinit/xinitrc.d ] ; then  for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do   [ -x "$f" ] && . "$f"  done  unset f fi  exec i3

The first time you start i3, it will ask you a few questions to select a management key (primary key to manipulating windows and i3 environment), and you have two selections, Windows Key or Alt Key. By default, i3 operates with Windows Key, and I recommend sticking with the default option.

Once i3 is started, it will create a configuration file in used ~/.local/i3 directory where you can configure all the necessary keybindings to get most of the i3 promised efficiencies.

A good start with learning the available options is the i3 official website and, specific for ArchLinux users, the i3 Arch Linux Wiki.

i3 KeyBindings

By default, i3 comes with pre-configured keybindings. I am assuming you selected WinKey as your management key. i3 refers to WinKey as the "$mod" key.

Open new Terminal

WinKey+Enter

You can try to open multiple terminals and to move between terminals without touching your mouse. i3 comes with vim key bindings.

Focus on Left WindowWinKey+j
Focus on Right WindowWinKey+;
Focus on Below Window >WinKey+k
Focus on Upper WindowWinKey+l

You can use the directional keys to navigate.

Window Position

Opening Application Windows we can arrange in a few ways.

Arranged Vertically

ArchLinux Tutorial, Part 3: i3 Configuration and Operation - DZone Open Source

Arranged Horizontally

ArchLinux Tutorial, Part 3: i3 Configuration and Operation - DZone Open Source

Arranged in Mix mode

ArchLinux Tutorial, Part 3: i3 Configuration and Operation - DZone Open Source

Windows Manipulation

Assuming we may have multiple windows open and you would like to focus on a single window, you can use this shortcut

Window full screenWinKey+f

i3 is sizing Windows, and every window gets an equal amount of space. But you can still manage your windows in 3 types.

split vertically and split horizontallyWinKey+e
get a list of windows at the topWinKey+s
position Windows at the top similar to tabsWinKey+w

i3 doesn’t provide a start button where you can launch the application. To start the application, you can use dmenu and pick from the list of installed application to launch.

Start applicationWinKey+d

Another way to start an application that may not appear in dmenu is this shortcut:

Start application

WinKey+Shift+d

Any time you open a new application will open in a new window on the right of the active window. If you intend to open a new window below an active one, you will need to let i3 know.

Focus to open a new window in vertical modeWinKey+v

Now you can open the application, and this will open this active window:

Focus to open a new window in default horizontal positionWinKey+h

i3 provides virtual desktops called workspaces. So as not to clutter the desktop, you can open the application in a chosen window using WinKey and a number from 1 to 0.

Select desktop 1WinKey+1
Select desktop 2WinKey+2
Select desktop 3WinKey+3

Select desktop 4

WinKey+3

Select desktop n

WinKey+n

Move the open application window to a new workspace

Select windows and move to Desktop 2WinKey+Shift+2

In some cases, users may want to make application windows behave similarly as standard desktop windows that can be moved across the desktop in different positions. This can be done in i3 by evoking a floating window.

On selected windows make it floatingWinKey+Shift+Space

If you want to allocate more desktop space for one of the applications, you can resize it.

Enter into the resize mode 

Winkey+r

Once in resize mode you can extend or contract active window both vertically and horizontally.

Horizontal active window resizeWinKey+j or WinKey+:
Vertical active windows resizeWinKey+k or WinKey+l

Instead of jusing the letter keys, feel free to use the directional keys.

Restarting i3WinKey+Shift+r
Exiting i3WinKey+Shift+e

For a more detailed explanation and additional configuration options you can find what you need in the i3 user guide.

i3 already comes with tons of useful keybindings that can help us get more focused and get more productive, but we can enhance it even more.

By default, i3 starts with the status bar at the bottom, and on the right side, you can see system information that can be useful.

Let try to enhance the i3status bar to show us only needed information by editting the ~/.config/i3status/config file.

In below example, I configured my system to show CPU usage, CPU load, disk space used in %, IP address, sound, volume, and time.

# ~/.config/i3status/config  general {         colors = true         interval = 3 }  order += "cpu_usage" order += "load" order += "disk /" order += "ethernet _first_" order += "volume master" order += "tztime local"  ethernet  _first_ {         # if you use %speed, i3status requires root privileges #        format_up = "E: %ip (%speed)"         format_up = "eth: %ip"         format_down = "E: down" }  cpu_usage {         format = "CPU %usage " }  tztime local {         format = "%Y-%m-%d %H:%M:%S" }  load {         format = "%1min %5min %15min" }  disk "/" {   format = "Used / %percentage_used"   separator = false }  volume master {         format = "♪: %volume"         format_muted = "♪: muted (%volume)"         device = "default"         mixer = "Master"         mixer_idx = 0 }

ArchLinux Tutorial, Part 3: i3 Configuration and Operation - DZone Open Source

It is time to do some small modifications to the i3 config file to get some additional functionality.

Edit~/.config/i3/config and add these changes to your configuration. In some cases, you may need to comment the original setting.

# Change Font font pango:monospace 10  # Move status bar on top bar {         position top         status_command i3status }  # Add gaps between windows look nicer gaps inner 5 gaps outer 5  # Mouse, please stop focus whenever you hover to whatever focus_follows_mouse no  # Use Mouse+$mod to drag floating windows to their wanted position floating_modifier $mod  # Enable floating dialogs application window for_window [window_role="pop-up"] floating enable for_window [window_role="task_dialog"] floating enable  # Key bind for Alsa sound # Note: My keyboard has dedicated buttons that it is mapped to alsamixer bindsym XF86AudioRaiseVolume exec amixer -q sset Master 5%+ unmute bindsym XF86AudioLowerVolume  exec amixer -q sset Master 5%- unmute bindsym XF86AudioMute exec amixer -q sset Master toggle  bindsym $mod+= exec amixer -q sset Master 5%+ unmute bindsym $mod+- exec amixer -q sset Master 5%- unmute  bindsym $mod+x [urgent=latest] focus  # num lock activated exec_always --no-startup-id numlockx on exec_always --no-startup-id conky  # Assign application to start on a specific workspace xprop assign [class="^Firefox$"] 1 assign [class="^Slack$"] 3 assign [class="^Code$"] 2 assign [class="^Vlc$"] 9 assign [class="^Spotify$"] 10 for_window [class="Spotify"] move to workspace 10 for_window [class="^Slack$"] floating enable  # Restart or shutdown or suspend by using WinKey+Pause key with meny to select option set $mode_system System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (Shift+s) shutdown mode "$mode_system" {     bindsym l exec --no-startup-id $Locker, mode "default"     bindsym e exec --no-startup-id i3-msg exit, mode "default"     bindsym s exec --no-startup-id $Locker && systemctl suspend, mode "default"     bindsym h exec --no-startup-id $Locker && systemctl hibernate, mode "default"     bindsym r exec --no-startup-id systemctl reboot, mode "default"     bindsym Shift+s exec --no-startup-id systemctl poweroff -i, mode "default"        # back to normal: Enter or Escape     bindsym Return mode "default"     bindsym Escape mode "default" }  bindsym $mod+Pause mode "$mode_system"  # Custom Keybindings  # Shortcuts to start application bindsym $mod+Ctrl+f exec --no-startup-id firefox bindsym $mod+Ctrl+v exec --no-startup-id vlc bindsym $mod+Ctrl+c exec --no-startup-id chromium bindsym $mod+Ctrl+r exec --no-startup-id urxvt -e ranger  # lock PC bindsym $mod+Ctrl+Delete exec $Locker, mode "default"  # Change you $USER home director and you may need to install packages imagemagick xclip  # take a screenshot of a screen region and copy it to a clipboard bindsym --release Shift+Print exec "/home/mudrii/.local/bin/screensh -s /home/mudrii/Images/"  # take a screenshot of a whole window and copy it to a clipboard bindsym --release Print exec "/home/mudrii/.local/bin/screensh /home/mudrii/Images/"

Often, I do not want to start my applications one by one and move to the correct workspace; I want to have a keybinding that allows me to start preselected, correctly formatted applications in a predefined workspace.

To achieve this it will create a script file that can be triggered by a key combination that will open the desired application in the predefined workspace and in a preselected position.

1. Open the selected application and position on your proffered workspace and run:

i3-save-tree --workspace 1 > ~/.config/i3/workspace_1.json && / tail -n +2 ~/.config/i3/workspace_1.json | fgrep -v '// splitv' | sed 's|//||g' > ~/.config/i3/workspace_1.jso

The command above will create a workspace_1.json file with all information captured from i3, which you may need to review and edit if required.

2. Create a shell script that will import the configuration into i3.

Note: In below case, I am starting Firefox, Sublime and Terminal URXVT on workspace 1.

#!/bin/bash  i3-msg "workspace 1; append_layout ~/.config/i3/workspace_1.json"  # And finally we fill the containers with the programs they had (firefox&) (subl3 &) (urxvt &)

3. The last step is to add a keybinding to ~/.config/i3/config.

bindsym $mod+Ctrl+1 exec ~/.config/i3/start_w1.sh

Once you are in i3, use WinKey+Ctrl+1 to open the predefined application in workspace 1. Repeat the same process for the rest of the application.

ArchLinux Tutorial, Part 3: i3 Configuration and Operation - DZone Open Source

Desktop System Information with Conky

Conky is a tool that can display desktop system information like CPU, RAM, and HDD. The Conky configuration is in ~/.config/conky/conky.conf.

-- vim: ts=4 sw=4 noet ai cindent syntax=lua --[[ Conky, a system monitor, based on torsmo Any original torsmo code is licensed under the BSD license All code written since the fork of torsmo is licensed under the GPL Please see COPYING for details Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS) All rights reserved. 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 <http://www.gnu.org/licenses/>. ]]  conky.config = {     own_window_transparent = true,     own_window_argb_visual = true,     own_window_argb_value = 255,     double_buffer = true,     alignment = 'bottom_right',     background = false,     border_width = 2,     cpu_avg_samples = 2,     default_color = 'white',     default_outline_color = 'white',     default_shade_color = 'white',     draw_borders = false,     draw_graph_borders = true,     draw_outline = false,     draw_shades = true,     use_xft = true,     font = 'Roboto Mono:size=14',     gap_x = 20,     gap_y = 50,     minimum_height = 5,     minimum_width = 5,     net_avg_samples = 2,     no_buffers = true,     out_to_console = false,     out_to_stderr = false,     extra_newline = false,     own_window = true,     own_window_class = 'Conky',     own_window_type = 'override',     stippled_borders = 0,     update_interval = 5.0,     uppercase = false,     use_spacer = 'none',     show_graph_scale = true,     show_graph_range = true }  conky.text = [[ ${color white}Uptime: ${color white}$uptime $hr ${color white}CPU:$color $cpu% ${color white}RAM:$color $mem / $memmax $hr /root: $color${fs_used /} / ${fs_size /} ]]

To see Conky for i3 add the below line to ~/.config/i3/config.

exec_always --no-startup-id conky

ArchLinux Tutorial, Part 3: i3 Configuration and Operation - DZone Open Source

Ranger File Manager

Ranger is a text-based file manager written in Python. Directories are displayed in one pane with three columns. We can configure Ranger to look more like the Midnight commander Unix users may be familiar.
Most of the keybindings in Ranger are very similar to VIM. If you are VIM users, Ranger will fit like a glove and if you are not, this is an excellent opportunity to get acquainted.

Let’s deep dive into the configuration options.

Once installed ranger let’s generate configuration files.

ranger --copy-config=all

This command will generate 5 files:

  • commands_full.py 

  • commands.py 

  • rc.conf 

  • rifle.conf 

  • scope.sh

Let’s focus first on default keys to manipulate files with the Ranger.

Navigation

Ranger uses many of the same keybindings as vim.

KeyDescription
jMove down
kMove up
hMove to the parent directory
ggGo to the top of the list
GGo to the bottom of the list
<Ctrl>+fPage down

<Ctrl>+b

Page up
JPage down 1/2 page
KPage up 1/2 page
HGo back through navigation history
LGo forward through navigation history

There are also some directory-specific shortcuts to move to common directories:

KeyDescription
ghcd ~
gecd /etc
gucd /usr
gdcd /dev
gocd /opt
gvcd /var
gmcd /media
gMcd /mnt
gscd /srv
grcd /
gRcd to ranger’s global configuration directory

Working With Files

Ranger allows you to perform many different operations on files from within its interface.

KeyDescription
iDisplay file (useful if you’d like to view a text file in a pager instead of editing it)
l or EOpen file (opens file in default file-handler)
rOpen file with… (allows you to choose a program to use)
oChange sort order (follow by a character in menu selection)
zChange settings (commonly used toggle settings)
zhView hidden files ( . files)
<Space>Select current file
tTag file (you can perform actions on tagged files)
cwRename current file
/Search for files
nJump to next match
NJump to the previous match
yyYank (copy) file
ddMark file for cut operation
<Delete>Delete selected file

Tabbed Browsing

Ranger also incorporates tabbed functionality to allow multiple viewports into the filesystem.

KeyDescription
<Ctrl>+nCreate new tab
<Ctrl>+wClose current tab
<Ctrl>+~View Both Tabs in same windows
<Tab>Next tab
<Shift><Tab>Previous tab

General Commands

These commands control Ranger itself:

KeyDescription
?View ranger man page
1?Keybindings help
2?Command help
3?Settings help
R

Reload current directory

QQuit

Command Interface

Like VIM, Ranger also includes a robust command interface. This allows you to manipulate files in more complex ways.

KeyDescription
!Execute a command from the shell (non-ranger commands)
:Execute a ranger command
duMeasure disk usage of the current directory
chmodChange permissions of the current file

There are a number of flags that you can pass to commands to modify the operation of the commands. They should be used with a dash "-" after typing "!" for shell commands or ":" for Ranger commands:

KeyDescription
-sDiscard the output of the current command.
-dDetach the process and run in the background
-pReturn the output in ranger’s file pager
-wDo not return immediately after command execution. Hang until "Enter" is pressed
-cPerform command on the current file, not the selected files

Ranger also allows you to target specific files by substituting groups of files for command operations. It accomplishes that by using placeholders that will be expanded with the correct files upon execution:

KeyDescription
%fSubstitute highlighted file
%dSubstitute current directory
%sSubstitute currently selected files
%tSubstitute currently tagged files

For example, if we wanted to change the names of multiple files, we could select them all with the space bar. After that, we can type:

:bulkrename %s

Once you get familiar with the Ranger operational mode, you can make some small changes to the Ranger and get more customized to our needs by editing main configuration file ~/.config/ranger/rc.conf

Note: In the below output, only changes and addons are pasted.

# ~/.config/i3status/config  general {         colors = true         interval = 3 }  order += "cpu_usage" order += "load" order += "disk /" order += "ethernet _first_" order += "volume master" order += "tztime local"  ethernet  _first_ {         # if you use %speed, i3status requires root privileges #        format_up = "E: %ip (%speed)"         format_up = "eth: %ip"         format_down = "E: down" }  cpu_usage {         format = "CPU %usage " }  tztime local {         format = "%Y-%m-%d %H:%M:%S" }  load {         format = "%1min %5min %15min" }  disk "/" {   format = "Used / %percentage_used"   separator = false }  volume master {         format = "♪: %volume"         format_muted = "♪: muted (%volume)"         device = "default"         mixer = "Master"         mixer_idx = 0 }

0

Let’s add more functionality to cleanup trash by editing~/.config/ranger/commands.py.

# ~/.config/i3status/config  general {         colors = true         interval = 3 }  order += "cpu_usage" order += "load" order += "disk /" order += "ethernet _first_" order += "volume master" order += "tztime local"  ethernet  _first_ {         # if you use %speed, i3status requires root privileges #        format_up = "E: %ip (%speed)"         format_up = "eth: %ip"         format_down = "E: down" }  cpu_usage {         format = "CPU %usage " }  tztime local {         format = "%Y-%m-%d %H:%M:%S" }  load {         format = "%1min %5min %15min" }  disk "/" {   format = "Used / %percentage_used"   separator = false }  volume master {         format = "♪: %volume"         format_muted = "♪: muted (%volume)"         device = "default"         mixer = "Master"         mixer_idx = 0 }

1

You can find more information on the Arch Linux Wiki Ranger page, and these config files can be found in my Github.

We just touched the surface of what is possible in i3. Every user may have a separate setup and desktop configurations and i3 is one of the most flexible and versatile window managers that provides full control over these settings. Feel free to explore and deep dive into countless possibilities i3 provides.

Like This Article? Read More From DZone

Topics:
linux ,desktop ,i3 ,archlinux ,installation and configuration ,open source

Opinions expressed by DZone contributors are their own.

Open Source Partner Resources

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.linkDescription }}

{{ parent.urlSource.name }}

by

CORE

· {{ parent.articleDate | date:’MMM. dd, yyyy’ }} {{ parent.linkDate | date:’MMM. dd, yyyy’ }}


Notice: Undefined variable: canUpdate in /var/www/html/wordpress/wp-content/plugins/wp-autopost-pro/wp-autopost-function.php on line 51