TheBlackzone Logo

Posts tagged with "linux"

TMUX and the system clipboard

When I started using TMUX years ago, I frequently updated it from its Github repository, always eager to learn about the latest features of each new version. But, having become the lazy slacker I am nowadays and also having become quite comfortable with my current tmux setup, I haven’t done so for ages.

Today however, I finally did an upgrade to the latest git version and took the opportunity to fix my TMUX configuration regarding a (mildly annoying) shortcoming of not being able to copy mouse selection directly to the system clipboard.

I normaly use the keyboard to copy and paste from or to tmux (CTRL-B being my tmux prefix key):

This behaviour is achieved by these configuraton options:

# Use vi keys for navigation
set-window-option -g mode-keys vi
# begin selection
bind -T copy-mode-vi v send-keys -X begin-selection
# copy to global clipboard
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -i -f -selection prima
# paste from global clipboard
bind p run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"

One thing that had never worked for me however was, to copy an area of text from tmux directly to the system clipboard by using the mouse.

To be honest, this had not bothered me enough to put a lot of energy in finding a solution for it, because in my terminal of choice (xfce4-terminal) it is easily possible to just hold down the shift key when doing mouse selections and then shift-right-click to use the terminal’s native copy-paste functionality.

Nevertheless, with the new version of TMUX I finally found an easy solution by adding these settings to my configuration file:

set-option -g mouse on
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard >/dev/null"

It’s the same command as for copying by keyboard, except the keycode being ‘‘MouseDragEnd1Pane’’.

I actually don’t know for how long this solution has been around, but I’m glad I finally learned about it. My TMUX experience now seems to be complete :-)

And, since everybody seems to enjoy looking at other’s configuration settings, here’s my complete ‘'.tmux.conf’' file:

# TERM
set -g default-terminal "screen-256color"

# Statusbar
set-option -g status on
set-option -g status-bg colour235
set-option -g status-fg colour244
set-option -g status-interval 2

set -g status-right '#[fg=green]#[bg=green]#[fg=black]  #(hostname)  %Y-%m-%d %H:%M #[fg=colour17]#[bg=colour17]#[fg=colour39] #(whoami) #[default]'

# Highlight active window
set-window-option -g window-status-current-style fg=white
set-window-option -g window-status-current-style bg=colour235

set-option -g pane-border-style bg=colour235
set-option -g pane-border-style fg=yellow
set-option -g pane-active-border-style fg=colour244

# key bindings
set-window-option -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."
bind v split-window -h
bind b split-window -v

bind-key C-b last-window
bind C-v paste-buffer

# begin selection
bind -T copy-mode-vi v send-keys -X begin-selection
# copy to global clipboard
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard >/dev/null"
# paste from global clipboard
bind p run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"

# options
set-window-option -g clock-mode-colour colour33
set-window-option -g aggressive-resize on

# faster key repeat
set -s escape-time 0

# Activity monitoring
set-window-option -g monitor-activity on
set -g visual-activity on

# mouse support
set-option -g mouse on
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard >/dev/null"

# scrollback
set -g history-limit 128000

# tab numbering starts at 1
set -g base-index 1

# F1 bound to quickly create a multi pane layout for my development work
bind F1 split-window -v -l 8 \; split-window -h -p 50 \; split-window -h -p 50 \; select-pane -t 0 \; split-window -h -p 50

You may have noticed those “special characters” in the status bar setup. These are actually some modified unicode characters coming from the font I use for my terminal, “LiterationMono Nerd Font”, which can be found here.

Adjusting the Linux (Xfce) Volume Control

Like many others I like to listen to music while sitting at my computer. When I am coding or doing other work I need to concentrate on, I do so at a very low volume level, just enough that the music is audible without distracting me. For this reason I use the volume controls of my keyboard quite often to adjust the level according to the current situation.

Normally the volume keys increase or decrease the volume level by 5%, which in most cases is a reasonable setting. But combined with my DELL AC511 sound bar, a step of 5% sometimes goes from “mute” directly to “too loud”, forcing me to use the mouse to make adjustments with the volume slider control.

I was looking for some way to have a more fine-grained control over the amount of volume change when using the keyboard and came up with two solutions to this “problem”.

The first one is specific to the Xfce desktop environment with the “xfce4-pulseaudio-plugin”, which is what I am using, the second one is more generic and works in Xfce as well as in other Linux desktop environments.

Let’s get started…

Read on...

Mounting Truecrypt Volumes in Linux

Today I learned (well not actually today, but a few days ago): You can easily mount Truecrypt containers with cryptsetup in Linux. So let's put a quick reminder here, just in case I need this again...

Set up a loop device

sudo losetup /dev/loop0 /path/to/truecrypt/container

Then open it

sudo cryptsetup open --type tcrypt /dev/loop0 tccontainer

And finally mount the container

sudo mount /dev/mapper/tccontainer /mnt

To close it again, go the other way round...

umount /mnt
sudo cryptsetup close tccontainer
sudo losetup -d /dev/loop0

Done.

You can also mount hidden Truecrypt containers by specifying the type tcrypt-hidden in the cryptsetup open... step.

QMMP Linux Media Player

There are plenty of media players for the Linux platform out there, but the one I like most is the QT-based Multimedia Player QMMP. Maybe one of the reasons for this is, that it feels very much like the original [Winamp Player](http://www.winamp.com/), which I had adopted as my media player of choice back in October 1998 when version 2.03 came out.

Read on...