wiki:linux/i3

Start terminal within working directory of currently focused window

Create a script write_focused_cwd with this content:

#!/bin/bash

ID=$(xdpyinfo | grep focus | cut -f4 -d " ")
PID=$(($(xprop -id $ID | grep -m 1 PID | cut -d " " -f 3) + 2))

if [ -e "/proc/$PID/cwd" ]; then
    echo $(readlink /proc/$PID/cwd) > $HOME/.cwd
else
    # if no $PID no window is focused
    rm $HOME/.cwd
fi

Open your ~/.bashrc an append these lines at the end:

if [ -f ~/.cwd ]; then
    cd $(< ~/.cwd)
fi

Change the keybinding of your i3 configuration for opening a terminal.

Open ~/.i3/config and replace the bindsym line for opening a terminal with this:

bindsym $mod+Return exec "write_focused_cwd; xterm"

Switching between workspaces

The easiest way is to made this keybinding within ~/.i3/config:

bindsym $mod+i exec "i3-input -F 'workspace %s' -P '
'Workspace: '"

The problem here is i3 will set no focus to the wished workspace when switching between workspaces which are placed on different monitors.

To solve this create a script named `i3_workspace_switch' by example with this content:

#!/bin/bash

echo -n 'Jump to workspace: '
read workspace
i3-msg workspace $workspace

Now set the keybinding like this:

bindsym $mod+i exec xterm -class FXTerm -geometry 60x10 -e i3_workspace_switch

Note: xterm -class FXTerm starts xterm classified as FXTerm in floating mode, see Start application in floating mode

Start application in floating mode

Open ~/.i3/config and define windows which should start in floating mode via its class value:

for_window [class="FXTerm"] floating enable, move absolute position center

Now each application with classification 'FXTerm' starts in floating mode.

Last modified 3 years ago Last modified on Feb 24, 2016, 10:13:17 PM