Difference between revisions of "Tmux"

From Redbrick Wiki
Jump to navigation Jump to search
(How to install and use tmux)
Line 1: Line 1:
Once upon a time there was BitchX. Then there was Irssi. Now there is Weechat. More and more people are switching over to Weechat from Irssi, probably coz the colours make IRC easier to read and follow. Problem is, for the Irssi user, Weechat may be a tad confusing.
Tmux is a terminal multiplexer
Weechat documentation can be tricky to follow, so this page is an attempt to make simple those bizarre and abstract commands.
What is a terminal multiplexer? It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.
It is a good alternative to screen.
== Running Weechat ==
$ git clone https://github.com/tmux/tmux.git
$ cd tmux
$ sh autogen.sh
$ ./configure && make
Dregin is a big Weechat fanboi. And as such, he has his own special builds designed for Redbrick. Azazel is the current login machine, dregin has compiled a version of Weechat that runs on azazel:
Shortcuts are all used by pressing the prefix then the shortcut.
The default is  
Control + b <shortcut>
The prefix can also be changed. (At the end of the wiki)
Copy and paste that into your terminal command line, hit enter, and give yourself a pat on the back.
==Session Management==
== Compiling Weechat ==
Sessions are useful for completely separating work environments.  
You can run
This is only recommended for running it the first time as it will overwrite your weechat config.
If You want to update your install just run
git clone https://github.com/weechat/weechat
cd weechat
mkdir build
cd build
make install
echo '*/upgrade ~/bin/weechat' > `find ~/.weechat -name "weechat_fifo_*"`
rm -rf ~/weechat
==Customising Weechat ==
To create a new tmux session named session_name
Weechat can be very basic when you first run it so here are some conf files to set it up with.
tmux new -s session_name
  cp ~edu/wcconf/* ~/.weechat/
To attache to an existing tmux session named session_name
you need to set your nick for the server
  tmux attach -t session_name
  vim ~/.weechat/irc.conf
To switche to an existing session named session_name
tmux switch -t session_name
To list existing tmux sessions
tmux list-sessions
To detach the currently attached session
  tmux detach (prefix + d)
If you ran the ~edu/compileweechat this will already have been done for you
== Basic use ==
use. (Well I don't because I guess I hate myself.
=== Connecting to a server and channel ===
To create a new window
tmux new-window (prefix + c)
To move to the window based on index
tmux select-window -t :0-9 (prefix + 0-9)
To rename the current window
tmux rename-window (prefix + ,)
When you hit 'chat' on Redbrick, you start Irssi, you're automatically connected to a server, then you're joined to Redbrick's #lobby. This all happens behind the scenes, and with Weechat, you need to do this manually. Fear not: it's easy.
When you start Weechat, you won't get connected to a server or channel. To connect to Redbrick's IRC sever, type:
Panes make everything easier, and better!
  /connect irc.redbrick.dcu.ie
splits the window into two vertical panes
  tmux split-window (prefix + ")
splits the window into two horizontal panes
tmux split-window -h (prefix + %)
swaps pane with another in the specified direction
tmux swap-pane -[UDLR] (prefix + { or })
selects the next pane in the specified direction
tmux select-pane -[UDLR]
selects the next pane in numerical order
tmux select-pane -t :.+
Then to join #lobby:
==Helpful tmux commands==
  /join #lobby
lists out every bound key and the tmux command it runs
  tmux list-keys
lists out every tmux command and its arguments
tmux list-commands
lists out every session, window, pane, its pid, etc.
tmux info
reloads the current tmux configuration (based on a default tmux config)
tmux source-file ~/.tmux.conf
As well as showing you how IRC clients (such as Weechat or Irssi or whatever) connect to stuff, this should also show you how to connect to other servers and channels outside of Redbrick.
==Helpful Configs==
To connect to any server, simply enter /connect <server_address>. You will probably be greeted with various messages and such from that server. To join a channel on that server, just type /join <channel_name>.
These are some tmux configs:
=== Navigation ===
nano .tmux.conf
Like Irssi, you can move between windows/buffers using Alt+<num>. You can also type /buffer <num> (similar to /win <num> in Irssi).
Remap prefix to Control + a
Unlike irssi you can do Alt+j then <num> to change to a number greater the 10 .
set -g prefix C-a
unbind C-b
bind C-a send-prefix
F5 and F6 move to the preceding and succeeding buffer, respectively.
Force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf
You can move buffers (chat windows) with /buffer move. In a channel, type:
Quick pane cycling
  unbind ^A
/buffer move <num>
  bind ^A select-pane -t :.+
(where <num> is any number you want). That channel is now accessible at Alt+<num>
=== Changing between servers ===
Weechat will generally assume that whatever channel you're in, that's also the server you're operating on. So you can chat away as you wish and issue general commands.
However, for some commands, you will need to let Weechat know what server you're on.
Hit Alt+1. This will bring you to your status window. Along the bottom you will see the time, number of channels, the server you're connect to, as well as other channel stuff.
Press Ctrl+x. If you're connected to multiple servers, the ''server'' section will change, telling you which server Weechat is connect to. So now you can issue commands to that server (such as /nick) without affecting other servers.
For example, I am currently connected to irc.redbrick.dcu.ie and to irc.starchat.net. If I hit Ctrl-x I can switch to StarChat, and change my nickname there without it affecting Redbrick's IRC.
== Mobile ==
weechat has a mobile app you can get from the [https://play.google.com/store/apps/details?id=com.ubergeek42.WeechatAndroid google play store] or from the [https://github.com/ubergeek42/weechat-android github].
Before we set up the app we need to go too weechat on the terminal and type in:
  /relay add weechat 1337
then we need to set the password
  /set relay.network.password "your-secret-password"
now on the Phone launch the app and in settings
In connection settings
Relay host: localhost
Relay Port: 1337 (choose your own port)
Relay password: your-secret-password
Connect type: SSH tunnel
then in  SSH Tunnel settings
SSH host: redbrick.dcu.ie
  SSH username: your username
  SSH port: 22
if you have an ssh key add the route to the key on your phone in SSH Private key file and put the passphrase in the SSH password/key passphrase box, if you dont just put your password in there
== Special commands ==
=== Keybinds ===
Keybinds are handy, especially if you have over 10 channels open. I use Alt+<num> to get to channels, but clearly this only works from 1 up to 0 (on a keyboard). So for channels in higher numbers, you can ''bind'' keys: i.e. Alt+q gets me to channel 11; Alt+y gets me to channel 16.
  /key bind meta-q /buffer 11
"Key" and "bind" are self-explanatory. "Meta" is Weechat's word for Alt (so meta-q is the same as Alt+q). /buffer 11 is the command that's executed once meta-q (Alt-q) is typed.
You can build up these to meta-w, meta-e, meta-r for buffer 2, buffer 3, buffer 4, etc etc.
Of course, you can bind any key combo to any weechat command; it's not necessary to make them Alt+<num> commands.
'''Note:''' Watch out for caps lock if you're keybinding. If you bind Alt+y to a command, Alt+Y won't work (unless you bind that separately). If you find your binds aren't working, check your caps.
== Triggers ==
Triggers are the swiss army knife of weechat. They can replace a '''lot''' of scripts, and we're still finding things to turn into trigger
=== Turn any line with "nsfw" in it bright red ===
/trigger addreplace nsfw modifier weechat_print "${tg_notify} && ${tg_message_nocolor} =~ .*nsfw.*" "/(.*)/${tg_prefix}\t${color:red}!NSFW! ${tg_message}"
=== Make urls underlined and blue ===
/trigger addreplace url_color modifier "weechat_print" "${tg_tags} !~ irc_quit" ";[a-z]+://\S+;${color:32}${color:underline}${re:0}${color:-underline}${color:reset};" ""
===Strip items such as time from screen on smaller screens ===
/trigger addreplace resize_small_timestamp signal signal_sigwinch "${info:term_width} < 200" "" "/set weechat.look.buffer_time_format \"\""
===add items such as time from screen on bigger screens ===
  /trigger addreplace resize_big_timestamp signal signal_sigwinch "${info:term_width} >=200" "" "/set weechat.look.buffer_time_format %H:%M:%S "
=== turn off nicklist on smaller screens ===
/trigger addreplace resize_big signal signal_sigwinch "${info:term_width} >= 100" "" "/bar show nicklist"
/trigger addreplace resize_small signal signal_sigwinch "${info:term_width} < 100" "" "/bar hide nicklist"
=== turn off buffer list on small screens ===
/trigger addreplace resize_small_buffer signal signal_sigwinch "${info:term_width} < 100" "" "/bar hide buffers"
/trigger addreplace resize_big_buffer signal signal_sigwinch "${info:term_width} >= 100" "" "/bar show buffers"
Conditions can be used to customize weechat depending on certain variables
===Turn off nicklist on small windows===
/set weechat.bar.nicklist.conditions "${nicklist} && (${window.win_width} > 100 || ${buffer.full_name} == irc.bitlbee.&bitlbee)"
===Hide buffer list on small terminals===
/set weechat.bar.buffers.conditions "${info:term_width} > 100"
===Turn off status on nonactive windows ===
/set weechat.bar.status.conditions "${active}"
== Spell Checker ==
Weechat uses a handy aspell plugin to check your spelling. To enable it, either use iset or use
/set aspell.check.enabled on
Aspell has a few settings which you may find useful
/set aspell.check.real_time on
/set aspell.check.word_min_length 2
/set aspell.check.default_dict "en"
/set aspell.check.suggestions 3
Or alternatively if you use iset, search for aspell
The aspell plugin can also offer suggestions as of 0.4.0 and it can be added as an item to your status bar. The item should be added to weechat.bar.status.items. For instance:
/set weechat.bar.status.items "time |,buffer_number+:buffer_name+(buffer_modes)+ |,buffer_nicklist_count |,hotlist |,[aspell_suggest]

Revision as of 22:25, 14 October 2016