How you can manage the i3 window manager on multiple computers

栏目: IT技术 · 发布时间: 5年前

内容简介:Posted on 2020-03-21.In this tutorial I'll show you a simple way you can manage the configuration of i3 across multiple computers with different setups on each computer.i3 is my favorite window manager and while I appreciate the simplicity of both

Posted on 2020-03-21.

In this tutorial I'll show you a simple way you can manage the configuration of i3 across multiple computers with different setups on each computer.

i3 is my favorite window manager and while I appreciate the simplicity of both dwm and bspwm I very much prefer both the amazing layout capabilities and the build-in bar in i3.

One of the downsides of i3 however is that its configuration file isn't scriptable and if you run it on multiple computers with different setups, such as a desktop with a dual monitor setup and a laptop, you have to maintain multiple configuration files.

However, there is a simple way you can get around that.

I use a shell script that contains all the different configuration options. I never touch the i3 configuration file manually, instead I change the options in the shell script and run that. The shell script generates the i3 config file and it has conditions that determine what options to use based on the hostname.

Below is an example of such a shell script. Rather than echoing out every configuration line to the i3 config file, I concatenate all the options in a variable and add a newline. There are several way you can do that, but I prefer the method below. The shell script strives to be POSIX.

Please note that you can make many improvements to the script below, such as putting color codes into variables, remove some of the DRY , improve settings, etc., but I have listed it like this to serve as an example for inspiration.

#!/bin/sh
#
# This script generates the i3 config file (v4)

cfg_file="$HOME/.config/i3/config"
hostname=$(hostname)

if [ -d $HOME/.config/i3 ]; then
    # Let's clean up.
    rm $HOME/.config/i3/*
else
    mkdir -pv $HOME/.config/i3
fi

options='# i3 config'"\n"
options="$options"'set $mod Mod4'"\n"
options="$options"'font pango:DejaVu Sans Mono 8'"\n"
options="$options"'floating_modifier $mod'"\n"

# Disable focus following the mouse.
options="$options"'focus_follows_mouse no'"\n"

# Kill focused window.
options="$options"'bindsym $mod+Shift+q kill'"\n"

# Chance focus.
options="$options"'bindsym $mod+h focus left'"\n"
options="$options"'bindsym $mod+j focus down'"\n"
options="$options"'bindsym $mod+k focus up'"\n"
options="$options"'bindsym $mod+l focus right'"\n"

# Move focused window.
options="$options"'bindsym $mod+Shift+h move left'"\n"
options="$options"'bindsym $mod+Shift+j move down'"\n"
options="$options"'bindsym $mod+Shift+k move up'"\n"
options="$options"'bindsym $mod+Shift+l move right'"\n"

# Split in horizontal orientation.
options="$options"'bindsym $mod+Shift+h split h'"\n"

# Split in vertical orientation.
options="$options"'bindsym $mod+Shift+v split v'"\n"

# Enter fullscreen mode for the focused container.
options="$options"'bindsym $mod+Shift+f fullscreen toggle'"\n"

# Change container layout (stacked, tabbed, toggle split).
options="$options"'bindsym $mod+Shift+s layout stacking'"\n"
options="$options"'bindsym $mod+Shift+t layout tabbed'"\n"
options="$options"'bindsym $mod+Shift+e layout toggle split'"\n"

# Toggle tiling / floating.
options="$options"'bindsym $mod+Shift+space floating toggle'"\n"

# Change focus between tiling / floating windows.
options="$options"'bindsym $mod+space focus mode_toggle'"\n"

# Focus the parent container.
#bindsym $mod+a focus parent

# Focus the child container.
#bindsym $mod+d focus child

# Switch to workspace.
options="$options"'bindsym $mod+1 workspace 1'"\n"
options="$options"'bindsym $mod+2 workspace 2'"\n"
options="$options"'bindsym $mod+3 workspace 3'"\n"
options="$options"'bindsym $mod+4 workspace 4'"\n"
options="$options"'bindsym $mod+5 workspace 5'"\n"
options="$options"'bindsym $mod+6 workspace 6'"\n"
options="$options"'bindsym $mod+7 workspace 7'"\n"
options="$options"'bindsym $mod+8 workspace 8'"\n"
options="$options"'bindsym $mod+9 workspace 9'"\n"
options="$options"'bindsym $mod+0 workspace 10'"\n"

# Move focused container to workspace.
options="$options"'bindsym $mod+Shift+1 move container to workspace 1'"\n"
options="$options"'bindsym $mod+Shift+2 move container to workspace 2'"\n"
options="$options"'bindsym $mod+Shift+3 move container to workspace 3'"\n"
options="$options"'bindsym $mod+Shift+4 move container to workspace 4'"\n"
options="$options"'bindsym $mod+Shift+5 move container to workspace 5'"\n"
options="$options"'bindsym $mod+Shift+6 move container to workspace 6'"\n"
options="$options"'bindsym $mod+Shift+7 move container to workspace 7'"\n"
options="$options"'bindsym $mod+Shift+8 move container to workspace 8'"\n"
options="$options"'bindsym $mod+Shift+9 move container to workspace 9'"\n"
options="$options"'bindsym $mod+Shift+0 move container to workspace 10'"\n"

# For the box running with i3-gaps.
if [ "$hostname" = 'foo' ]; then
    options="$options"'gaps inner 10'"\n"
    options="$options"'gaps outer 0'"\n"
fi

# Disable title bars.
options="$options"'for_window [class="^.*"] border pixel 1'"\n"

options="$options"'bindsym $mod+d exec dmenu_run -i -l 20'"\n"
options="$options"'bindsym $mod+Return exec xterm'"\n"
options="$options"'bindsym $mod+c exec claws-mail'"\n"
options="$options"'bindsym $mod+f exec firefox'"\n"
options="$options"'bindsym $mod+g exec gimp'"\n"
options="$options"'bindsym $mod+h exec hexchat'"\n"
options="$options"'bindsym $mod+z exec filezilla'"\n"

# Custom scripts.
options="$options"'bindsym $mod+F9 exec --no-startup-id f9menu'
options="$options"'bindsym $mod+F10 exec --no-startup-id f10menu'"\n"
options="$options"'bindsym $mod+F12 exec --no-startup-id gnome-screenshot -i'"\n"

# Assign to floating by default.
options="$options"'for_window [class="mpv"] floating enable'"\n"

# Let's try to get most pop-up floating.
options="$options"'for_window [window_role="pop-up"] floating enable'"\n"
options="$options"'for_window [window_role="bubble"] floating enable'"\n"
options="$options"'for_window [window_role="task_dialog"] floating enable'"\n"
options="$options"'for_window [window_role="Preferences"] floating enable'"\n"
options="$options"'for_window [window_type="dialog"] floating enable'"\n"
options="$options"'for_window [window_type="menu"] floating enable'"\n"

# Reload the configuration file.
options="$options"'bindsym $mod+Shift+w reload'"\n"

# Restart i3 inplace (preserves your layout/session, can be used to upgrade i3).
options="$options"'bindsym $mod+Shift+Escape restart'"\n"

# Resize window (you can also use the mouse for that).
options="$options"'mode 'resize' {'"\n"
options="$options"'    bindsym h resize shrink width 10 px or 10 ppt'"\n"
options="$options"'    bindsym j resize grow height 10 px or 10 ppt'"\n"
options="$options"'    bindsym k resize shrink height 10 px or 10 ppt'"\n"
options="$options"'    bindsym l resize grow width 10 px or 10 ppt'"\n"

# Back to normal: Enter or Escape.
options="$options"'    bindsym Return mode "default"'"\n"
options="$options"'    bindsym Escape mode "default"'"\n"
options="$options"'}'"\n"

options="$options"'bindsym $mod+Shift+r mode resize'"\n"

if [ "$hostname" = 'foo' ]; then
    # Place workspace.
    options="$options"'workspace 1 output hdmi1'"\n"
    options="$options"'workspace 2 output hdmi2'"\n"

    options="$options"'bar {'"\n"
    options="$options"'    output hdmi1'"\n"
    options="$options"'    position top'"\n"
    options="$options"'    colors {'"\n"
    options="$options"'        background #1e1e1e'"\n"
    options="$options"'        statusline #aaaaaa'"\n"
    options="$options"'        separator  #555555'"\n"
    options="$options"'        focused_workspace  #008fff #007fff #ffffff'"\n"
    options="$options"'        active_workspace   #333333 #5f676a #ffffff'"\n"
    options="$options"'        inactive_workspace #333333 #222222 #888888'"\n"
    options="$options"'        urgent_workspace   #aa0000 #990000 #ffffff'"\n"
    options="$options"'    }'"\n"
    options="$options"'}'"\n"

    options="$options"'bar {'"\n"
    options="$options"'    output hdmi2'"\n"
    options="$options"'    position top'"\n"
    options="$options"'    colors {'"\n"
    options="$options"'        background #1e1e1e'"\n"
    options="$options"'        statusline #aaaaaa'"\n"
    options="$options"'        separator  #555555'"\n"
    options="$options"'        focused_workspace  #008fff #007fff #ffffff'"\n"
    options="$options"'        active_workspace   #333333 #5f676a #ffffff'"\n"
    options="$options"'        inactive_workspace #333333 #222222 #888888'"\n"
    options="$options"'        urgent_workspace   #aa0000 #990000 #ffffff'"\n"
    options="$options"'    }'"\n"
    options="$options"'    status_command i3blocks -c ~/.config/i3blocks.conf'"\n"
    options="$options"'}'"\n"
else
    options="$options"'bar {'"\n"
    options="$options"'    position top'"\n"
    options="$options"'    colors {'"\n"
    options="$options"'        background #1e1e1e'"\n"
    options="$options"'        statusline #aaaaaa'"\n"
    options="$options"'        separator  #555555'"\n"
    options="$options"'        focused_workspace  #008fff #007fff #ffffff'"\n"
    options="$options"'        active_workspace   #333333 #5f676a #ffffff'"\n"
    options="$options"'        inactive_workspace #333333 #222222 #888888'"\n"
    options="$options"'        urgent_workspace   #aa0000 #990000 #ffffff'"\n"
    options="$options"'    }'"\n"
    options="$options"'    status_command i3blocks -c ~/.config/i3blocks.conf'"\n"
    options="$options"'}'"\n"
fi

printf "$options" > $cfg_file
if [ -f $cfg_file ]; then
    echo "Created i3 config file"
else
    echo "Could not write config file"
fi

That's it! Feel free to email me any suggestions, correction, or comments.


以上所述就是小编给大家介绍的《How you can manage the i3 window manager on multiple computers》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

渐进增强的Web设计

渐进增强的Web设计

[美] Todd Parker、[英] Patty Toland、[英] Scott Jehl、[法] Maggie Costello Wachs / 牛化成 / 人民邮电出版社 / 2014-1 / 69.00

本书由全球著名Web设计公司Filament集团两位创始人和两位开发主力联手打造,其中Scott Jehl还是jQuery团队成员。四位作者具有多年的网站设计和开发经验,曾为网站、无线设备、Web应用设计过众多高度实用的用户界面,受到了高度赞扬。本书展示了如何利用渐进增强方法开发网站,从而获得最佳用户体验。本书既是理解渐进增强原则和益处的实用指南,也用详细的案例分析,目的是向设计师以及开发人员传授......一起来看看 《渐进增强的Web设计》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具