diff --git a/CONFIGURATION.md b/CONFIGURATION.md new file mode 100644 index 0000000..a164bbf --- /dev/null +++ b/CONFIGURATION.md @@ -0,0 +1,241 @@ +# Configuration + +If you want to customize how is shown your tmux-copyrat hints those all available +parameters to set your perfect profile. + +NOTE: for changes to take effect, you'll need to source again your `.tmux.conf` file. + +- [@copyrat-key](#thumbs-key) +- [@copyrat-alphabet](#thumbs-alphabet) +- [@copyrat-reverse](#thumbs-reverse) +- [@copyrat-unique](#thumbs-unique) +- [@copyrat-position](#thumbs-position) +- [@copyrat-regexp-N](#thumbs-regexp-N) +- [@copyrat-command](#thumbs-command) +- [@copyrat-upcase-command](#thumbs-upcase-command) +- [@copyrat-bg-color](#thumbs-bg-color) +- [@copyrat-fg-color](#thumbs-fg-color) +- [@copyrat-hint-bg-color](#thumbs-hint-bg-color) +- [@copyrat-hint-fg-color](#thumbs-hint-fg-color) +- [@copyrat-select-fg-color](#thumbs-select-fg-color) +- [@copyrat-select-bg-color](#thumbs-select-bg-color) +- [@copyrat-contrast](#thumbs-contrast) + +### @thumbs-key + +`default: space` + +Choose which key is used to enter in thumbs mode. + +For example: + +``` +set -g @thumbs-key F +``` + +### @thumbs-alphabet + +`default: qwerty` + +Choose which set of characters is used to build hints. Review all [available alphabets](#Alphabets) + +For example: + +``` +set -g @thumbs-alphabet dvorak-homerow +``` + +### @thumbs-reverse + +`default: disabled` + +Choose in which direction you want to assign hints. Useful to get shorter hints closer to the cursor. + +For example: + +``` +set -g @thumbs-reverse +``` + +### @thumbs-unique + +`default: disabled` + +Choose if you want to assign the same hint for the same text spans. + +For example: + +``` +set -g @thumbs-unique +``` + +### @thumbs-position + +`default: left` + +Choose where do you want to show the hint in the text spans. Options (left, right). + +For example: + +``` +set -g @thumbs-position right +``` + +### @thumbs-regexp-N + +Add extra patterns to match. This parameter can have multiple instances. + +For example: + +``` +set -g @thumbs-regexp-1 '[a-z]+@[a-z]+.com' # Match emails +set -g @thumbs-regexp-2 '[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:' # Match MAC addresses +``` + +### @thumbs-command + +`default: 'tmux set-buffer {}'` + +Choose which command execute when you press a hint. `tmux-thumbs` will replace `{}` with the picked hint. + +For example: + +``` +set -g @thumbs-command 'echo -n {} | pbcopy' +``` + +### @thumbs-upcase-command + +`default: 'tmux set-buffer {} && tmux paste-buffer'` + +Choose which command execute when you press a upcase hint. `tmux-thumbs` will replace `{}` with the picked hint. + +For example: + +``` +set -g @thumbs-upcase-command 'echo -n {} | pbcopy' +``` + +### @thumbs-bg-color + +`default: black` + +Sets the background color for spans + +For example: + +``` +set -g @thumbs-bg-color blue +``` + +### @thumbs-fg-color + +`default: green` + +Sets the foreground color for spans + +For example: + +``` +set -g @thumbs-fg-color green +``` + +### @thumbs-hint-bg-color + +`default: black` + +Sets the background color for hints + +For example: + +``` +set -g @thumbs-hint-bg-color blue +``` + +### @thumbs-hint-fg-color + +`default: yellow` + +Sets the foreground color for hints + +For example: + +``` +set -g @thumbs-hint-fg-color green +``` + +### @thumbs-select-fg-color + +`default: blue` + +Sets the foreground color for selection + +For example: + +``` +set -g @thumbs-select-fg-color red +``` + +### @thumbs-select-bg-color + +`default: black` + +Sets the background color for selection + +For example: + +``` +set -g @thumbs-select-bg-color red +``` + +### @thumbs-contrast + +`default: 0` + +Displays hint character in square brackets for extra visibility. + +For example: + +``` +set -g @thumbs-contrast 1 +``` + +#### Colors + +This is the list of available colors: + +- black +- red +- green +- yellow +- blue +- magenta +- cyan +- white +- default + +#### Alphabets + +This is the list of available alphabets: + +- `qwerty`: asdfqwerzxcvjklmiuopghtybn +- `qwerty-homerow`: asdfjklgh +- `qwerty-left-hand`: asdfqwerzcxv +- `qwerty-right-hand`: jkluiopmyhn +- `azerty`: qsdfazerwxcvjklmuiopghtybn +- `azerty-homerow`: qsdfjkmgh +- `azerty-left-hand`: qsdfazerwxcv +- `azerty-right-hand`: jklmuiophyn +- `qwertz`: asdfqweryxcvjkluiopmghtzbn +- `qwertz-homerow`: asdfghjkl +- `qwertz-left-hand`: asdfqweryxcv +- `qwertz-right-hand`: jkluiopmhzn +- `dvorak`: aoeuqjkxpyhtnsgcrlmwvzfidb +- `dvorak-homerow`: aoeuhtnsid +- `dvorak-left-hand`: aoeupqjkyix +- `dvorak-right-hand`: htnsgcrlmwvz +- `colemak`: arstqwfpzxcvneioluymdhgjbk +- `colemak-homerow`: arstneiodh +- `colemak-left-hand`: arstqwfpzxcv +- `colemak-right-hand`: neioluymjhk + diff --git a/Cargo.toml b/Cargo.toml index 69a8119..cbc9425 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,8 @@ name = "copyrat" version = "0.4.1" authors = ["graelo "] edition = "2021" -description = "This is tmux-copycat on Rust steroids." + +description = "A tmux plugin for copy-pasting within tmux panes." repository = "https://github.com/graelo/tmux-copyrat" keywords = ["rust", "tmux", "tmux-plugin", "tmux-copycat"] license = "MIT" diff --git a/INSTALLATION.md b/INSTALLATION.md new file mode 100644 index 0000000..81c1894 --- /dev/null +++ b/INSTALLATION.md @@ -0,0 +1,100 @@ +# Installation + +## A note on extending tmux functionality + +Extending [tmux] functionality is easy: it boils down to adding key-bindings +which call internal commands or external programs that you provide. + +The minimalistic way to add functionality is simply to add your key-bindings +directly inside `~/.tmux.conf`. I don't do this because it ends up being messy, +but it's still an option described below. + +In contrast, the most flexible way to extend is via plugins. You declare your +bindings in a plugin file often located in +`~/.tmux/plugins/your-plugin-dir/plugin-file.tmux`, and optionally provide your +external programs in the same folder or elsewhere. You then simply ask tmux to +_run_ your plugin file by adding `run-shell +~/.tmux/plugins/your-plugin-dir/plugin-file.tmux` inside your `tmux.conf`. Your +key-bindings will be registered on tmux initial start. + +[TPM], the tmux plugin manager, is an integrated way of doing the same. It adds +a level of indirection: when tmux first starts, it runs TPM, which asks tmux to +_run_ all the plugin files in `~/.tmux/plugins/**/` as executables. +When run, each plugin file registers their key-bindings with tmux. TPM also has +an installation mechanism for plugins. + + +## Minimalistic installation + +As described above, a valid option is to ignore the [`copyrat.tmux`] plugin +file simply add a few key bindings to tmux. You just have to create +key-bindings which launch the `tmux-copyrat` binary with its command line +options. Notice you probably need the absolute path to the binary. + +However, when creating your bindings, avoid using `run-shell` to run `tmux-copyrat` +because by design tmux launches processes without attaching them to a pty. +Take inspiration from [`copyrat.tmux`] for correct syntax. + + +## Standard installation (recommended) + +The easiest way to install is to copy the config file [`copyrat.tmux`] into `~/.tmux/plugins/tmux-copyrat/` and tell tmux to source it either via + +- sourcing it directly from your `~/.tmux.conf`: you simply add the line `source-file ~/.tmux/plugins/tmux-copyrat/copyrat.tmux` +- or, if you use [TPM], registering it with TPM in your `~/.tmux.conf`: you simply add the line + + +```tmux +set -g @tpm_plugins ' \ + tmux-plugins/tpm \ + tmux-plugins/tmux-copyrat \ <- line added + tmux-plugins/tmux-yank \ + ... +``` + + +second style of tmux integration is more declarative: you configure the tmux key bindings to pass none or very few command line arguments to `tmux-copyrat`, and ask `tmux-copyrat` to query back tmux for the rest of the configuration. + + + +## Tmux integration + +Clone the repo: + +``` +git clone https://github.com/graelo/tmux-copyrat ~/.tmux/plugins/tmux-copyrat +``` + +Compile it with [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html): + +``` +cd ~/.tmux/plugins/tmux-copyrat +cargo build --release +``` + +Source it in your `.tmux.conf`: + +``` +run-shell ~/.tmux/plugins/tmux-copyrat/copyrat.tmux +``` + +Reload TMUX conf by running: + +``` +tmux source-file ~/.tmux.conf +``` + +## Using Tmux Plugin Manager + +You can add this line to your list of [TPM](https://github.com/tmux-plugins/tpm) plugins in `.tmux.conf`: + +``` +set -g @plugin 'graelo/tmux-copyrat' +``` + +To be able to install the plugin just hit prefix + I. You should now be able to use +the plugin! + +[`copyrat.tmux`]: https://raw.githubusercontent.com/graelo/tmux-copyrat/main/copyrat.tmux +[tmux]: https://tmux.github.io +[TPM]: https://github.com/tmux-plugins/tpm diff --git a/README.md b/README.md index fcb8f99..bfea4fe 100644 --- a/README.md +++ b/README.md @@ -2,326 +2,113 @@ [![crate](https://img.shields.io/crates/v/tmux-copyrat.svg)](https://crates.io/crates/tmux-copyrat) [![documentation](https://docs.rs/tmux-copyrat/badge.svg)](https://docs.rs/tmux-copyrat) -[![minimum rustc 1.8](https://img.shields.io/badge/rustc-1.56+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) -[![minimum rustc 1.8](https://img.shields.io/badge/edition-2021-blue.svg)](https://doc.rust-lang.org/edition-guide/rust-2021/index.html) +[![minimum rustc 1.8](https://img.shields.io/badge/rustc-1.56+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) +[![edition 2021](https://img.shields.io/badge/edition-2021-blue.svg)](https://doc.rust-lang.org/edition-guide/rust-2021/index.html) +[![tmux 3.x](https://img.shields.io/badge/tmux-3.0+-blue.svg)](https://tmux.github.io) [![build status](https://github.com/graelo/tmux-copyrat/workflows/main/badge.svg)](https://github.com/graelo/tmux-copyrat/actions) +A tmux-plugin for copy-pasting spans of text from the [tmux] pane's history +into a clipboard. -A hommage to [tmux-copyrat](https://github.com/tmux-plugins/tmux-copycat), written in [Rust](https://www.rust-lang.org/) for copy pasting within [tmux](http://tmux.github.io). +**Use case**: you're in tmux and press the key binding to highlight, say dates. +This makes `tmux-copyrat` search within tmux's current pane history and +highlight all spans of text which correspond to a date. All spans are displayed +with a one or two key _hint_, which you can then press to copy-paste the span +into the tmux clipboard or the system clipboard. Check out the demo below. -## Usage +The name is a tribute to [tmux-copyrat], which I used for many years. -Press ( prefix + Space ) to highlist in you current tmux -visible pane all text that match specific pattern. Then press the highlighted -letter hint to yank the text in your tmux buffer. - -### Matched patterns - -- File paths -- File in diff -- Git SHAs -- IPFS CID's -- Colors in hex -- Numbers ( 4+ digits ) -- Hex numbers -- Markdown urls -- IP4 addresses -- Docker images -- kubernetes resources -- UUIDs - -These are the list of matched patterns that will be highlighted by default. If -you want to highlight a pattern that is not in this list you can add one or -more with `--regexp` parameter. ## Demo [![demo](https://asciinema.org/a/232775.png?ts=1)](https://asciinema.org/a/232775?autoplay=1) -## Tmux integration -Clone the repo: +## Usage -``` -git clone https://github.com/graelo/tmux-copyrat ~/.tmux/plugins/tmux-copyrat +Restart tmux after the plugin is installed and configured (see both +[INSTALLATION.md] and [CONFIGURATION.md] pages). Press one of the pre-defined +tmux key-bindings (see table below) in order to highlight spans of text +matching a specific pattern. To yank some text span in the tmux buffer, press +the corresponding _hint_, or press Esc to cancel and exit. + +If instead you want to yank the text span into the system clipboard, either +press the caps version of the key hint (for instance E instead of +e), or first toggle the destination buffer with the space +key and press the hint with no caps. + +You can also use the n and p (or Up and +Down) keys to move focus across the highlighted spans. Press +y to yank the focused span into the tmux buffer, or press +Y to yank it into the system clipboard. + +By default, span highlighting starts from the bottom of the terminal, but you +can reverse that behavior with the `--reverse` option (more on that in the +[Configuration.md] page). The `--focus wrap-around` option makes navigation +go back to the first span. + + +### Matched patterns and default key-bindings + +tmux-copyrat can match one or more pre-defined (named) patterns, but you can +add your own too. + +The default configuration provided in the [`copyrat.tmux`](copyrat.tmux) plugin +file provides the following key-bindings. Because they all start with +prefix + t, the table below only lists the keyboard key +that comes after. For instance, for URLs, the key is u, but you +should type prefix + t + u. + +| key binding | searches for | pattern name | +| --- | --- | --- | +| c | Hex color codes | `hexcolor` | +| d | Dates or datetimes | `datetime` | +| D | Docker/Podman IDs | `docker` | +| e | Emails | `email` | +| G | String of 4+ digits | `digits` | +| h | SHA-1/-2 short & long | `sha` | +| m | Markdown URLs `[..](matched-url)` | `markdown-url` | +| p | Abs. and rel. filepaths | `path` | +| P | Hex numbers and pointer addresses | `pointer-address` | +| | strings inside single quotes | `quoted-single` | +| | strings inside double quotes | `quoted-double` | +| | strings inside backticks | `quoted-tick` | +| q | strings inside single/double/backticks | | +| u | URLs | `url` | +| U | UUIDs | `uuid` | +| v | version numbers | `version` | +| 4 | IPv4 addresses | `4` | +| 6 | IPv6 addresses | `6` | +| space | All patterns | | + +If you want additional patterns, you can provide them via the +`--custom-pattern` command line option (short option: `-X`), see +[CONFIGURATION.md]. + + +## The `copyrat` companion executable + +The central binary of this crate is `tmux-copyrat`, however there is also the +`copyrat` executable. It simply provides the same functionality, without any +tmux dependency or integration. + +You can use `copyrat` to search a span of text that you provide to stdin. + +For instance here is a bunch of text, with dates and git hashes which you can +search with copyrat. + +```console +$ echo -n '* e006b06 - (12 days ago = 2021-03-04T12:23:34) e006b06 e006b06 swapper: Make quotes\n/usr/local/bin/git\n\nlorem\n/usr/local/bin\nlorem\n/usr/local/bin/git\n* e006b06 - (12 days ago = 2021-03-04T12:23:34) e006b06 e006b06 swapper: Make quotes' \ + | ./target/release/copyrat -r --unique-hint -s bold -X '(loca)' -x sha datetime ``` -Compile it with [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html): +You will see the following in your terminal -``` -cd ~/.tmux/plugins/tmux-copyrat -cargo build --release -``` +![[copyrat-output.png](images/copyrat-output.png)](images/copyrat-output.png) -Source it in your `.tmux.conf`: +You may have noticed that all identical spans share the same _hint_, this is +due to the `-unique-hint` option (`-u`). The hints are in bold text, due to the `--hint-style bold` option (`-s`). -``` -run-shell ~/.tmux/plugins/tmux-copyrat/copyrat.tmux -``` - -Reload TMUX conf by running: - -``` -tmux source-file ~/.tmux.conf -``` - -## Using Tmux Plugin Manager - -You can add this line to your list of [TPM](https://github.com/tmux-plugins/tpm) plugins in `.tmux.conf`: - -``` -set -g @plugin 'graelo/tmux-copyrat' -``` - -To be able to install the plugin just hit prefix + I. You should now be able to use -the plugin! - -## Configuration - -If you want to customize how is shown your tmux-copyrat hints those all available -parameters to set your perfect profile. - -NOTE: for changes to take effect, you'll need to source again your `.tmux.conf` file. - -- [@copyrat-key](#thumbs-key) -- [@copyrat-alphabet](#thumbs-alphabet) -- [@copyrat-reverse](#thumbs-reverse) -- [@copyrat-unique](#thumbs-unique) -- [@copyrat-position](#thumbs-position) -- [@copyrat-regexp-N](#thumbs-regexp-N) -- [@copyrat-command](#thumbs-command) -- [@copyrat-upcase-command](#thumbs-upcase-command) -- [@copyrat-bg-color](#thumbs-bg-color) -- [@copyrat-fg-color](#thumbs-fg-color) -- [@copyrat-hint-bg-color](#thumbs-hint-bg-color) -- [@copyrat-hint-fg-color](#thumbs-hint-fg-color) -- [@copyrat-select-fg-color](#thumbs-select-fg-color) -- [@copyrat-select-bg-color](#thumbs-select-bg-color) -- [@copyrat-contrast](#thumbs-contrast) - -### @thumbs-key - -`default: space` - -Choose which key is used to enter in thumbs mode. - -For example: - -``` -set -g @thumbs-key F -``` - -### @thumbs-alphabet - -`default: qwerty` - -Choose which set of characters is used to build hints. Review all [available alphabets](#Alphabets) - -For example: - -``` -set -g @thumbs-alphabet dvorak-homerow -``` - -### @thumbs-reverse - -`default: disabled` - -Choose in which direction you want to assign hints. Useful to get shorter hints closer to the cursor. - -For example: - -``` -set -g @thumbs-reverse -``` - -### @thumbs-unique - -`default: disabled` - -Choose if you want to assign the same hint for the same text spans. - -For example: - -``` -set -g @thumbs-unique -``` - -### @thumbs-position - -`default: left` - -Choose where do you want to show the hint in the text spans. Options (left, right). - -For example: - -``` -set -g @thumbs-position right -``` - -### @thumbs-regexp-N - -Add extra patterns to match. This parameter can have multiple instances. - -For example: - -``` -set -g @thumbs-regexp-1 '[a-z]+@[a-z]+.com' # Match emails -set -g @thumbs-regexp-2 '[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:' # Match MAC addresses -``` - -### @thumbs-command - -`default: 'tmux set-buffer {}'` - -Choose which command execute when you press a hint. `tmux-thumbs` will replace `{}` with the picked hint. - -For example: - -``` -set -g @thumbs-command 'echo -n {} | pbcopy' -``` - -### @thumbs-upcase-command - -`default: 'tmux set-buffer {} && tmux paste-buffer'` - -Choose which command execute when you press a upcase hint. `tmux-thumbs` will replace `{}` with the picked hint. - -For example: - -``` -set -g @thumbs-upcase-command 'echo -n {} | pbcopy' -``` - -### @thumbs-bg-color - -`default: black` - -Sets the background color for spans - -For example: - -``` -set -g @thumbs-bg-color blue -``` - -### @thumbs-fg-color - -`default: green` - -Sets the foreground color for spans - -For example: - -``` -set -g @thumbs-fg-color green -``` - -### @thumbs-hint-bg-color - -`default: black` - -Sets the background color for hints - -For example: - -``` -set -g @thumbs-hint-bg-color blue -``` - -### @thumbs-hint-fg-color - -`default: yellow` - -Sets the foreground color for hints - -For example: - -``` -set -g @thumbs-hint-fg-color green -``` - -### @thumbs-select-fg-color - -`default: blue` - -Sets the foreground color for selection - -For example: - -``` -set -g @thumbs-select-fg-color red -``` - -### @thumbs-select-bg-color - -`default: black` - -Sets the background color for selection - -For example: - -``` -set -g @thumbs-select-bg-color red -``` - -### @thumbs-contrast - -`default: 0` - -Displays hint character in square brackets for extra visibility. - -For example: - -``` -set -g @thumbs-contrast 1 -``` - -#### Colors - -This is the list of available colors: - -- black -- red -- green -- yellow -- blue -- magenta -- cyan -- white -- default - -#### Alphabets - -This is the list of available alphabets: - -- `qwerty`: asdfqwerzxcvjklmiuopghtybn -- `qwerty-homerow`: asdfjklgh -- `qwerty-left-hand`: asdfqwerzcxv -- `qwerty-right-hand`: jkluiopmyhn -- `azerty`: qsdfazerwxcvjklmuiopghtybn -- `azerty-homerow`: qsdfjkmgh -- `azerty-left-hand`: qsdfazerwxcv -- `azerty-right-hand`: jklmuiophyn -- `qwertz`: asdfqweryxcvjkluiopmghtzbn -- `qwertz-homerow`: asdfghjkl -- `qwertz-left-hand`: asdfqweryxcv -- `qwertz-right-hand`: jkluiopmhzn -- `dvorak`: aoeuqjkxpyhtnsgcrlmwvzfidb -- `dvorak-homerow`: aoeuhtnsid -- `dvorak-left-hand`: aoeupqjkyix -- `dvorak-right-hand`: htnsgcrlmwvz -- `colemak`: arstqwfpzxcvneioluymdhgjbk -- `colemak-homerow`: arstneiodh -- `colemak-left-hand`: arstqwfpzxcv -- `colemak-right-hand`: neioluymjhk - -## Extra features - -- **Arrow navigation:** You can use the arrows to move around between all spans. -- **Auto paste:** If your last typed hint character is uppercase, you are going to pick and paste the desired hint. -- **Multi selection:** If you run thumb with multi selection mode you will be able to choose multiple hints pressing the desired letter and `Space` to finalize the selection. ## Tmux compatibility @@ -329,7 +116,7 @@ This is the known list of versions of `tmux` compatible with `tmux-thumbs`: | Version | Compatible | |:-------:|:----------:| -| 3.0b | ✅ | +| 3.0+ | ✅ | | 2.9a | ✅ | | 2.8 | ❓ | | 2.7 | ❓ | @@ -340,7 +127,8 @@ This is the known list of versions of `tmux` compatible with `tmux-thumbs`: | 1.8 | ❓ | | 1.7 | ❓ | -If you can check hat `tmux-thumbs` is or is not compatible with some specific version of `tmux`, let me know. +Please report incompatibilities as you find them, I'll add them to the list. + ## Standalone `thumbs` @@ -413,18 +201,50 @@ During those days another alternative appeared, called [tmux-picker](https://git I was curious to know if this was possible to be written in [Rust](https://www.rust-lang.org/), and soon I realized that was something doable. The ability to implement tests for all critic parts of the application give you a great confidence about it. On the other hand, Rust has an awesome community that lets you achieve this kind of project in a short period of time. -## Roadmap -- [X] Support multi selection -- [X] Decouple `tmux-thumbs` from `tmux` -- [ ] Code [Kitty](https://github.com/kovidgoyal/kitty) plugin, now that `thumbs` can run standalone +## Run code-coverage -## Contribute +Install the llvm-tools-preview component and grcov -This project started as a side project to learn Rust, so I'm sure that is full -of mistakes and areas to be improve. If you think you can tweak the code to -make it better, I'll really appreaciate a pull request. ;) +```sh +rustup component add llvm-tools-preview +cargo install grcov +``` -# License +Install nightly -[MIT](https://github.com/fcsonline/tmux-thumbs/blob/master/LICENSE) +```sh +rustup toolchain install nightly +``` + +The following make invocation will switch to nigthly run the tests using +Cargo, and output coverage HTML report in `./coverage/` + +```sh +make coverage +``` + +The coverage report is located in `./coverage/index.html` + + + +## License + +Licensed under either of + + * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) + * [MIT license](http://opensource.org/licenses/MIT) + +at your option. + + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall +be dual licensed as above, without any additional terms or conditions. + +[tmux]: https://tmux.github.io +[tmux-copyrat]: https://github.com/tmux-plugins/tmux-copycat +[CONFIGURATION.md]: CONFIGURATION.md +[INSTALLATION.md]: INSTALLATION.md diff --git a/copyrat.tmux b/copyrat.tmux index c3eb357..98cdfa6 100755 --- a/copyrat.tmux +++ b/copyrat.tmux @@ -15,9 +15,10 @@ # bind-key -T foobar h new-window -d -n "[copyrat]" '/path/to/tmux-copyrat --window-name "[copyrat]" --pattern-name urls' # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # -# changing this script may break integration with `tmux-copyrat`. +# Please avoid modifying this script as it may break the integration with +# `tmux-copyrat`. +# # - # Just make sure you first open a named window in the background and provide # that name to the binary `tmux-copyrat`. # @@ -28,7 +29,8 @@ # options and bindings in your `tmux.conf`. CURRENT_DIR="$( cd "$( dirname "$0" )" && pwd )" -BINARY="${CURRENT_DIR}/tmux-copyrat" +PATH=${PATH}:${CURRENT_DIR} +BINARY=$(realpath tmux-copyrat) # @@ -36,11 +38,11 @@ BINARY="${CURRENT_DIR}/tmux-copyrat" # setup_option() { - local opt_name=$1 - local default_value=$2 - local current_value=$(tmux show-option -gqv @copyrat-${opt_name}) - value=${current_value:-${default_value}} - tmux set-option -g @copyrat-${opt_name} ${value} + local opt_name=$1 + local default_value=$2 + local current_value=$(tmux show-option -gqv @copyrat-${opt_name}) + value=${current_value:-${default_value}} + tmux set-option -g @copyrat-${opt_name} ${value} } @@ -70,11 +72,11 @@ tmux bind-key ${keyswitch} switch-client -T ${keytable} # setup_pattern_binding() { - local key=$1 - local pattern_arg="$2" - # The default window name `[copyrat]` has to be single quoted because it is - # interpreted by the shell when launched by tmux. - tmux bind-key -T ${keytable} ${key} new-window -d -n ${window_name} "${BINARY} --window-name '"${window_name}"' --reverse --unique-hint ${pattern_arg}" + local key=$1 + local pattern_arg="$2" + # The default window name `[copyrat]` has to be single quoted because it is + # interpreted by the shell when launched by tmux. + tmux bind-key -T ${keytable} ${key} new-window -d -n ${window_name} "${BINARY} --window-name '"${window_name}"' --reverse --unique-hint ${pattern_arg}" } # prefix + t + c searches for hex colors #aa00f5 diff --git a/images/copyrat-output.png b/images/copyrat-output.png new file mode 100644 index 0000000..f6d34f6 Binary files /dev/null and b/images/copyrat-output.png differ diff --git a/src/config/basic.rs b/src/config/basic.rs index 3a5afb9..729b6f2 100644 --- a/src/config/basic.rs +++ b/src/config/basic.rs @@ -31,7 +31,8 @@ pub struct Config { #[clap(short = 'x', long = "--pattern-name", parse(try_from_str = regexes::parse_pattern_name))] pub named_patterns: Vec, - /// Additional regex patterns ("foo*bar", etc). + /// Additional regex patterns ("(foo.*)bar", etc). Must have a capture + /// group. #[clap(short = 'X', long = "--custom-pattern")] pub custom_patterns: Vec,