# LibTmux::Session#link_window

- **Module:** LibTmux
- **Package:** libtmux
- **Language:** Ruby
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-ruby/blob/da7b6191b9439e3c84fa1c9eeaa9168263ee7af4/gems/libtmux/lib/libtmux/operations.rb#L268
- **Page:** https://libtmux.org/en/ruby/v0.1.1/reference/libtmux-session-link_window/

```
def link_window: (
  ::LibTmux::EntityRef,
  index: ::Integer,
  ?timeout: ::Numeric,
  ?cancel: untyped
) -> ::LibTmux::CommandResult
```

Behavior: Window links.

Behavior contract: Window links.

## Examples

Link one window at two more indexes of its session and list the three links that share one window ID. Use Ruby 3.3 or newer with Bundler, and tmux 3.3a or newer, on Unix with `/bin/cat` and `/bin/sh` available. In an empty directory, save this `Gemfile`:

```ruby
source "https://rubygems.org"

gem "libtmux", "0.1.1"
```

Save this complete program as `link_window.rb`. Its `Server.start` block owns a private tmux server and stops it on exit, including after an error.

[Source example](https://github.com/libtmux/libtmux-ruby/blob/da7b6191b9439e3c84fa1c9eeaa9168263ee7af4/examples/api/link_window.rb).

```ruby
# frozen_string_literal: true

begin
  # docs:begin main
  require "libtmux"

  LibTmux::Server.start do |server|
    session = server.new_session(name: "links", command: ["/bin/cat"])
    window = session.list_windows.fetch(0)
    session.link_window(window.ref, index: 4)
    session.link_window(window.ref, index: 9)
    links = session.list_window_links
    puts "indexes: #{links.map(&:index).join(', ')}"
    puts "windows: #{links.map { |link| link.window.id }.uniq.join(', ')}"
  end
  # docs:end main
rescue StandardError => error
  warn "#{error.class}: #{error.message}"
  exit 1
end
```

Install the gem and run the program. An operation or cleanup error makes it exit unsuccessfully:

```console
$ bundle install && \
  bundle exec ruby link_window.rb
```

Expected output:

```text
indexes: 0, 4, 9
windows: @0
```

## Parameters

- `arg1` (`::LibTmux::EntityRef`)
- `index` (`::Integer`)
- `timeout` (`::Numeric`)
- `cancel` (`untyped`)

## Raises

- `ArgumentError`

## tmux command

The tmux commands behind `link_window`.

- [`link-window`](/en/tmux/latest/manual/link-window/)

## tmux C API

The C declarations in tmux that implement these commands.

- [`cmd_link_window_entry`](/en/tmux/latest/reference/c-variable-cmd_link_window_entry/) (attribute)
- [`cmd_move_window_exec`](/en/tmux/latest/reference/c-function-cmd-move-window-c-cmd_move_window_exec/) (function)

## Guides

Pages that discuss `link_window`.

- [Server bindings](/en/ruby/v0.1.1/guides/core/)

## In other ports

Link a window into another session

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Window.link`](/en/py/latest/reference/libtmux-window-link/) (method) |
| Lua | [`libtmux.WindowLink:link`](/en/lua/latest/reference/libtmux-windowlink-link/) (method) |
| TypeScript | [`window.Window.link`](/en/ts/latest/reference/window-window-link/) (method) |
| Rust | [`window.Window.link_to`](/en/rs/latest/reference/window-window-link_to/) (method) |
| Go | [`tmux.Window.Link`](/en/go/latest/reference/tmux-window-link/) (method) |
| Java | [`io.github.libtmux.Window.linkTo`](/en/java/latest/reference/io-github-libtmux-window-window-linkto/) (method) |
| C# | [`LibTmux.Window.LinkAsync`](/en/csharp/latest/reference/libtmux-window-linkasync/) (method) |
| C++ | [`libtmux::Window::link_to`](/en/cxx/latest/reference/libtmux-window-link_to/) (method) |
| Swift | [`Server.link(_:into:)`](/en/swift/latest/reference/server-link(_-into-)/) (method) |

No equivalent is recorded in PowerShell, Julia, Elixir, Kotlin, Scala or F#.
