Skip to content

Commit 88d4f9d

Browse files
committed
Initial version
0 parents  commit 88d4f9d

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

Diff for: LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Ivan Bitkin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# tmux-fzf-snippets
2+
A very simple plugin that allows to insert snippets. Based on [tmux-fzf-url](https://github.com/wfxr/tmux-fzf-url).
3+
4+
The main use case is for docker containers or remote hosts.
5+
6+
The snippets are read from a plaintext file where each line is a separate
7+
snippet. Tmux buffer selection menu can be used for similar purposes, but is
8+
less convenient.
9+
10+
11+
### Configuration
12+
`@fzf-snippets-bind`: binding to run the plugin. Default is `Prefix+a`.
13+
14+
`@fzf-snippets-file`: plaintext file from which to get the snippets. Default is `~/.tmux/snippets`.
15+
16+
`@fzf-snippets-fzf-options`: options that are passed to `fzf-tmux`. See default in `fzf-snippets.sh`.
17+
18+
### Installation
19+
##### tpm
20+
Add this line to your tmux config file, then hit `prefix + I`:
21+
```tmux
22+
set -g @plugin 'bitkeen/tmux-fzf-snippets'
23+
```
24+
##### Manual
25+
Clone this repo and source `fzf-snippets.tmux` in tmux config file:
26+
```tmux
27+
run-shell ~/.tmux/plugins/tmux-fzf-snippets/fzf-snippets.tmux
28+
```

Diff for: fzf-snippets.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
get_fzf_options() {
3+
fzf_default_options='-d 35% --exit-0 --no-preview --no-border --header="Choose snippet" --header-first'
4+
fzf_options="$(tmux show -gqv '@fzf-snippets-fzf-options')"
5+
[ -n "$fzf_options" ] && echo "$fzf_options" || echo "$fzf_default_options"
6+
}
7+
8+
fzf_filter() {
9+
eval "fzf-tmux $(get_fzf_options)"
10+
}
11+
12+
chosen="$(fzf_filter < "$1")"
13+
[ -z "$chosen" ] && exit
14+
15+
tmux set-buffer "$chosen"
16+
tmux paste-buffer

Diff for: fzf-snippets.tmux

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
SCRIPT_DIR="$(dirname "$0")"
3+
4+
tmux_get() {
5+
# $1: option
6+
# $2: default value
7+
value="$(tmux show -gqv "$1")"
8+
[ -n "$value" ] && echo "$value" || echo "$2"
9+
}
10+
11+
key="$(tmux_get '@fzf-snippets-bind' 'a')"
12+
snippets_file="$(tmux_get '@fzf-snippets-file' "$HOME/.tmux/snippets")"
13+
14+
tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-snippets.sh '$snippets_file'"

0 commit comments

Comments
 (0)