Port most kak scripts to be POSIX shell compliant

This commit is contained in:
Maxime Coste 2014-03-06 03:35:38 +00:00
parent 8e0b5d67aa
commit f733007a7b
8 changed files with 38 additions and 33 deletions

View File

@ -16,7 +16,7 @@ def clang-complete %{
(
pos=-:${kak_cursor_line}:${kak_cursor_column}
cd $(dirname ${kak_buffile})
output=$(clang++ -x c++ -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-at=${pos} - < ${kak_opt_clang_filename} |& tee /tmp/kak-clang-out |
output=$(clang++ -x c++ -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-at=${pos} - < ${kak_opt_clang_filename} 2>&1 | tee /tmp/kak-clang-out |
grep -E "^COMPLETION:[^:]+:" | perl -pe 's/^COMPLETION:[^:]+: +//; s/:/\\:/g; s/\[#.*?#\]|<#.*?#>(, *|\))?|\{#.*?#\}\)?//g')
rm -r $(dirname ${kak_opt_clang_filename})
completions="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
@ -24,7 +24,7 @@ def clang-complete %{
completions="${completions}:${cmp}"
done
echo "eval -client $kak_client %[ echo completed; set buffer completions '${completions}' ]" | kak -p ${kak_session}
) >& /dev/null < /dev/null &
) > /dev/null 2>&1 < /dev/null &
}
}

View File

@ -1,5 +1,5 @@
decl str termcmd %sh{
if [[ -n "$TMUX" ]]; then
if [ -n "$TMUX" ]; then
echo "'tmux split-window -h'"
else
echo "'urxvt -e sh -c'"
@ -8,6 +8,6 @@ decl str termcmd %sh{
def new -docstring 'create a new kak client for current session' \
-shell-params %{ nop %sh{
if (( $# != 0 )); then kakoune_params="-e '$@'"; fi
setsid ${kak_opt_termcmd} "kak -c ${kak_session} ${kakoune_params}" < /dev/null >& /dev/null &
if [ $# -ne 0 ]; then kakoune_params="-e '$@'"; fi
setsid ${kak_opt_termcmd} "kak -c ${kak_session} ${kakoune_params}" < /dev/null > /dev/null 2>&1 &
}}

View File

@ -75,26 +75,32 @@ hook global BufNew .*\.(h|hh|hpp|hxx|H) _cpp_insert_include_guards
decl str-list alt_dirs ".;.."
def alt -docstring "Jump to the alternate file (header/implementation)" %{ %sh{
shopt -s extglob
alt_dirs=${kak_opt_alt_dirs//;/ }
alt_dirs=$(echo ${kak_opt_alt_dirs} | sed -e 's/;/ /g')
file=$(basename ${kak_buffile})
dir=$(dirname ${kak_buffile})
case ${file} in
*.c|*.cc|*.cpp|*.cxx|*.C)
for alt_dir in ${alt_dirs}; do
altname=$(ls -1 "${dir}/${alt_dir}/${file%.*}".@(h|hh|hpp|hxx|H) 2> /dev/null | head -n 1)
[[ -e ${altname} ]] && break
for ext in h hh hpp hxx H; do
altname="${dir}/${alt_dir}/${file%.*}.${ext}"
[ -f ${altname} ] && break
done
[ -f ${altname} ] && break
done
;;
*.h|*.hh|*.hpp|*.hxx|*.H)
for alt_dir in ${alt_dirs}; do
altname=$(ls -1 "${dir}/${alt_dir}/${file%.*}".@(c|cc|cpp|cxx|C) 2> /dev/null | head -n 1)
[[ -e ${altname} ]] && break
for ext in c cc cpp cxx C; do
altname="${dir}/${alt_dir}/${file%.*}.${ext}"
[ -f ${altname} ] && break
done
[ -f ${altname} ] && break
done
;;
esac
if [[ -e ${altname} ]]; then
echo debug ${altname}
if [ -f ${altname} ]; then
echo edit "'${altname}'"
else
echo echo "'alternative file not found'"

View File

@ -8,20 +8,20 @@ def -shell-params \
-docstring 'jump to tag definition' \
tag \
%{ %sh{
if [[ -z "$1" ]]; then tagname=${kak_selection}; else tagname=$1; fi
if [ -z "$1" ]; then tagname=${kak_selection}; else tagname="$1"; fi
matches=$(readtags ${tagname})
if [[ -z "${matches}" ]]; then
if [ -z "${matches}" ]; then
echo "echo tag not found ${tagname}"
else
menuparam=$(readtags ${tagname} | perl -i -ne '
/([^\t]+)\t([^\t]+)\t\/\^([^{}]*).*\$\// and print "%{$2 [$3]} %{try %{ edit %{$2}; exec %{/\\Q$3<ret>vc} } catch %{ echo %{unable to find tag} } } ";
/([^\t]+)\t([^\t]+)\t(\d+)/ and print "%{$2:$3} %{edit %{$2} %{$3}}";
')
' | sed -e 's/\n/ /g')
if [[ -z "${menuparam}" ]]; then
if [ -z "${menuparam}" ]; then
echo "echo no such tag ${tagname}";
else
echo "menu -auto-single ${menuparam//$'\n'/ }";
echo "menu -auto-single ${menuparam}";
fi
fi
}}
@ -29,12 +29,10 @@ def -shell-params \
def tag-complete %{ eval -draft %{
exec <space>hb<a-k>^\w+$<ret>
%sh{ (
compl=$(readtags -p "$kak_selection" | cut -f 1 | sort | uniq)
compl=${compl//:/\\:}
compl=${compl//$'\n'/:}
compl=$(readtags -p "$kak_selection" | cut -f 1 | sort | uniq | sed -e 's/:/\\:/g' | sed -e 's/\n/:/g' )
compl="${kak_cursor_line}.${kak_cursor_column}+${#kak_selection}@${kak_timestamp}:${compl}"
echo "set buffer=$kak_bufname completions '${compl}'" | kak -p ${kak_session}
) >& /dev/null < /dev/null & }
) > /dev/null 2>&1 < /dev/null & }
}}
def funcinfo %{
@ -42,7 +40,7 @@ def funcinfo %{
exec [(<space>B<a-k>[a-zA-Z_]+\(<ret>
%sh{
sigs=$(readtags -e ${kak_selection%(} | grep kind:f | sed -re 's/^(\S+).*(class|struct|namespace):(\S+).*signature:(.*)$/\4 [\3::\1]/')
if [[ -n "$sigs" ]]; then
if [ -n "$sigs" ]; then
echo "eval -client ${kak_client} %{info -anchor right '$sigs'}"
fi
}
@ -70,5 +68,5 @@ def gentags -docstring 'generate tag file asynchronously' %{
msg="tags generation failed"
fi
echo "eval -client $kak_client echo -color Information '${msg}'" | kak -p ${kak_session}
) >& /dev/null < /dev/null & }
) > /dev/null 2>&1 < /dev/null & }
}

View File

@ -22,14 +22,14 @@ def -shell-params git %{ %sh{
esac
tmpfile=$(mktemp /tmp/kak-git-XXXXXX)
if git "$@" > ${tmpfile}; then
[[ -n "$kak_opt_docsclient" ]] && echo "eval -client '$kak_opt_docsclient' %{"
[ -n "$kak_opt_docsclient" ] && echo "eval -client '$kak_opt_docsclient' %{"
echo "edit! -scratch *git*
exec |cat<space>${tmpfile}<ret>gk
nop %sh{rm ${tmpfile}}
set buffer filetype '${filetype}'"
[[ -n "$kak_opt_docsclient" ]] && echo "}"
[ -n "$kak_opt_docsclient" ] && echo "}"
else
echo "echo %{git $@ failed, see *debug* buffer}"
rm ${tmpfile}
@ -45,7 +45,7 @@ def -shell-params git %{ %sh{
declare -A authors
declare -A dates
send_flags() {
if [[ -z "$line" ]]; then return; fi
if [ -z "$line" ]; then return; fi
text=$(echo "${sha:0:8} ${dates[$sha]} ${authors[$sha]}" | sed -e 's/:/\\:/g')
flag="$line|black|$text"
for (( i=1; $i < $count; i++ )); do

View File

@ -5,10 +5,10 @@ def -shell-params -file-completion \
grep %{ %sh{
output=$(mktemp -d -t kak-grep.XXXXXXXX)/fifo
mkfifo ${output}
if (( $# > 0 )); then
( ${kak_opt_grepcmd} "$@" | tr -d '\r' >& ${output} ) >& /dev/null < /dev/null &
if [ $# -gt 0 ]; then
( ${kak_opt_grepcmd} "$@" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
else
( ${kak_opt_grepcmd} "${kak_selection}" | tr -d '\r' >& ${output} ) >& /dev/null < /dev/null &
( ${kak_opt_grepcmd} "${kak_selection}" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
fi
echo "eval -try-client '$kak_opt_toolsclient' %{

View File

@ -4,7 +4,7 @@ decl str toolsclient
def -shell-params make %{ %sh{
output=$(mktemp -d -t kak-make.XXXXXXXX)/fifo
mkfifo ${output}
( eval ${kak_opt_makecmd} $@ >& ${output} ) >& /dev/null < /dev/null &
( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
echo "eval -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${output} *make*

View File

@ -16,8 +16,9 @@ hook global WinSetOption filetype=(?!man).* %{
def -hidden -shell-params _man %{ %sh{
tmpfile=$(mktemp /tmp/kak-man-XXXXXX)
MANWIDTH=${kak_window_width} man "$@" | col -b > ${tmpfile}
if (( ${PIPESTATUS[0]} == 0 )); then
output=$(MANWIDTH=${kak_window_width} man "$@")
if [ $? -eq 0 ]; then
echo "${output}" | col -b > ${tmpfile}
echo "edit! -scratch '*man*'
exec |cat<space>${tmpfile}<ret>gk
nop %sh{rm ${tmpfile}}
@ -29,6 +30,6 @@ def -hidden -shell-params _man %{ %sh{
} }
def -shell-params man %{ %sh{
[[ -z "$@" ]] && set -- "$kak_selection"
[ -z "$@" ] && set -- "$kak_selection"
echo "eval -try-client %opt{docsclient} _man $@"
} }