summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-04-22 00:55:39 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-04-22 00:55:39 +0900
commit06b4f7568084358fce6927c3bedc6816159607f0 (patch)
tree881781e6f767022f673c90f5731bb0513897ffb2
parent318edc8c352250be04a9c2d15f5854084671c3df (diff)
Fix broken FZF_TMUX switch and update test cases (#203)
-rw-r--r--shell/key-bindings.bash8
-rw-r--r--shell/key-bindings.fish20
-rw-r--r--shell/key-bindings.zsh10
3 files changed, 26 insertions, 12 deletions
diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash
index dfa9bf6e..362e4428 100644
--- a/shell/key-bindings.bash
+++ b/shell/key-bindings.bash
@@ -12,6 +12,10 @@ __fzf_select__() {
if [[ $- =~ i ]]; then
+__fzfcmd() {
+ [ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
+}
+
__fzf_select_tmux__() {
local height
height=${FZF_TMUX_HEIGHT:-40%}
@@ -26,11 +30,11 @@ __fzf_select_tmux__() {
__fzf_cd__() {
local dir
dir=$(command find -L ${1:-.} \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
- -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +m) && printf 'cd %q' "$dir"
+ -o -type d -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) +m) && printf 'cd %q' "$dir"
}
__fzf_history__() {
- HISTTIMEFORMAT= history | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r | sed "s/ *[0-9]* *//"
+ HISTTIMEFORMAT= history | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r | sed "s/ *[0-9]* *//"
}
__use_tmux=0
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
index 2caaf203..8be5ab5f 100644
--- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -26,14 +26,14 @@ function fzf_key_bindings
end
function __fzf_ctrl_t
- __fzf_list | fzf-tmux (__fzf_tmux_height) -m > $TMPDIR/fzf.result
+ __fzf_list | eval (__fzfcmd) -m > $TMPDIR/fzf.result
and commandline -i (cat $TMPDIR/fzf.result | __fzf_escape)
commandline -f repaint
rm -f $TMPDIR/fzf.result
end
function __fzf_ctrl_r
- history | fzf-tmux (__fzf_tmux_height) +s +m --tiebreak=index --toggle-sort=ctrl-r > $TMPDIR/fzf.result
+ history | eval (__fzfcmd) +s +m --tiebreak=index --toggle-sort=ctrl-r > $TMPDIR/fzf.result
and commandline (cat $TMPDIR/fzf.result)
commandline -f repaint
rm -f $TMPDIR/fzf.result
@@ -41,18 +41,24 @@ function fzf_key_bindings
function __fzf_alt_c
# Fish hangs if the command before pipe redirects (2> /dev/null)
- __fzf_list_dir | fzf-tmux (__fzf_tmux_height) +m > $TMPDIR/fzf.result
+ __fzf_list_dir | eval (__fzfcmd) +m > $TMPDIR/fzf.result
[ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]
and cd (cat $TMPDIR/fzf.result)
commandline -f repaint
rm -f $TMPDIR/fzf.result
end
- function __fzf_tmux_height
- if set -q FZF_TMUX_HEIGHT
- echo "-d$FZF_TMUX_HEIGHT"
+ function __fzfcmd
+ set -q FZF_TMUX; or set FZF_TMUX 1
+
+ if [ $FZF_TMUX -eq 1 ]
+ if set -q FZF_TMUX_HEIGHT
+ echo "fzf-tmux -d$FZF_TMUX_HEIGHT"
+ else
+ echo "fzf-tmux -d40%"
+ end
else
- echo "-d40%"
+ echo "fzf"
end
end
diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh
index 40acafc3..f8cbb715 100644
--- a/shell/key-bindings.zsh
+++ b/shell/key-bindings.zsh
@@ -5,12 +5,16 @@ __fsel() {
command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-o -type f -print \
-o -type d -print \
- -o -type l -print 2> /dev/null | sed 1d | cut -b3- | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} -m | while read item; do
+ -o -type l -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) -m | while read item; do
printf '%q ' "$item"
done
echo
}
+__fzfcmd() {
+ [ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
+}
+
if [[ $- =~ i ]]; then
fzf-file-widget() {
@@ -23,7 +27,7 @@ bindkey '^T' fzf-file-widget
# ALT-C - cd into the selected directory
fzf-cd-widget() {
cd "${$(command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
- -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +m):-.}"
+ -o -type d -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) +m):-.}"
zle reset-prompt
}
zle -N fzf-cd-widget
@@ -32,7 +36,7 @@ bindkey '\ec' fzf-cd-widget
# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget() {
local selected
- if selected=$(fc -l 1 | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "$LBUFFER"); then
+ if selected=$(fc -l 1 | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "$LBUFFER"); then
num=$(echo "$selected" | head -1 | awk '{print $1}' | sed 's/[^0-9]//g')
LBUFFER=!$num
zle expand-history