1
0
Fork 0

add message if no VCS found

This commit is contained in:
Andrey Orst 2018-10-11 15:01:42 +03:00
parent e9d3616321
commit 7b61eef360

View file

@ -140,40 +140,38 @@ Best used with mapping like:
" \ " \
fzf-vcs-mode %{ try %{ evaluate-commands 'enter-user-mode fzf-vcs' } } fzf-vcs-mode %{ try %{ evaluate-commands 'enter-user-mode fzf-vcs' } }
define-command -hidden fzf-file %{ define-command -hidden fzf-file %{ evaluate-commands %sh{
evaluate-commands %sh{ if [ -z $(command -v $kak_opt_fzf_file_command) ]; then
if [ -z $(command -v $kak_opt_fzf_file_command) ]; then echo "echo -markup '{Information}''$kak_opt_fzf_file_command'' is not installed. Falling back to ''find'''"
echo "echo -markup '{Information}''$kak_opt_fzf_file_command'' is not installed. Falling back to ''find'''" kak_opt_fzf_file_command="find"
kak_opt_fzf_file_command="find" fi
fi case $kak_opt_fzf_file_command in
case $kak_opt_fzf_file_command in find)
find) cmd="find -type f" ;;
cmd="find -type f" ;; ag)
ag) cmd="ag -l -f --hidden --one-device . " ;;
cmd="ag -l -f --hidden --one-device . " ;; rg)
rg) cmd="rg -L --hidden --files" ;;
cmd="rg -L --hidden --files" ;; fd)
fd) cmd="fd --type f --follow" ;;
cmd="fd --type f --follow" ;; find*|ag*|rg*|fd*)
find*|ag*|rg*|fd*) cmd=$kak_opt_fzf_file_command ;;
cmd=$kak_opt_fzf_file_command ;; *)
*) executable=$(echo $kak_opt_fzf_file_command | awk '{print $1'}| tr '(' ' ' | cut -d " " -f 2)
executable=$(echo $kak_opt_fzf_file_command | awk '{print $1'}| tr '(' ' ' | cut -d " " -f 2) echo "echo -markup '{Information}''$executable'' is not supported by the script. fzf.kak may not work as you expect.'"
echo "echo -markup '{Information}''$executable'' is not supported by the script. fzf.kak may not work as you expect.'" cmd=$kak_opt_fzf_file_command ;;
cmd=$kak_opt_fzf_file_command ;; esac
esac title="fzf file"
title="fzf file" [ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings="
[ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings="
<c-s>: open file in horizontal split <c-s>: open file in horizontal split
<c-v>: open file in vertical split" <c-v>: open file in vertical split"
message="Open single or multiple files. message="Open single or multiple files.
<ret>: open file in new buffer. <ret>: open file in new buffer.
<c-w>: open file in new window $additional_keybindings" <c-w>: open file in new window $additional_keybindings"
echo "info -title '$title' '$message'" echo "info -title '$title' '$message'"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s" [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"' eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"'
} }}
}
define-command -docstring "Wrapper command for fzf vcs to automatically decect define-command -docstring "Wrapper command for fzf vcs to automatically decect
used version control system. used version control system.
@ -184,116 +182,97 @@ Supported vcs:
Mercurial SCM: ""hg"" Mercurial SCM: ""hg""
GNU Bazaar: ""bzr"" GNU Bazaar: ""bzr""
" \ " \
-hidden fzf-vcs %{ -hidden fzf-vcs %{ evaluate-commands %sh{
evaluate-commands %sh{ commands="git rev-parse --is-inside-work-tree
commands="git rev-parse --is-inside-work-tree
svn info svn info
hg --cwd . root hg --cwd . root
bzr status" bzr status"
IFS=' IFS='
' '
for cmd in $commands; do for cmd in $commands; do
eval $cmd >/dev/null 2>&1 eval $cmd >/dev/null 2>&1
res=$? res=$?
if [ "$res" = "0" ]; then if [ "$res" = "0" ]; then
vcs=$(echo $cmd | awk '{print $1}') vcs=$(echo $cmd | awk '{print $1}')
title="fzf $vcs" title="fzf $vcs"
[ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings=" [ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings="
<c-s>: open file in horizontal split <c-s>: open file in horizontal split
<c-v>: open file in vertical split" <c-v>: open file in vertical split"
message="Open single or multiple files from git tree. message="Open single or multiple files from git tree.
<ret>: open file in new buffer. <ret>: open file in new buffer.
<c-w>: open file in new window $additional_keybindings" <c-w>: open file in new window $additional_keybindings"
echo "info -title '$title' '$message'" echo "info -title '$title' '$message'"
echo "fzf-$vcs" echo "fzf-$vcs"
break exit
fi fi
done done
} echo "echo -markup '{Information}No VCS found in current folder'"
} }}
define-command -hidden fzf-git %{ define-command -hidden fzf-git %{ evaluate-commands %sh{
evaluate-commands %sh{ case $kak_opt_fzf_git_command in
case $kak_opt_fzf_git_command in git)
git) cmd="git ls-tree --name-only -r HEAD" ;;
cmd="git ls-tree --name-only -r HEAD" git*)
;; cmd=$kak_opt_fzf_git_command ;;
git*) esac
cmd=$kak_opt_fzf_git_command [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
;; eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"'
esac }}
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"'
}
}
define-command -hidden fzf-hg %{ define-command -hidden fzf-hg %{ evaluate-commands %sh{
evaluate-commands %sh{ case $kak_opt_fzf_hg_command in
case $kak_opt_fzf_hg_command in hg)
hg) cmd="hg locate -f -0 -I .hg locate -f -0 -I ." ;;
cmd="hg locate -f -0 -I .hg locate -f -0 -I ." hg*)
;; cmd=$kak_opt_fzf_hg_command ;;
hg*) esac
cmd=$kak_opt_fzf_hg_command [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
;; eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"'
esac }}
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"'
}
}
define-command -hidden fzf-svn %{ define-command -hidden fzf-svn %{ evaluate-commands %sh{
evaluate-commands %sh{ case $kak_opt_fzf_svn_command in
case $kak_opt_fzf_svn_command in svn)
svn) cmd="svn list -R . | grep -v '$/' | tr '\\n' '\\0'" ;;
cmd="svn list -R . | grep -v '$/' | tr '\\n' '\\0'" svn*)
;; cmd=$kak_opt_fzf_svn_command ;;
svn*) esac
cmd=$kak_opt_fzf_svn_command [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
;; eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"'
esac }}
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"'
}
}
define-command -hidden fzf-bzr %{ define-command -hidden fzf-bzr %{ evaluate-commands %sh{
evaluate-commands %sh{ case $kak_opt_fzf_bzr_command in
case $kak_opt_fzf_bzr_command in bzr)
bzr) cmd="bzr ls -R --versioned -0" ;;
cmd="bzr ls -R --versioned -0" bzr*)
;; cmd=$kak_opt_fzf_bzr_command ;;
bzr*) esac
cmd=$kak_opt_fzf_bzr_command [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
;; eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"'
esac }}
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
eval echo 'fzf \"edit \$1\" \"$cmd\" \"-m --expect ctrl-w $additional_flags\"'
}
}
define-command -hidden fzf-tag %{ define-command -hidden fzf-tag %{ evaluate-commands %sh{
evaluate-commands %sh{ case $kak_opt_fzf_tag_command in
case $kak_opt_fzf_tag_command in readtags)
readtags) cmd="readtags -l | cut -f1 | sort -u" ;;
cmd="readtags -l | cut -f1 | sort -u" ;; readtags*)
readtags*) cmd=$kak_opt_fzf_tag_command ;;
cmd=$kak_opt_fzf_tag_command ;; *)
*) echo "echo -markup '{Information}$kak_opt_fzf_tag_command is not supported by the script. fzf.kak may not work as you expect."
echo "echo -markup '{Information}$kak_opt_fzf_tag_command is not supported by the script. fzf.kak may not work as you expect." cmd=$kak_opt_fzf_tag_command ;;
cmd=$kak_opt_fzf_tag_command ;; esac
esac title="fzf tag"
title="fzf tag" [ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings="
[ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings="
<c-s>: open tag in horizontal split <c-s>: open tag in horizontal split
<c-v>: open tag in vertical split" <c-v>: open tag in vertical split"
message="Jump to a symbol''s definition.<ret>: open tag in new buffer. message="Jump to a symbol''s definition.<ret>: open tag in new buffer.
<c-w>: open tag in new window $additional_keybindings" <c-w>: open tag in new window $additional_keybindings"
echo "info -title '$title' '$message'" echo "info -title '$title' '$message'"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s" [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
eval echo 'fzf \"ctags-search \$1\" \"$cmd\" \"--expect ctrl-w $additional_flags\"' eval echo 'fzf \"ctags-search \$1\" \"$cmd\" \"--expect ctrl-w $additional_flags\"'
} }}
}
define-command -hidden fzf-cd %{ define-command -hidden fzf-cd %{
evaluate-commands %sh{ evaluate-commands %sh{
@ -304,8 +283,7 @@ define-command -hidden fzf-cd %{
fzf "change-directory $1" "(echo .. && find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" fzf "change-directory $1" "(echo .. && find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)"
} }
define-command -hidden fzf-buffer-search %{ define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{
evaluate-commands %sh{
title="fzf buffer search" title="fzf buffer search"
message="Search buffer with fzf, and jump to result location" message="Search buffer with fzf, and jump to result location"
echo "info -title '$title' '$message'" echo "info -title '$title' '$message'"
@ -315,8 +293,7 @@ define-command -hidden fzf-buffer-search %{
echo "execute-keys %{%<a-|>cat<space>><space>$buffer_content<ret>;}" echo "execute-keys %{%<a-|>cat<space>><space>$buffer_content<ret>;}"
echo "execute-keys $line g $char l" echo "execute-keys $line g $char l"
echo "fzf \"execute-keys \$1 gx\" \"(nl -b a -n ln $buffer_content\" \"--reverse | cut -f 1; rm $buffer_content)\"" echo "fzf \"execute-keys \$1 gx\" \"(nl -b a -n ln $buffer_content\" \"--reverse | cut -f 1; rm $buffer_content)\""
} } }
}
define-command -hidden fzf -params 2..3 %{ evaluate-commands %sh{ define-command -hidden fzf -params 2..3 %{ evaluate-commands %sh{
callback=$1 callback=$1