diff options
Diffstat (limited to 'tmux')
-rwxr-xr-x | tmux/.bin/tmux-clipboard | 74 | ||||
-rw-r--r-- | tmux/.config/sh/rc.d/tmux | 5 | ||||
-rw-r--r-- | tmux/.config/tmux/tmux.conf | 47 |
3 files changed, 126 insertions, 0 deletions
diff --git a/tmux/.bin/tmux-clipboard b/tmux/.bin/tmux-clipboard new file mode 100755 index 0000000..dae796b --- /dev/null +++ b/tmux/.bin/tmux-clipboard @@ -0,0 +1,74 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.020; +use feature 'signatures'; +no warnings 'experimental::signatures'; + +use Config; + +use constant { + COPY_CMD => ($Config{osname} eq 'linux' ? 'xclip -i' : 'pbcopy'), + PASTE_CMD => ($Config{osname} eq 'linux' ? 'xclip -o' : 'pbpaste'), +}; + +sub main($cmd, $selection) { + if ($cmd eq 'copy') { + tmux_copy($selection); + } + elsif ($cmd eq 'paste') { + tmux_paste($selection); + } + else { + die "usage: $0 [copy|paste]"; + } +} + +sub tmux_copy($selection='primary') { + set_clipboard_contents(get_tmux_buffer(), $selection); +} + +sub tmux_paste($selection='primary') { + write_to_tmux(get_clipboard_contents($selection)); +} + +sub set_clipboard_contents($contents, $selection) { + my $copy_cmd = COPY_CMD; + if ($Config{osname} eq 'linux') { + $copy_cmd .= " -selection $selection"; + } + + open my $clipboard, '|-', $copy_cmd + or die "can't set clipboard contents using `$copy_cmd`: $!"; + print $clipboard $contents; + close $clipboard; +} + +sub get_clipboard_contents($selection) { + my $paste_cmd = PASTE_CMD; + if ($Config{osname} eq 'linux') { + $paste_cmd .= " -selection $selection"; + } + + open my $clipboard, '-|', $paste_cmd + or die "can't get clipboard contents using `$paste_cmd`: $!"; + my $contents = do { local $/; <$clipboard> }; + close $clipboard; + $contents +} + +sub get_tmux_buffer { + scalar `tmux show-buffer` +} + +sub write_to_tmux($contents) { + my $tmux_cmd = "tmux load-buffer -b tmux-clipboard -"; + open my $tmux, '|-', $tmux_cmd + or die "can't set tmux buffer contents using `$tmux_cmd`: $!"; + print $tmux $contents; + close $tmux; + + system("tmux paste-buffer -b tmux-clipboard -dp"); +} + +main(@ARGV) diff --git a/tmux/.config/sh/rc.d/tmux b/tmux/.config/sh/rc.d/tmux new file mode 100644 index 0000000..520e98c --- /dev/null +++ b/tmux/.config/sh/rc.d/tmux @@ -0,0 +1,5 @@ +alias main='tmux new -As main' +alias chat='tmux new -As chat' +alias work='tmux new -As work' +alias docs='tmux new -As docs' +alias misc='tmux new -As misc' diff --git a/tmux/.config/tmux/tmux.conf b/tmux/.config/tmux/tmux.conf new file mode 100644 index 0000000..a1ea5ec --- /dev/null +++ b/tmux/.config/tmux/tmux.conf @@ -0,0 +1,47 @@ +# bells in any window get sent to the terminal +set -g bell-action any + +# lots of scrollback +set -g history-limit 4096 + +# use ^F rather than ^B for the prefix key +set -g prefix ^F + +# hide the statusbar by default +set -g status off + +# display window titles +set -g set-titles on + +# keep windows in order +set -g renumber-windows on + +# use vi keybindings +setw -g mode-keys vi +set -g status-keys vi + +# colors +setw -g mode-style bg=cyan,fg=black +set -g message-style bg=green,fg=black + +# fast escape +set -g escape-time 50 + +# keybindings +bind f send-prefix +bind ^F run 'tmux choose-tree -Nwf"##{==:##{session_name},#{session_name}}"' +bind ^N new-window +bind ^D detach-client +bind ^[ copy-mode +bind \{ copy-mode +bind Enter run 'tmux capture-pane -pJ | open-link' + +bind -T copy-mode-vi v send-keys -X begin-selection +bind -T copy-mode-vi ) send-keys -X start-of-line +bind -T copy-mode-vi _ send-keys -X back-to-indentation + +bind -T copy-mode-vi y run "tmux send-keys -X copy-selection-and-cancel; tmux run -b 'tmux-clipboard copy primary'" +bind -T copy-mode-vi ^C run "tmux send-keys -X copy-selection-and-cancel; tmux run -b 'tmux-clipboard copy clipboard'" +bind ^V run "tmux-clipboard paste clipboard" + +unbind ^B |