Добавлены конфиги tmux и zsh
This commit is contained in:
20
tmux/plugins/tmux-yank/LICENSE.md
Normal file
20
tmux/plugins/tmux-yank/LICENSE.md
Normal file
@@ -0,0 +1,20 @@
|
||||
Copyright (C) 2014, 2017 Bruno Sutic
|
||||
Copyright (C) 2017 Christian Höltje
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
288
tmux/plugins/tmux-yank/README.md
Normal file
288
tmux/plugins/tmux-yank/README.md
Normal file
@@ -0,0 +1,288 @@
|
||||
[](https://travis-ci.org/tmux-plugins/tmux-yank)
|
||||
[](https://github.com/tmux-plugins/tmux-yank/releases)
|
||||
[](https://github.com/tmux-plugins/tmux-yank/issues)
|
||||
|
||||
tmux-yank
|
||||
=========
|
||||
|
||||
Copy to the system clipboard in [`tmux`](https://tmux.github.io/).
|
||||
|
||||
Supports:
|
||||
|
||||
- Linux
|
||||
- macOS
|
||||
- Cygwin
|
||||
- Windows Subsystem for Linux (WSL)
|
||||
|
||||
Installing
|
||||
----------
|
||||
|
||||
### Via TPM (recommended)
|
||||
|
||||
The easiest way to install `tmux-yank` is via the [Tmux Plugin
|
||||
Manager](https://github.com/tmux-plugins/tpm).
|
||||
|
||||
1. Add plugin to the list of TPM plugins in `.tmux.conf`:
|
||||
|
||||
``` tmux
|
||||
set -g @plugin 'tmux-plugins/tmux-yank'
|
||||
```
|
||||
|
||||
2. Use <kbd>prefix</kbd>–<kbd>I</kbd> install `tmux-yank`. You should now
|
||||
be able to `tmux-yank` immediately.
|
||||
3. When you want to update `tmux-yank` use <kbd>prefix</kbd>–<kbd>U</kbd>.
|
||||
|
||||
### Manual Installation
|
||||
|
||||
1. Clone the repository
|
||||
|
||||
``` sh
|
||||
$ git clone https://github.com/tmux-plugins/tmux-yank ~/clone/path
|
||||
```
|
||||
|
||||
2. Add this line to the bottom of `.tmux.conf`
|
||||
|
||||
``` tmux
|
||||
run-shell ~/clone/path/yank.tmux
|
||||
```
|
||||
|
||||
3. Reload the `tmux` environment
|
||||
|
||||
``` sh
|
||||
# type this inside tmux
|
||||
$ tmux source-file ~/.tmux.conf
|
||||
```
|
||||
|
||||
You should now be able to use `tmux-yank` immediately.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
In order for `tmux-yank` to work, there must be a program that store data in
|
||||
the system clipboard.
|
||||
|
||||
### macOS
|
||||
|
||||
- [`reattach-to-user-namespace`](https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard)
|
||||
|
||||
**Note**: Some versions of macOS (aka OS X) have been reported to work
|
||||
without `reattach-to-user-namespace`. It doesn't hurt to have it installed.
|
||||
|
||||
- OS X 10.8: Mountain Lion – *required*
|
||||
- OS X 10.9: Mavericks – *required*
|
||||
- OS X 10.10: Yosemite – *not required*
|
||||
- OS X 10.11: El Capitan – *not required*
|
||||
- macOS 10.12: Sierra – *required*
|
||||
|
||||
The easiest way to use `reattach-to-user-namespace` with `tmux` is use to
|
||||
use the [`tmux-sensible`](https://github.com/tmux-plugins/tmux-sensible)
|
||||
plugin.
|
||||
|
||||
To use it manually, use:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
set-option -g default-command "reattach-to-user-namespace -l $SHELL"
|
||||
```
|
||||
|
||||
If you have `tmux` 1.5 or newer and are using
|
||||
[iTerm2](https://www.iterm2.com/) version 3 or newer then the <kbd>y</kbd>
|
||||
in `copy-mode` and mouse selection will work without `tmux-yank`.
|
||||
|
||||
To enable this:
|
||||
|
||||
1. Go into iTerm2's preferences.
|
||||
2. Go to the "General" tab.
|
||||
3. Check "Applications in terminal may access clipboard"
|
||||
4. In `tmux`, ensure `set-clipboard` is turned on:
|
||||
|
||||
``` sh
|
||||
$ tmux show-options -g -s set-clipboard
|
||||
set-clipboard on
|
||||
```
|
||||
|
||||
#### [HomeBrew](https://brew.sh/) (recommended)
|
||||
|
||||
``` sh
|
||||
$ brew install reattach-to-user-namespace
|
||||
```
|
||||
|
||||
#### MacPorts
|
||||
|
||||
``` sh
|
||||
$ sudo port install tmux-pasteboard
|
||||
```
|
||||
|
||||
### Linux
|
||||
|
||||
- `xsel` (recommended) or `xclip` (for X).
|
||||
- `wl-copy` from [wl-clipboard](https://github.com/bugaevc/wl-clipboard) (for Wayland)
|
||||
|
||||
If you have `tmux` 1.5 or newer and are using `xterm`, the <kbd>y</kbd> in
|
||||
`copy-mode` and mouse selection will work without `tmux-yank`. See the
|
||||
`tmux(1)` man page entry for the `set-clipboard` option.
|
||||
|
||||
#### Debian & Ubuntu
|
||||
|
||||
``` sh
|
||||
$ sudo apt-get install xsel # or xclip
|
||||
```
|
||||
|
||||
#### RedHat & CentOS
|
||||
|
||||
``` sh
|
||||
$ sudo yum install xsel # or xclip
|
||||
```
|
||||
|
||||
### Cygwin
|
||||
|
||||
- (*optional*) `putclip` which is part of the `cygutils-extra` package.
|
||||
|
||||
### Windows Subsystem for Linux (WSL)
|
||||
|
||||
- `clip.exe` is shipped with Windows Subsystem for Linux.
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
### Key bindings
|
||||
|
||||
- Normal Mode
|
||||
- <kbd>prefix</kbd>–<kbd>y</kbd> — copies text from the command line
|
||||
to the clipboard.
|
||||
|
||||
Works with all popular shells/repls. Tested with:
|
||||
|
||||
- shells: `bash`, `zsh` (with `bindkey -e`), `tcsh`
|
||||
- repls: `irb`, `pry`, `node`, `psql`, `python`, `php -a`,
|
||||
`coffee`
|
||||
- remote shells: `ssh`, [mosh](http://mosh.mit.edu/)
|
||||
- vim/neovim command line (requires
|
||||
[vim-husk](https://github.com/bruno-/vim-husk) or
|
||||
[vim-rsi](https://github.com/tpope/vim-rsi) plugin)
|
||||
|
||||
- <kbd>prefix</kbd>–<kbd>Y</kbd> — copy the current pane's current
|
||||
working directory to the clipboard.
|
||||
|
||||
- Copy Mode
|
||||
- <kbd>y</kbd> — copy selection to system clipboard.
|
||||
- <kbd>Y</kbd> (shift-y) — "put" selection. Equivalent to copying a
|
||||
selection, and pasting it to the command line.
|
||||
|
||||
|
||||
### Default and Preferred Clipboard Programs
|
||||
|
||||
tmux-yank does its best to detect a reasonable choice for a clipboard
|
||||
program on your OS.
|
||||
|
||||
If tmux-yank can't detect a known clipboard program then it uses the
|
||||
`@custom_copy_command` tmux option as your clipboard program if set.
|
||||
|
||||
If you need to always override tmux-yank's choice for a clipboard program,
|
||||
then you can set `@override_copy_command` to force tmux-yank to use whatever
|
||||
you want.
|
||||
|
||||
Note that both programs _must_ accept `STDIN` for the text to be copied.
|
||||
|
||||
An example of setting `@override_copy_command`:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @custom_copy_command 'my-clipboard-copy --some-arg'
|
||||
# or
|
||||
set -g @override_copy_command 'my-clipboard-copy --some-arg'
|
||||
```
|
||||
|
||||
### Linux Clipboards
|
||||
|
||||
Linux has several cut-and-paste clipboards: `primary`, `secondary`, and
|
||||
`clipboard` (default in tmux-yank is `clipboard`).
|
||||
|
||||
You can change this by setting `@yank_selection`:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @yank_selection 'primary' # or 'secondary' or 'clipboard'
|
||||
```
|
||||
|
||||
With mouse support turned on (see below) the default clipboard for mouse
|
||||
selections is `primary`.
|
||||
|
||||
You can change this by setting `@yank_selection_mouse`:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @yank_selection_mouse 'clipboard' # or 'primary' or 'secondary'
|
||||
```
|
||||
|
||||
### Controlling Yank Behavior
|
||||
|
||||
By default, `tmux-yank` will exit copy mode after yanking text. If you wish to
|
||||
remain in copy mode, you can set `@yank_action`:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @yank_action 'copy-pipe' # or 'copy-pipe-and-cancel' for the default
|
||||
```
|
||||
|
||||
### Mouse Support
|
||||
|
||||
`tmux-yank` has mouse support enabled by default. It will only work if `tmux`'s
|
||||
built-in mouse support is also enabled (with `mouse on` since `tmux` 2.1, or
|
||||
`mode-mouse on` in older versions).
|
||||
|
||||
To yank with the mouse, click and drag with the primary button to begin
|
||||
selection, and release to yank.
|
||||
|
||||
If you would prefer to disable this behavior, or provide your own bindings for
|
||||
the `MouseDragEnd1Pane` event, you can do so with:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @yank_with_mouse off # or 'on'
|
||||
```
|
||||
|
||||
If you want to remain in copy mode after making a mouse selection, set
|
||||
`@yank_action` as described above.
|
||||
|
||||
### vi mode support
|
||||
|
||||
If using `tmux` 2.3 or older *and* using vi keys then you'll have add the
|
||||
following configuration setting:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @shell_mode 'vi'
|
||||
```
|
||||
|
||||
This isn't needed with `tmux` 2.4 or newer.
|
||||
|
||||
### Screen-cast
|
||||
|
||||
[](https://vimeo.com/102039099)
|
||||
|
||||
**Note**: The screen-cast uses <kbd>Control</kbd>–<kbd>y</kbd> for
|
||||
"put selection". Use <kbd>Y</kbd> in `v2.0.0` and later.
|
||||
|
||||
### Other tmux plugins
|
||||
|
||||
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin
|
||||
for regular expression searches in tmux and fast match selection
|
||||
- [tmux-open](https://github.com/tmux-plugins/tmux-open) - a plugin for
|
||||
quickly opening highlighted file or a URL
|
||||
- [tmux-continuum](https://github.com/tmux-plugins/tmux-continuum) -
|
||||
automatic restoring and continuous saving of tmux environment.
|
||||
|
||||
### License
|
||||
|
||||
[MIT](LICENSE.md)
|
||||
111
tmux/plugins/tmux-yank/scripts/copy_line.sh
Executable file
111
tmux/plugins/tmux-yank/scripts/copy_line.sh
Executable file
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
HELPERS_DIR="$CURRENT_DIR"
|
||||
TMUX_COPY_MODE=""
|
||||
|
||||
REMOTE_SHELL_WAIT_TIME="0.4"
|
||||
|
||||
# shellcheck source=scripts/helpers.sh
|
||||
source "${HELPERS_DIR}/helpers.sh"
|
||||
|
||||
# sets a TMUX_COPY_MODE that is used as a global variable
|
||||
get_tmux_copy_mode() {
|
||||
TMUX_COPY_MODE="$(tmux show-option -gwv mode-keys)"
|
||||
}
|
||||
|
||||
# The command when on ssh with latency. To make it work in this case too,
|
||||
# sleep is added.
|
||||
add_sleep_for_remote_shells() {
|
||||
local pane_command
|
||||
pane_command="$(tmux display-message -p '#{pane_current_command}')"
|
||||
if [[ $pane_command =~ (ssh|mosh) ]]; then
|
||||
sleep "$REMOTE_SHELL_WAIT_TIME"
|
||||
fi
|
||||
}
|
||||
|
||||
go_to_the_beginning_of_current_line() {
|
||||
if [ "$(shell_mode)" == "emacs" ]; then
|
||||
tmux send-key 'C-a'
|
||||
else
|
||||
tmux send-key 'Escape' '0'
|
||||
fi
|
||||
}
|
||||
|
||||
enter_tmux_copy_mode() {
|
||||
tmux copy-mode
|
||||
}
|
||||
|
||||
start_tmux_selection() {
|
||||
if tmux_is_at_least 2.4; then
|
||||
tmux send -X begin-selection
|
||||
elif [ "$TMUX_COPY_MODE" == "vi" ]; then
|
||||
# vi copy mode
|
||||
tmux send-key 'Space'
|
||||
else
|
||||
# emacs copy mode
|
||||
tmux send-key 'C-Space'
|
||||
fi
|
||||
}
|
||||
|
||||
# works when command spans accross multiple lines
|
||||
end_of_line_in_copy_mode() {
|
||||
if tmux_is_at_least 2.4; then
|
||||
tmux send -X -N 150 'cursor-down' # 'down' key. 'vi' mode is faster so we're
|
||||
# jumping more lines than emacs.
|
||||
tmux send -X 'end-of-line' # End of line (just in case we are already at the last line).
|
||||
tmux send -X 'previous-word' # Beginning of the previous word.
|
||||
tmux send -X 'next-word-end' # End of next word.
|
||||
elif [ "$TMUX_COPY_MODE" == "vi" ]; then
|
||||
# vi copy mode
|
||||
# This sequence of keys consistently selects multiple lines
|
||||
tmux send-key '150' # Go to the bottom of scrollback buffer by using
|
||||
tmux send-key 'j' # 'down' key. 'vi' mode is faster so we're
|
||||
# jumping more lines than emacs.
|
||||
tmux send-key '$' # End of line (just in case we are already at the last line).
|
||||
tmux send-key 'b' # Beginning of the previous word.
|
||||
tmux send-key 'e' # End of next word.
|
||||
else
|
||||
# emacs copy mode
|
||||
for ((c = 1; c <= '30'; c++)); do # go to the bottom of scrollback buffer
|
||||
tmux send-key 'C-n'
|
||||
done
|
||||
tmux send-key 'C-e'
|
||||
tmux send-key 'M-b'
|
||||
tmux send-key 'M-f'
|
||||
fi
|
||||
}
|
||||
|
||||
yank_to_clipboard() {
|
||||
if tmux_is_at_least 2.4; then
|
||||
# shellcheck disable=SC2119
|
||||
tmux send -X copy-pipe-and-cancel "$(clipboard_copy_command)"
|
||||
else
|
||||
tmux send-key "$(yank_wo_newline_key)"
|
||||
fi
|
||||
}
|
||||
|
||||
go_to_the_end_of_current_line() {
|
||||
if [ "$(shell_mode)" == "emacs" ]; then
|
||||
tmux send-keys 'C-e'
|
||||
else
|
||||
tmux send-keys '$' 'a'
|
||||
fi
|
||||
}
|
||||
|
||||
yank_current_line() {
|
||||
go_to_the_beginning_of_current_line
|
||||
add_sleep_for_remote_shells
|
||||
enter_tmux_copy_mode
|
||||
start_tmux_selection
|
||||
end_of_line_in_copy_mode
|
||||
yank_to_clipboard
|
||||
go_to_the_end_of_current_line
|
||||
display_message 'Line copied to clipboard!'
|
||||
}
|
||||
|
||||
main() {
|
||||
get_tmux_copy_mode
|
||||
yank_current_line
|
||||
}
|
||||
main
|
||||
25
tmux/plugins/tmux-yank/scripts/copy_pane_pwd.sh
Executable file
25
tmux/plugins/tmux-yank/scripts/copy_pane_pwd.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
HELPERS_DIR="$CURRENT_DIR"
|
||||
|
||||
# shellcheck source=scripts/helpers.sh
|
||||
source "${HELPERS_DIR}/helpers.sh"
|
||||
|
||||
pane_current_path() {
|
||||
tmux display -p -F "#{pane_current_path}"
|
||||
}
|
||||
|
||||
display_notice() {
|
||||
display_message 'PWD copied to clipboard!'
|
||||
}
|
||||
|
||||
main() {
|
||||
local copy_command
|
||||
# shellcheck disable=SC2119
|
||||
copy_command="$(clipboard_copy_command)"
|
||||
# $copy_command below should not be quoted
|
||||
pane_current_path | tr -d '\n' | $copy_command
|
||||
display_notice
|
||||
}
|
||||
main
|
||||
205
tmux/plugins/tmux-yank/scripts/helpers.sh
Normal file
205
tmux/plugins/tmux-yank/scripts/helpers.sh
Normal file
@@ -0,0 +1,205 @@
|
||||
#!bash
|
||||
# shellcheck disable=SC2239
|
||||
|
||||
yank_line="y"
|
||||
yank_line_option="@yank_line"
|
||||
|
||||
yank_pane_pwd="Y"
|
||||
yank_pane_pwd_option="@yank_pane_pwd"
|
||||
|
||||
yank_default="y"
|
||||
yank_option="@copy_mode_yank"
|
||||
|
||||
put_default="Y"
|
||||
put_option="@copy_mode_put"
|
||||
|
||||
yank_put_default="M-y"
|
||||
yank_put_option="@copy_mode_yank_put"
|
||||
|
||||
yank_wo_newline_default="!"
|
||||
yank_wo_newline_option="@copy_mode_yank_wo_newline"
|
||||
|
||||
yank_selection_default="clipboard"
|
||||
yank_selection_option="@yank_selection"
|
||||
|
||||
yank_selection_mouse_default="primary"
|
||||
yank_selection_mouse_option="@yank_selection_mouse"
|
||||
|
||||
yank_with_mouse_default="on"
|
||||
yank_with_mouse_option="@yank_with_mouse"
|
||||
|
||||
yank_action_default="copy-pipe-and-cancel"
|
||||
yank_action_option="@yank_action"
|
||||
|
||||
shell_mode_default="emacs"
|
||||
shell_mode_option="@shell_mode"
|
||||
|
||||
custom_copy_command_default=""
|
||||
custom_copy_command_option="@custom_copy_command"
|
||||
|
||||
override_copy_command_default=""
|
||||
override_copy_command_option="@override_copy_command"
|
||||
|
||||
# helper functions
|
||||
get_tmux_option() {
|
||||
local option="$1"
|
||||
local default_value="$2"
|
||||
local option_value
|
||||
option_value=$(tmux show-option -gqv "$option")
|
||||
if [ -z "$option_value" ]; then
|
||||
echo "$default_value"
|
||||
else
|
||||
echo "$option_value"
|
||||
fi
|
||||
}
|
||||
|
||||
yank_line_key() {
|
||||
get_tmux_option "$yank_line_option" "$yank_line"
|
||||
}
|
||||
|
||||
yank_pane_pwd_key() {
|
||||
get_tmux_option "$yank_pane_pwd_option" "$yank_pane_pwd"
|
||||
}
|
||||
|
||||
yank_key() {
|
||||
get_tmux_option "$yank_option" "$yank_default"
|
||||
}
|
||||
|
||||
put_key() {
|
||||
get_tmux_option "$put_option" "$put_default"
|
||||
}
|
||||
|
||||
yank_put_key() {
|
||||
get_tmux_option "$yank_put_option" "$yank_put_default"
|
||||
}
|
||||
|
||||
yank_wo_newline_key() {
|
||||
get_tmux_option "$yank_wo_newline_option" "$yank_wo_newline_default"
|
||||
}
|
||||
|
||||
yank_selection() {
|
||||
get_tmux_option "$yank_selection_option" "$yank_selection_default"
|
||||
}
|
||||
|
||||
yank_selection_mouse() {
|
||||
get_tmux_option "$yank_selection_mouse_option" "$yank_selection_mouse_default"
|
||||
}
|
||||
|
||||
yank_with_mouse() {
|
||||
get_tmux_option "$yank_with_mouse_option" "$yank_with_mouse_default"
|
||||
}
|
||||
|
||||
yank_action() {
|
||||
get_tmux_option "$yank_action_option" "$yank_action_default"
|
||||
}
|
||||
|
||||
shell_mode() {
|
||||
get_tmux_option "$shell_mode_option" "$shell_mode_default"
|
||||
}
|
||||
|
||||
custom_copy_command() {
|
||||
get_tmux_option "$custom_copy_command_option" "$custom_copy_command_default"
|
||||
}
|
||||
|
||||
override_copy_command() {
|
||||
get_tmux_option "$override_copy_command_option" "$override_copy_command_default"
|
||||
}
|
||||
# Ensures a message is displayed for 5 seconds in tmux prompt.
|
||||
# Does not override the 'display-time' tmux option.
|
||||
display_message() {
|
||||
local message="$1"
|
||||
|
||||
# display_duration defaults to 5 seconds, if not passed as an argument
|
||||
if [ "$#" -eq 2 ]; then
|
||||
local display_duration="$2"
|
||||
else
|
||||
local display_duration="5000"
|
||||
fi
|
||||
|
||||
# saves user-set 'display-time' option
|
||||
local saved_display_time
|
||||
saved_display_time=$(get_tmux_option "display-time" "750")
|
||||
|
||||
# sets message display time to 5 seconds
|
||||
tmux set-option -gq display-time "$display_duration"
|
||||
|
||||
# displays message
|
||||
tmux display-message "$message"
|
||||
|
||||
# restores original 'display-time' value
|
||||
tmux set-option -gq display-time "$saved_display_time"
|
||||
}
|
||||
|
||||
command_exists() {
|
||||
local command="$1"
|
||||
type "$command" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
clipboard_copy_command() {
|
||||
local mouse="${1:-false}"
|
||||
# installing reattach-to-user-namespace is recommended on OS X
|
||||
if [ -n "$(override_copy_command)" ]; then
|
||||
override_copy_command
|
||||
elif command_exists "pbcopy"; then
|
||||
if command_exists "reattach-to-user-namespace"; then
|
||||
echo "reattach-to-user-namespace pbcopy"
|
||||
else
|
||||
echo "pbcopy"
|
||||
fi
|
||||
elif command_exists "clip.exe"; then # WSL clipboard command
|
||||
echo "cat | clip.exe"
|
||||
elif command_exists "wl-copy"; then # wl-clipboard: Wayland clipboard utilities
|
||||
echo "wl-copy"
|
||||
elif command_exists "xsel"; then
|
||||
local xsel_selection
|
||||
if [[ $mouse == "true" ]]; then
|
||||
xsel_selection="$(yank_selection_mouse)"
|
||||
else
|
||||
xsel_selection="$(yank_selection)"
|
||||
fi
|
||||
echo "xsel -i --$xsel_selection"
|
||||
elif command_exists "xclip"; then
|
||||
local xclip_selection
|
||||
if [[ $mouse == "true" ]]; then
|
||||
xclip_selection="$(yank_selection_mouse)"
|
||||
else
|
||||
xclip_selection="$(yank_selection)"
|
||||
fi
|
||||
echo "xclip -selection $xclip_selection"
|
||||
elif command_exists "putclip"; then # cygwin clipboard command
|
||||
echo "putclip"
|
||||
elif [ -n "$(custom_copy_command)" ]; then
|
||||
custom_copy_command
|
||||
fi
|
||||
}
|
||||
|
||||
# Cache the TMUX version for speed.
|
||||
tmux_version="$(tmux -V | cut -d ' ' -f 2)"
|
||||
|
||||
tmux_is_at_least() {
|
||||
if [[ $tmux_version == "$1" ]] || [[ $tmux_version == master ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local i
|
||||
local -a current_version wanted_version
|
||||
IFS='.' read -ra current_version <<<"$tmux_version"
|
||||
IFS='.' read -ra wanted_version <<<"$1"
|
||||
|
||||
# fill empty fields in current_version with zeros
|
||||
for ((i = ${#current_version[@]}; i < ${#wanted_version[@]}; i++)); do
|
||||
current_version[i]=0
|
||||
done
|
||||
|
||||
# fill empty fields in wanted_version with zeros
|
||||
for ((i = ${#wanted_version[@]}; i < ${#current_version[@]}; i++)); do
|
||||
wanted_version[i]=0
|
||||
done
|
||||
|
||||
for ((i = 0; i < ${#current_version[@]}; i++)); do
|
||||
if ((10#${current_version[i]} < 10#${wanted_version[i]})); then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
92
tmux/plugins/tmux-yank/yank.tmux
Executable file
92
tmux/plugins/tmux-yank/yank.tmux
Executable file
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRIPTS_DIR="${CURRENT_DIR}/scripts"
|
||||
HELPERS_DIR="${CURRENT_DIR}/scripts"
|
||||
|
||||
# shellcheck source=scripts/helpers.sh
|
||||
source "${HELPERS_DIR}/helpers.sh"
|
||||
|
||||
clipboard_copy_without_newline_command() {
|
||||
local copy_command="$1"
|
||||
printf "tr -d '\\n' | %s" "$copy_command"
|
||||
}
|
||||
|
||||
set_error_bindings() {
|
||||
local key_bindings key
|
||||
key_bindings="$(yank_key) $(put_key) $(yank_put_key)"
|
||||
for key in $key_bindings; do
|
||||
if tmux_is_at_least 2.4; then
|
||||
tmux bind-key -T copy-mode-vi "$key" send-keys -X copy-pipe-and-cancel "tmux display-message 'Error! tmux-yank dependencies not installed!'"
|
||||
tmux bind-key -T copy-mode "$key" send-keys -X copy-pipe-and-cancel "tmux display-message 'Error! tmux-yank dependencies not installed!'"
|
||||
else
|
||||
tmux bind-key -t vi-copy "$key" copy-pipe "tmux display-message 'Error! tmux-yank dependencies not installed!'"
|
||||
tmux bind-key -t emacs-copy "$key" copy-pipe "tmux display-message 'Error! tmux-yank dependencies not installed!'"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
error_handling_if_command_not_present() {
|
||||
local copy_command="$1"
|
||||
if [ -z "$copy_command" ]; then
|
||||
set_error_bindings
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# `yank_without_newline` binding isn't intended to be used by the user. It is
|
||||
# a helper for `copy_line` command.
|
||||
set_copy_mode_bindings() {
|
||||
local copy_command="$1"
|
||||
local copy_wo_newline_command
|
||||
copy_wo_newline_command="$(clipboard_copy_without_newline_command "$copy_command")"
|
||||
local copy_command_mouse
|
||||
copy_command_mouse="$(clipboard_copy_command "true")"
|
||||
if tmux_is_at_least 2.4; then
|
||||
tmux bind-key -T copy-mode-vi "$(yank_key)" send-keys -X "$(yank_action)" "$copy_command"
|
||||
tmux bind-key -T copy-mode-vi "$(put_key)" send-keys -X copy-pipe-and-cancel "tmux paste-buffer"
|
||||
tmux bind-key -T copy-mode-vi "$(yank_put_key)" send-keys -X copy-pipe-and-cancel "$copy_command; tmux paste-buffer"
|
||||
tmux bind-key -T copy-mode-vi "$(yank_wo_newline_key)" send-keys -X "$(yank_action)" "$copy_wo_newline_command"
|
||||
if [[ "$(yank_with_mouse)" == "on" ]]; then
|
||||
tmux bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X "$(yank_action)" "$copy_command_mouse"
|
||||
fi
|
||||
|
||||
tmux bind-key -T copy-mode "$(yank_key)" send-keys -X "$(yank_action)" "$copy_command"
|
||||
tmux bind-key -T copy-mode "$(put_key)" send-keys -X copy-pipe-and-cancel "tmux paste-buffer"
|
||||
tmux bind-key -T copy-mode "$(yank_put_key)" send-keys -X copy-pipe-and-cancel "$copy_command; tmux paste-buffer"
|
||||
tmux bind-key -T copy-mode "$(yank_wo_newline_key)" send-keys -X "$(yank_action)" "$copy_wo_newline_command"
|
||||
if [[ "$(yank_with_mouse)" == "on" ]]; then
|
||||
tmux bind-key -T copy-mode MouseDragEnd1Pane send-keys -X "$(yank_action)" "$copy_command_mouse"
|
||||
fi
|
||||
else
|
||||
tmux bind-key -t vi-copy "$(yank_key)" copy-pipe "$copy_command"
|
||||
tmux bind-key -t vi-copy "$(put_key)" copy-pipe "tmux paste-buffer"
|
||||
tmux bind-key -t vi-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
|
||||
tmux bind-key -t vi-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
|
||||
if [[ "$(yank_with_mouse)" == "on" ]]; then
|
||||
tmux bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "$copy_command_mouse"
|
||||
fi
|
||||
|
||||
tmux bind-key -t emacs-copy "$(yank_key)" copy-pipe "$copy_command"
|
||||
tmux bind-key -t emacs-copy "$(put_key)" copy-pipe "tmux paste-buffer"
|
||||
tmux bind-key -t emacs-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
|
||||
tmux bind-key -t emacs-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
|
||||
if [[ "$(yank_with_mouse)" == "on" ]]; then
|
||||
tmux bind-key -t emacs-copy MouseDragEnd1Pane copy-pipe "$copy_command_mouse"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
set_normal_bindings() {
|
||||
tmux bind-key "$(yank_line_key)" run-shell -b "$SCRIPTS_DIR/copy_line.sh"
|
||||
tmux bind-key "$(yank_pane_pwd_key)" run-shell -b "$SCRIPTS_DIR/copy_pane_pwd.sh"
|
||||
}
|
||||
|
||||
main() {
|
||||
local copy_command
|
||||
copy_command="$(clipboard_copy_command)"
|
||||
error_handling_if_command_not_present "$copy_command"
|
||||
set_copy_mode_bindings "$copy_command"
|
||||
set_normal_bindings
|
||||
}
|
||||
main
|
||||
Reference in New Issue
Block a user