summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2014-03-28 17:15:32 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2014-03-28 17:15:45 +0900
commitcf8dbf804769fd41bea6982a9c17dda3b74fb106 (patch)
tree172c96688097b8081ddda2784b9262385a519667
parent995d38020016ee1074a6d4ab2fa7f6ce29faf8ff (diff)
Allow setting tmux split height in %
-rw-r--r--README.md24
-rwxr-xr-xinstall22
-rw-r--r--plugin/fzf.vim14
3 files changed, 42 insertions, 18 deletions
diff --git a/README.md b/README.md
index f2a2740b..f0bd85df 100644
--- a/README.md
+++ b/README.md
@@ -214,7 +214,7 @@ The install script will setup the following key bindings.
If you're on a tmux session, `CTRL-T` will launch fzf in a new split-window. You
may disable this tmux integration by setting `FZF_TMUX` to 0, or change the
-height of the window with `FZF_TMUX_HEIGHT`.
+height of the window with `FZF_TMUX_HEIGHT` (e.g. `20`, `50%`).
The source code can be found in `~/.fzf.bash` and in `~/.fzf.zsh`.
@@ -315,8 +315,8 @@ Note that the environment variables `FZF_DEFAULT_COMMAND` and `FZF_DEFAULT_OPTS`
also apply here.
If you're on a tmux session, `:FZF` will launch fzf in a new split-window whose
-height can be adjusted with `g:fzf_tmux_height` (default: 15). However, the bang
-version (`:FZF!`) will always start in fullscreen.
+height can be adjusted with `g:fzf_tmux_height` (default: '40%'). However, the
+bang version (`:FZF!`) will always start in fullscreen.
### `fzf#run([options])`
@@ -325,15 +325,15 @@ of the selected items.
`fzf#run()` may take an options-dictionary:
-| Option name | Type | Description |
-| ----------- | ------- | ---------------------------------------------------------- |
-| `source` | string | External command to generate input to fzf (e.g. `find .`) |
-| `source` | list | Vim list as input to fzf |
-| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
-| `sink` | funcref | Reference to function to process each selected item |
-| `options` | string | Options to fzf |
-| `dir` | string | Working directory |
-| `tmux` | number | Use tmux split if possible with the given height |
+| Option name | Type | Description |
+| ----------- | ------------- | ------------------------------------------------------------------- |
+| `source` | string | External command to generate input to fzf (e.g. `find .`) |
+| `source` | list | Vim list as input to fzf |
+| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
+| `sink` | funcref | Reference to function to process each selected item |
+| `options` | string | Options to fzf |
+| `dir` | string | Working directory |
+| `tmux` | number/string | Use tmux split if possible with the given height (e.g. `20`, `50%`) |
#### Examples
diff --git a/install b/install
index a32d0661..5446697e 100755
--- a/install
+++ b/install
@@ -115,7 +115,14 @@ __fsel() {
}
__fsel_tmux() {
- tmux split-window -l ${FZF_TMUX_HEIGHT:-15} "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""
+ local height lines
+ height=${FZF_TMUX_HEIGHT:-40%}
+ lines=${LINES:-40}
+ if [[ $height =~ %$ ]]; then
+ height=${height:0:${#height}-1}
+ height=$(( height * lines / 100 ))
+ fi
+ tmux split-window -l $height "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""
}
__fcd() {
@@ -124,7 +131,7 @@ __fcd() {
}
__use_tmux=0
-[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-30} -gt 15 ] && __use_tmux=1
+[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ] && __use_tmux=1
if [ -z "$(set -o | grep '^vi.*on')" ]; then
# Required to refresh the prompt after fzf
@@ -180,9 +187,16 @@ read -r -d '' __fsel <<'EOF'
echo
EOF
-if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-30} -gt 15 ]; then
+if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ]; then
fzf-file-widget() {
- tmux split-window -l ${FZF_TMUX_HEIGHT:-15} "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""
+ local height lines
+ height=${FZF_TMUX_HEIGHT:-40%}
+ lines=${LINES:-40}
+ if [[ $height =~ %$ ]]; then
+ height=${height:0:${#height}-1}
+ height=$(( height * lines / 100 ))
+ fi
+ tmux split-window -l $height "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""
}
else
fzf-file-widget() {
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index ba0d0b33..c1b68cef 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -22,7 +22,7 @@
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
let s:min_tmux_height = 3
-let s:default_tmux_height = 15
+let s:default_tmux_height = '40%'
let s:cpo_save = &cpo
set cpo&vim
@@ -114,7 +114,17 @@ function! s:execute_tmux(dict, command, temps)
else
let command = a:command
endif
- let height = a:dict.tmux
+
+ if type(a:dict.tmux) == 1
+ if a:dict.tmux =~ '%$'
+ let height = screenrow() * str2nr(a:dict.tmux[0:-2]) / 100
+ else
+ let height = str2nr(a:dict.tmux)
+ endif
+ else
+ let height = a:dict.tmux
+ endif
+
let s:pane = substitute(
\ system(
\ printf(