1
0
Fork 0

add -override flag, simplify some echos, add safe way to reload script file

This commit is contained in:
Andrey Orst 2018-09-22 22:41:16 +03:00
parent 62fe13bb45
commit 8af81ae376

View file

@ -12,7 +12,7 @@
# ╰─────────────────────────────────╯ # ╰─────────────────────────────────╯
# New mode # New mode
declare-user-mode fzf evaluate-commands %sh{ modes="_ "$kak_user_modes; [ -z "${modes##*fzf*}" ] || echo declare-user-mode fzf }
# Options # Options
declare-option -docstring "command to provide list of files to fzf. declare-option -docstring "command to provide list of files to fzf.
@ -43,22 +43,22 @@ map global fzf -docstring "change directory" c '<esc>: fzf-cd<ret>'
map global fzf -docstring "edif file in git tree" g '<esc>: fzf-git<ret>' map global fzf -docstring "edif file in git tree" g '<esc>: fzf-git<ret>'
# Commands # Commands
define-command -docstring \ define-command -override -docstring \
"fzf-mode: Enter fzf-mode "fzf-mode: Enter fzf-mode
This is to be used in mappings to enter fzf-mode This is to be used in mappings to enter fzf-mode
For example: map global normal <c-p> ': fzf-mode<ret>' For example: map global normal <c-p> ': fzf-mode<ret>'
" \ " \
fzf-mode %{ evaluate-commands 'enter-user-mode fzf' } fzf-mode %{ evaluate-commands 'enter-user-mode fzf' }
define-command -hidden -docstring \ define-command -override -hidden -docstring \
"fzf-file: Run fzf to open file "fzf-file: Run fzf to open file
Configurable options: Configurable options:
fzf_file_command: command to run with fzf to list possible files. fzf_file_command: command to run with fzf to list possible files.
"\ " \
fzf-file %{ 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
printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}$kak_opt_fzf_file_command is not installed. Falling back to find'" | kak -p ${kak_session} 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
@ -75,27 +75,27 @@ fzf-file %{
cmd=$kak_opt_fzf_file_command cmd=$kak_opt_fzf_file_command
;; ;;
*) *)
echo fail "fzf wrong file command: \'$kak_opt_fzf_file_command'" echo "echo -markup '{Information}$kak_opt_fzf_file_command is not supported by the script. It may not work as you expect."
exit cmd=$kak_opt_fzf_file_command
;; ;;
esac esac
eval echo 'fzf \"edit \$1\" \"$cmd\"' eval echo 'fzf \"edit \$1\" \"$cmd\"'
} }
} }
define-command -hidden fzf-git %{ define-command -override -hidden fzf-git %{
fzf "edit $1" "git ls-tree --name-only -r HEAD" fzf "edit $1" "git ls-tree --name-only -r HEAD"
} }
define-command -hidden fzf-tag %{ define-command -override -hidden fzf-tag %{
fzf "ctags-search $1" "readtags -l | cut -f1 | sort -u" fzf "ctags-search $1" "readtags -l | cut -f1 | sort -u"
} }
define-command -hidden fzf-cd %{ define-command -override -hidden fzf-cd %{
fzf "change-directory $1" "find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print" fzf "change-directory $1" "find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print"
} }
define-command -hidden fzf -params 2 %{ exec %sh{ define-command -override -hidden fzf -params 2 %{ exec %sh{
tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX)) tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX))
exec=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-exec.XXXXXX)) exec=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-exec.XXXXXX))
callback=$1; shift callback=$1; shift
@ -118,7 +118,7 @@ define-command -hidden fzf -params 2 %{ exec %sh{
) > /dev/null 2>&1 < /dev/null & ) > /dev/null 2>&1 < /dev/null &
}} }}
define-command -hidden fzf-buffer %{ evaluate-commands %sh{ define-command -override -hidden fzf-buffer %{ evaluate-commands %sh{
tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX)) tmp=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-fzf.XXXXXX))
setbuf=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-setbuf.XXXXXX)) setbuf=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-setbuf.XXXXXX))
delbuf=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-delbuf.XXXXXX)) delbuf=$(mktemp $(eval echo $kak_opt_fzf_tmp/kak-delbuf.XXXXXX))